org.postgresql.jdbc2
Class AbstractJdbc2Connection

java.lang.Object
  extended by org.postgresql.jdbc2.AbstractJdbc2Connection
All Implemented Interfaces:
java.sql.Connection, BaseConnection, PGConnection
Direct Known Subclasses:
AbstractJdbc3Connection

public abstract class AbstractJdbc2Connection
extends java.lang.Object
implements BaseConnection

This class defines methods of the jdbc2 specification. The real Connection class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Connection


Field Summary
 boolean autoCommit
           
 boolean bindStringAsVarchar
           
 java.sql.SQLWarning firstWarning
           
protected  java.sql.DatabaseMetaData metadata
           
protected  int prepareThreshold
           
 boolean readOnly
           
protected  java.util.Map typemap
           
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
protected AbstractJdbc2Connection(java.lang.String host, int port, java.lang.String user, java.lang.String database, java.util.Properties info, java.lang.String url)
           
 
Method Summary
 void addDataType(java.lang.String type, java.lang.Class klass)
          This allows client code to add a handler for one of org.postgresql's more unique data types.
 void addDataType(java.lang.String type, java.lang.String name)
          This allows client code to add a handler for one of org.postgresql's more unique data types.
 void addWarning(java.sql.SQLWarning warn)
           
 void cancelQuery()
          Cancel the current query executing on this connection.
 void clearWarnings()
           
 void close()
          In some cases, it is desirable to immediately release a Connection's database and JDBC resources instead of waiting for them to be automatically released.
 void commit()
           
 java.sql.Statement createStatement()
           
abstract  java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
           
protected  void enableDriverManagerLogging()
           
 byte[] encodeString(java.lang.String str)
          Encode a string using the database's client_encoding (usually UNICODE, but can vary on older server versions).
 java.lang.String escapeString(java.lang.String str)
          Escapes a string for use as string-literal within an SQL command.
 java.sql.ResultSet execSQLQuery(java.lang.String s)
          Execute a SQL query that returns a single resultset.
 java.sql.ResultSet execSQLQuery(java.lang.String s, int resultSetType, int resultSetConcurrency)
          Simple query execution.
 void execSQLUpdate(java.lang.String s)
          Execute a SQL query that does not return results.
protected  void finalize()
           
 boolean getAutoCommit()
           
 java.lang.String getCatalog()
           
 java.lang.String getCursorName()
           
 java.lang.String getDBVersionNumber()
           
 Encoding getEncoding()
           
 Fastpath getFastpathAPI()
          This returns the Fastpath API for the current connection.
protected  java.lang.String getIsolationLevelName(int level)
           
 java.lang.String getJavaClass(int oid)
           
 LargeObjectManager getLargeObjectAPI()
          This returns the LargeObject API for the current connection.
 Logger getLogger()
           
abstract  java.sql.DatabaseMetaData getMetaData()
           
 PGNotification[] getNotifications()
          This method returns any notifications that have been received since the last call to this method.
 java.lang.Object getObject(java.lang.String type, java.lang.String value)
          Construct and return an appropriate object for the given type and value.
 java.lang.String getPGType(int oid)
          Look up the postgresql type name for a given oid.
 int getPGType(java.lang.String typeName)
          Look up the oid for a given postgresql type name.
 java.util.Iterator getPGTypeNamesWithSQLTypes()
           
 int getPrepareThreshold()
          Get the default server-side prepare reuse threshold for statements created from this connection.
 int getProtocolVersion()
           
 QueryExecutor getQueryExecutor()
          Get the QueryExecutor implementation for this connection.
 int getServerMajorVersion()
           
 int getServerMinorVersion()
           
 int getSQLType(int oid)
          Look up the SQL typecode for a given type oid.
 int getSQLType(java.lang.String pgTypeName)
          Look up the SQL typecode for a given postgresql type name.
 boolean getStandardConformingStrings()
          Returns whether the server treats string-literals according to the SQL standard or if it uses traditional PostgreSQL escaping rules.
 boolean getStringVarcharFlag()
           
 TimestampUtils getTimestampUtils()
           
 int getTransactionIsolation()
           
 java.util.Map getTypeMap()
           
 java.lang.String getURL()
           
 java.lang.String getUserName()
           
 java.sql.SQLWarning getWarnings()
           
 boolean haveMinimumCompatibleVersion(java.lang.String ver)
          Check if we should use driver behaviour introduced in a particular driver version.
 boolean haveMinimumServerVersion(java.lang.String ver)
          Is the server we are connected to running at least this version?
 boolean isClosed()
           
 boolean isReadOnly()
           
 java.lang.String nativeSQL(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql)
           
