001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jdbc;
031:
032: import com.caucho.util.Log;
033:
034: import javax.sql.DataSource;
035: import java.util.logging.Logger;
036:
037: /**
038: * Abstract way of grabbing data from the JDBC connection.
039: */
040: public class PostgresMetaData extends GenericMetaData {
041: private static final Logger log = Log.open(PostgresMetaData.class);
042:
043: protected PostgresMetaData(DataSource ds) {
044: super (ds);
045: }
046:
047: /**
048: * Returns the literal for FALSE.
049: */
050: public String getFalseLiteral() {
051: return "false";
052: }
053:
054: /**
055: * Returns true if the POSITION function is supported.
056: */
057: public boolean supportsPositionFunction() {
058: return true;
059: }
060:
061: /**
062: * Returns true if sequences are supported.
063: */
064: public boolean supportsSequences() {
065: return true;
066: }
067:
068: /**
069: * Returns true if table alias name with UPDATE is supported.
070: */
071: public boolean supportsUpdateTableAlias() {
072: // Postgres 8.0.x compatibility. Postgres 8.2.x supports it.
073: return false;
074: }
075:
076: /**
077: * Returns a sequence select expression.
078: */
079: public String createSequenceSQL(String name, int size) {
080: if (size > 1)
081: return "CREATE SEQUENCE " + name + " INCREMENT " + size;
082: else
083: return "CREATE SEQUENCE " + name;
084: }
085:
086: /**
087: * Returns a sequence select expression.
088: */
089: public String selectSequenceSQL(String name) {
090: return "SELECT Nextval('" + name + "')";
091: }
092:
093: /**
094: * Returns a sequence select expression.
095: */
096: public String testSequenceSQL(String name) {
097: return "SELECT Currval('" + name + "')";
098: }
099:
100: /**
101: * Returns the code to test for a boolean value for a term.
102: */
103: public String generateBoolean(String term) {
104: return "(" + term + " = 't')";
105: }
106: }
|