org.postgresql.jdbc2
Class AbstractJdbc2Connection

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

public abstract class AbstractJdbc2Connection
extends 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
           
 SQLWarning firstWarning
           
protected  DatabaseMetaData metadata
           
protected  int prepareThreshold
           
 boolean readOnly
           
protected  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(String host, int port, String user, String database, Properties info, String url)
           
 
Method Summary
 void addDataType(String type, Class klass)
          This allows client code to add a handler for one of org.postgresql's more unique data types.
 void addDataType(String type, String name)
          This allows client code to add a handler for one of org.postgresql's more unique data types.
 void addWarning(SQLWarning warn)
           
 void cancelQuery()
          Cancel the current query executing on this connection.
protected  void checkClosed()
           
 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()
           
 Statement createStatement()
           
abstract  Statement createStatement(int resultSetType, int resultSetConcurrency)
           
protected  TypeInfo createTypeInfo(BaseConnection conn, int unknownLength)
           
protected  void enableDriverManagerLogging()
           
 byte[] encodeString(String str)
          Encode a string using the database's client_encoding (usually UTF8, but can vary on older server versions).
 String escapeString(String str)
          Escapes a string for use as string-literal within an SQL command.
 ResultSet execSQLQuery(String s)
          Execute a SQL query that returns a single resultset.
 ResultSet execSQLQuery(String s, int resultSetType, int resultSetConcurrency)
          Simple query execution.
 void execSQLUpdate(String s)
          Execute a SQL query that does not return results.
protected  void finalize()
           
 boolean getAutoCommit()
           
 String getCatalog()
           
 CopyManager getCopyAPI()
          This returns the COPY API for the current connection.
 String getCursorName()
           
 String getDBVersionNumber()
           
 Encoding getEncoding()
           
 Fastpath getFastpathAPI()
          This returns the Fastpath API for the current connection.
protected  String getIsolationLevelName(int level)
           
 LargeObjectManager getLargeObjectAPI()
          This returns the LargeObject API for the current connection.
 Logger getLogger()
           
abstract  DatabaseMetaData getMetaData()
           
 PGNotification[] getNotifications()
          This method returns any notifications that have been received since the last call to this method.
 Object getObject(String type, String value)
          Construct and return an appropriate object for the given type and value.
 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()
           
 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()
           
 int getTransactionState()
          Get the current transaction state of this connection.
 TypeInfo getTypeInfo()
           
 Map getTypeMap()
           
 String getURL()
           
 String getUserName()
           
 SQLWarning getWarnings()
           
 boolean haveMinimumCompatibleVersion(String ver)
          Check if we should use driver behaviour introduced in a particular driver version.
 boolean haveMinimumServerVersion(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).
 boolean isClosed()
           
 boolean isReadOnly()
           
 String nativeSQL(String sql)
           
 CallableStatement prepareCall(String sql)
           
abstract  CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
           
 PreparedStatement prepareStatement(String sql)
           
abstract  PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
           
 void rollback()
           
 void setAutoCommit(boolean autoCommit)
           
 void setCatalog(String catalog)
           
 void setCursorName(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(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
createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStruct, getClientInfo, getClientInfo, getHoldability, isValid, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setClientInfo, setClientInfo, setHoldability, setSavepoint, setSavepoint, setTypeMap
 
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
 

Field Detail

prepareThreshold

protected int prepareThreshold

autoCommit

public boolean autoCommit

readOnly

public boolean readOnly

bindStringAsVarchar

public final boolean bindStringAsVarchar

firstWarning

public SQLWarning firstWarning

typemap

protected Map typemap

metadata

protected DatabaseMetaData metadata
Constructor Detail

AbstractJdbc2Connection

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

getMetaData

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

getTimestampUtils

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

createStatement

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

createStatement

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

prepareStatement

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

prepareStatement

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

prepareCall

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

prepareCall

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

getTypeMap

public Map getTypeMap()
               throws SQLException
Specified by:
getTypeMap in interface Connection
Throws:
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(SQLWarning warn)

execSQLQuery

public ResultSet execSQLQuery(String s)
                       throws 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:
SQLException - if something goes wrong.

execSQLQuery

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

Specified by:
execSQLQuery in interface BaseConnection
Throws:
SQLException

execSQLUpdate

public void execSQLUpdate(String s)
                   throws 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:
SQLException - if something goes wrong.

setCursorName

public void setCursorName(String cursor)
                   throws SQLException
Throws:
SQLException

getCursorName

public String getCursorName()
                     throws SQLException
Throws:
SQLException

getURL

public String getURL()
              throws SQLException
Throws:
SQLException

getUserName

public String getUserName()
                   throws SQLException
Throws:
SQLException

getFastpathAPI

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

Specified by:
getFastpathAPI in interface PGConnection
Throws:
SQLException

getLargeObjectAPI

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

Specified by:
getLargeObjectAPI in interface PGConnection
Throws:
SQLException

getObject

public Object getObject(String type,
                        String value)
                 throws 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
Parameters:
type - the backend typename
value - the type-specific string representation of the value
Returns:
an appropriate object; never null.
Throws:
SQLException - if something goes wrong

createTypeInfo

protected TypeInfo createTypeInfo(BaseConnection conn,
                                  int unknownLength)

getTypeInfo

public TypeInfo getTypeInfo()
Specified by:
getTypeInfo in interface BaseConnection

addDataType

public void addDataType(String type,
                        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(String type,
                        Class klass)
                 throws 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:
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 Connection
Throws:
SQLException - if a database access error occurs

nativeSQL

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

getWarnings

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

clearWarnings

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

setReadOnly

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

isReadOnly

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

setAutoCommit

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

getAutoCommit

public boolean getAutoCommit()
                      throws SQLException
Specified by:
getAutoCommit in interface Connection
Throws:
SQLException

commit

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

checkClosed

protected void checkClosed()
                    throws SQLException
Throws:
SQLException

rollback

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

getTransactionState

public int getTransactionState()
Description copied from interface: BaseConnection
Get the current transaction state of this connection.

Specified by:
getTransactionState in interface BaseConnection
Returns:
a ProtocolConnection.TRANSACTION_* constant.

getTransactionIsolation

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

setTransactionIsolation

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

getIsolationLevelName

protected String getIsolationLevelName(int level)

setCatalog

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

getCatalog

public String getCatalog()
                  throws SQLException
Specified by:
getCatalog in interface Connection
Throws:
SQLException

finalize

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

getDBVersionNumber

public String getDBVersionNumber()

getServerMajorVersion

public int getServerMajorVersion()

getServerMinorVersion

public int getServerMinorVersion()

haveMinimumServerVersion

public boolean haveMinimumServerVersion(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(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 BaseConnection

encodeString

public byte[] encodeString(String str)
                    throws SQLException
Description copied from interface: BaseConnection
Encode a string using the database's client_encoding (usually UTF8, 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:
SQLException - if something goes wrong.

escapeString

public String escapeString(String str)
                    throws 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:
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()

isClosed

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

cancelQuery

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

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

getNotifications

public PGNotification[] getNotifications()
                                  throws 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:
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(Map map)
                    throws SQLException
Throws:
SQLException

getLogger

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

enableDriverManagerLogging

protected void enableDriverManagerLogging()

getProtocolVersion

public int getProtocolVersion()

getStringVarcharFlag

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

getCopyAPI

public CopyManager getCopyAPI()
                       throws SQLException
Description copied from interface: PGConnection
This returns the COPY API for the current connection.

Specified by:
getCopyAPI in interface PGConnection
Throws:
SQLException


Copyright © 2013. All Rights Reserved.