abstract  java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
           
abstract  java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 void rollback()
           
 void setAutoCommit(boolean autoCommit)
           
 void setCatalog(java.lang.String catalog)
           
 void setCursorName(java.lang.String cursor)
           
 void setPrepareThreshold(int newThreshold)
          Set the default statement reuse threshold before enabling server-side prepare.
 void setReadOnly(boolean readOnly)
           
 void setTransactionIsolation(int level)
           
 void setTypeMapImpl(java.util.Map map)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.sql.Connection
createStatement, getHoldability, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setHoldability, setSavepoint, setSavepoint, setTypeMap
 

Field Detail

prepareThreshold

protected int prepareThreshold

autoCommit

public boolean autoCommit

readOnly

public boolean readOnly

bindStringAsVarchar

public final boolean bindStringAsVarchar

firstWarning

public java.sql.SQLWarning firstWarning

typemap

protected java.util.Map typemap

metadata

protected java.sql.DatabaseMetaData metadata
Constructor Detail

AbstractJdbc2Connection

protected AbstractJdbc2Connection(java.lang.String host,
                                  int port,
                                  java.lang.String user,
                                  java.lang.String database,
                                  java.util.Properties info,
                                  java.lang.String url)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException
Method Detail

getMetaData

public abstract java.sql.DatabaseMetaData getMetaData()
                                               throws java.sql.SQLException
Specified by:
getMetaData in interface java.sql.Connection
Throws:
java.sql.SQLException

getTimestampUtils

public TimestampUtils getTimestampUtils()
Specified by:
getTimestampUtils in interface BaseConnection

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public abstract java.sql.Statement createStatement(int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public abstract java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                            int resultSetType,
                                                            int resultSetConcurrency)
                                                     throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public abstract java.sql.CallableStatement prepareCall(java.lang.String sql,
                                                       int resultSetType,
                                                       int resultSetConcurrency)
                                                throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Specified by:
getTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

getQueryExecutor

public QueryExecutor getQueryExecutor()
Description copied from interface: BaseConnection
Get the QueryExecutor implementation for this connection.

Specified by:
getQueryExecutor in interface BaseConnection
Returns:
the (non-null) executor

addWarning

public void addWarning(java.sql.SQLWarning warn)

execSQLQuery

public java.sql.ResultSet execSQLQuery(java.lang.String s)
                                throws java.sql.SQLException
Description copied from interface: BaseConnection
Execute a SQL query that returns a single resultset. Never causes a new transaction to be started regardless of the autocommit setting.

Specified by:
execSQLQuery in interface BaseConnection
Parameters:
s - the query to execute
Returns:
the (non-null) returned resultset
Throws:
java.sql.SQLException - if something goes wrong.

execSQLQuery

public java.sql.ResultSet execSQLQuery(java.lang.String s,
                                       int resultSetType,
                                       int resultSetConcurrency)
                                throws java.sql.SQLException
Simple query execution.

Specified by:
execSQLQuery in interface BaseConnection
Throws:
java.sql.SQLException

execSQLUpdate

public void execSQLUpdate(java.lang.String s)
                   throws java.sql.SQLException
Description copied from interface: BaseConnection
Execute a SQL query that does not return results. Never causes a new transaction to be started regardless of the autocommit setting.

Specified by:
execSQLUpdate in interface BaseConnection
Parameters:
s - the query to execute
Throws:
java.sql.SQLException - if something goes wrong.

setCursorName

public void setCursorName(java.lang.String cursor)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getCursorName

public java.lang.String getCursorName()
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

getURL

public java.lang.String getURL()
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

getUserName

public java.lang.String getUserName()
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

getFastpathAPI

public Fastpath getFastpathAPI()
                        throws java.sql.SQLException
Description copied from interface: PGConnection
This returns the Fastpath API for the current connection.

Specified by:
getFastpathAPI in interface PGConnection
Throws:
java.sql.SQLException

getLargeObjectAPI

public LargeObjectManager getLargeObjectAPI()
                                     throws java.sql.SQLException
Description copied from interface: PGConnection
This returns the LargeObject API for the current connection.

Specified by:
getLargeObjectAPI in interface PGConnection
Throws:
java.sql.SQLException

getObject

public java.lang.Object getObject(java.lang.String type,
                                  java.lang.String value)
                           throws java.sql.SQLException
Description copied from interface: BaseConnection
Construct and return an appropriate object for the given type and value. This only considers the types registered via PGConnection.addDataType(String,Class) and PGConnection.addDataType(String,String).

If no class is registered as handling the given type, then a generic PGobject instance is returned.

Specified by:
getObject in interface BaseConnection
Specified by:
getObject in interface PGConnection
Parameters:
type - the backend typename
value - the type-specific string representation of the value
Returns:
an appropriate object; never null.
Throws:
java.sql.SQLException - if something goes wrong

addDataType

public void addDataType(java.lang.String type,
                        java.lang.String name)
Description copied from interface: PGConnection
This allows client code to add a handler for one of org.postgresql's more unique data types. It is approximately equivalent to addDataType(type, Class.forName(name)).

Specified by:
addDataType in interface PGConnection

addDataType

public void addDataType(java.lang.String type,
                        java.lang.Class klass)
                 throws java.sql.SQLException
Description copied from interface: PGConnection
This allows client code to add a handler for one of org.postgresql's more unique data types.

NOTE: This is not part of JDBC, but an extension.

The best way to use this is as follows:

 ...
 ((org.postgresql.PGConnection)myconn).addDataType("mytype", my.class.name.class);
 ...
 

where myconn is an open Connection to org.postgresql.

The handling class must extend org.postgresql.util.PGobject

Specified by:
addDataType in interface PGConnection
Parameters:
type - the PostgreSQL type to register
klass - the class implementing the Java representation of the type; this class must implement PGobject).
Throws:
java.sql.SQLException - if klass does not implement PGobject).
See Also:
PGobject

close

public void close()
In some cases, it is desirable to immediately release a Connection's database and JDBC resources instead of waiting for them to be automatically released. Note: A Connection is automatically closed when it is garbage collected. Certain fatal errors also result in a closed connection.

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException - if a database access error occurs

nativeSQL

public java.lang.String nativeSQL(java.lang.String sql)
                           throws java.sql.SQLException
Specified by:
nativeSQL in interface java.sql.Connection
Throws:
java.sql.SQLException

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Specified by:
getWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
Specified by:
setReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Specified by:
isReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Specified by:
setAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

getAutoCommit

public boolean getAutoCommit()
Specified by:
getAutoCommit in interface java.sql.Connection

commit

public void commit()
            throws java.sql.SQLException
Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback()
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Specified by:
getTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
Specified by:
setTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

getIsolationLevelName

protected java.lang.String getIsolationLevelName(int level)

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
Specified by:
setCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Specified by:
getCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getDBVersionNumber

public java.lang.String getDBVersionNumber()

getServerMajorVersion

public int getServerMajorVersion()

getServerMinorVersion

public int getServerMinorVersion()

haveMinimumServerVersion

public boolean haveMinimumServerVersion(java.lang.String ver)
Is the server we are connected to running at least this version? This comparison method will fail whenever a major or minor version goes to two digits (10.3.0) or (7.10.1).

Specified by:
haveMinimumServerVersion in interface BaseConnection
Parameters:
ver - the server version to check
Returns:
true if the server version is at least "ver".

haveMinimumCompatibleVersion

public boolean haveMinimumCompatibleVersion(java.lang.String ver)
Description copied from interface: BaseConnection
Check if we should use driver behaviour introduced in a particular driver version. This defaults to behaving as the actual driver's version but can be overridden by the "compatible" URL parameter.

Specified by:
haveMinimumCompatibleVersion in interface BaseConnection
Parameters:
ver - the driver version to check
Returns:
true if the driver's behavioural version is at least "ver".

getEncoding

public Encoding getEncoding()
Specified by:
getEncoding in interface PGConnection

encodeString

public byte[] encodeString(java.lang.String str)
                    throws java.sql.SQLException
Description copied from interface: BaseConnection
Encode a string using the database's client_encoding (usually UNICODE, but can vary on older server versions). This is used when constructing synthetic resultsets (for example, in metadata methods).

Specified by:
encodeString in interface BaseConnection
Parameters:
str - the string to encode
Returns:
an encoded representation of the string
Throws:
java.sql.SQLException - if something goes wrong.

escapeString

public java.lang.String escapeString(java.lang.String str)
                              throws java.sql.SQLException
Description copied from interface: BaseConnection
Escapes a string for use as string-literal within an SQL command. The method chooses the applicable escaping rules based on the value of BaseConnection.getStandardConformingStrings().

Specified by:
escapeString in interface BaseConnection
Parameters:
str - a string value
Returns:
the escaped representation of the string
Throws:
java.sql.SQLException - if the string contains a \0 character

getStandardConformingStrings

public boolean getStandardConformingStrings()
Description copied from interface: BaseConnection
Returns whether the server treats string-literals according to the SQL standard or if it uses traditional PostgreSQL escaping rules. Versions up to 8.1 always treated backslashes as escape characters in string-literals. Since 8.2, this depends on the value of the standard_conforming_strings server variable.

Specified by:
getStandardConformingStrings in interface BaseConnection
Returns:
true if the server treats string literals according to the SQL standard
See Also:
ProtocolConnection.getStandardConformingStrings()

getSQLType

public int getSQLType(int oid)
               throws java.sql.SQLException
Description copied from interface: BaseConnection
Look up the SQL typecode for a given type oid.

Specified by:
getSQLType in interface BaseConnection
Specified by:
getSQLType in interface PGConnection
Parameters:
oid - the type's OID
Returns:
the SQL typecode (a constant from Types) for the type
Throws:
java.sql.SQLException - if something goes wrong

getPGTypeNamesWithSQLTypes

public java.util.Iterator getPGTypeNamesWithSQLTypes()

getPGType

public int getPGType(java.lang.String typeName)
              throws java.sql.SQLException
Description copied from interface: BaseConnection
Look up the oid for a given postgresql type name. This is the inverse of BaseConnection.getPGType(int).

Specified by:
getPGType in interface BaseConnection
Specified by:
getPGType in interface PGConnection
Parameters:
typeName - the server type name to look up
Returns:
oid the type's OID, or 0 if unknown
Throws:
java.sql.SQLException - if something goes wrong

getJavaClass

public java.lang.String getJavaClass(int oid)
                              throws java.sql.SQLException
Specified by:
getJavaClass in interface BaseConnection
Throws:
java.sql.SQLException

getPGType

public java.lang.String getPGType(int oid)
                           throws java.sql.SQLException
Description copied from interface: BaseConnection
Look up the postgresql type name for a given oid. This is the inverse of BaseConnection.getPGType(String).

Specified by:
getPGType in interface BaseConnection
Specified by:
getPGType in interface PGConnection
Parameters:
oid - the type's OID
Returns:
the server type name for that OID, or null if unknown
Throws:
java.sql.SQLException - if something goes wrong

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Specified by:
isClosed in interface java.sql.Connection
Throws:
java.sql.SQLException

cancelQuery

public void cancelQuery()
                 throws java.sql.SQLException
Description copied from interface: BaseConnection
Cancel the current query executing on this connection.

Specified by:
cancelQuery in interface BaseConnection
Throws:
java.sql.SQLException - if something goes wrong.

getNotifications

public PGNotification[] getNotifications()
                                  throws java.sql.SQLException
Description copied from interface: PGConnection
This method returns any notifications that have been received since the last call to this method. Returns null if there have been no notifications.

Specified by:
getNotifications in interface PGConnection
Throws:
java.sql.SQLException

getPrepareThreshold

public int getPrepareThreshold()
Description copied from interface: PGConnection
Get the default server-side prepare reuse threshold for statements created from this connection.

Specified by:
getPrepareThreshold in interface PGConnection
Returns:
the current threshold

setPrepareThreshold

public void setPrepareThreshold(int newThreshold)
Description copied from interface: PGConnection
Set the default statement reuse threshold before enabling server-side prepare. See PGStatement.setPrepareThreshold(int) for details.

Specified by:
setPrepareThreshold in interface PGConnection
Parameters:
newThreshold - the new threshold

setTypeMapImpl

public void setTypeMapImpl(java.util.Map map)
                    throws java.sql.SQLException
Throws:
java.sql.SQLException

getLogger

public Logger getLogger()
Specified by:
getLogger in interface BaseConnection

enableDriverManagerLogging

protected void enableDriverManagerLogging()

getSQLType

public int getSQLType(java.lang.String pgTypeName)
Description copied from interface: BaseConnection
Look up the SQL typecode for a given postgresql type name.

Specified by:
getSQLType in interface BaseConnection
Specified by:
getSQLType in interface PGConnection
Parameters:
pgTypeName - the server type name to look up
Returns:
the SQL typecode (a constant from Types) for the type

getProtocolVersion

public int getProtocolVersion()

getStringVarcharFlag

public boolean getStringVarcharFlag()
Specified by:
getStringVarcharFlag in interface BaseConnection