jxDBCon 0.9z

org.sourceforge.jxdbcon.postgresql
Class PGConnection

java.lang.Object
  |
  +--org.sourceforge.jxdbcon.AbstractConnection
        |
        +--org.sourceforge.jxdbcon.postgresql.PGConnection
All Implemented Interfaces:
Cloneable, Connection, InfoKeys, PGInfoKeys
Direct Known Subclasses:
IntConnection, LibConnection, NetConnection

public abstract class PGConnection
extends AbstractConnection
implements PGInfoKeys

The PGConnection class is the abstract superclass for Connections with PostgreSQL. TODO:

Version:
$Revision: 1.30 $
Author:
Keve Müller

Field Summary
protected  boolean autoCommit
          Are we in autoCommit mode?.
protected  String clientEncoding
          What encoding uses the protocol?.
private  int databaseVersion
          The backend's version.
private static Map dbenc2jenc
          Conversion map for encoding names returned by getdatabaseencoding() and names used by Java.
protected  String dbEncoding
          What encoding uses the database?.
private  DatabaseMetaData dbmeta
          The metadata instance.
private  int defCursor
          A counter for naming unnamed cursors.
protected  boolean isBigEndian
          Is the backend sending data in Big Endian?
 Map oidTypeMap
          Map from oid to AbstractType.
private  List passByVal
          List of AbstractType values we should pass by value when calling functions.
private  PGProtocol proto
          The Protocol instance that talks to the backend.
 
Fields inherited from class org.sourceforge.jxdbcon.AbstractConnection
info, typeMap, warning
 
Fields inherited from interface org.sourceforge.jxdbcon.postgresql.PGInfoKeys
FORCECLIENTENC, OPTIONS, PROTOVERSION, SETTIMEZONE, STRICTSCHEMA, TTY, USEASYNC, USECLIENTENC, USEDBENC, USESSL
 
Fields inherited from interface org.sourceforge.jxdbcon.InfoKeys
CATALOG, DESCRIPTION, DRIVER, HOST, PASSWORD, PORT, SUBDRIVER, USER
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
PGConnection()
           
 
Method Summary
 void close()
          Close the connection.
 void commit()
          Commit the transaction and start a new one.
protected abstract  PGProtocol connect(Properties info)
          Open a connection.
 Statement createStatement(int resultSetType, int resultSetConcurrency)
          Create a statement.
(package private)  PGFuncResult exec(long oid, byte[][] args)
           
(package private)  PGExecResult exec(String sql)
           
(package private)  PGFuncResult exec(String funcName, byte[][] args)
          Execute a function with arguments by name.
(package private)  int[] executeBatch(List batch)
           
 PGExecResult executeSQL(String sql, AbstractStatement stmt)
           
protected  void fillPropertyInfo(ArrayList pi, Properties info)
          Fill the given list with the DriverPropertyInfo structures recognized by the driver.
 PGFunc[] findFunc(long funcOid, int argLen)
          Find a PostgreSQL function by oid and parameter list length.
(package private)  PGFunc[] findFunc(String funcName, int argLen)
          Find a function by name and parameter list length.
 PGFunc findFunc(String funcName, long[] argOids)
          Find a PostgreSQL function by name and parameter list oids.
 boolean getAutoCommit()
          Return the auto commit state.
(package private)  PGConversionContext getConversionContext(boolean isBinary)
          Return a conversion context suitable to convert from database internal representation to Java types.
protected  EscapeContext getEscapeContext(Object paramBuf, ConversionContext paramContext)
          Create an EscapeContext.
 ResultSet getGeneratedKeys(String sql, PGExecResult res)
           
 DatabaseMetaData getMetaData()
           
private  DatabaseMetaData getPGDatabaseMetaData(String version, String url)
          Creates an instance of PGDatabaseMetaData.
 PGProtocol getProtocol()
           
 ResultSet getResultSet(AbstractStatement stmt, PGExecResult res)
           
 ResultSet getResultSet(AbstractStatement stmt, PGExecResult res, DefaultResultSetMetaData resMeta)
           
 int getTransactionIsolation()
          Get the transaction isolation level.
(package private)  AbstractType getType(long oid, int typmod)
           
 AbstractType getType(String name)
          Get the AbstractType given its name.
 long getTypeOid(String name)
          Get the oid of a given type.
private  String learnEndianness()
          Learn about the endianness used by the database and its version.
private  void learnTypes()
          Learn about the types supported by the database.
protected  void open(String url, Properties uinfo)
          Open a connection to the given URL.
 CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
           
 PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
           
(package private)  Object[] res2Types(PGExecResult res)
           
 void rollback()
          Rollback work.
 void setAutoCommit(boolean autoCommit)
          Set auto commit mode.
 void setCatalog(String catalog)
          Set the current catalog.
 void setTransactionIsolation(int level)
          Set the transaction isolation level.
protected  void takeOver(AbstractConnection conn)
          Take over the connection to the dbms created by a different instance.
 String toString()
          Format the connection's properties into a String.
 
Methods inherited from class org.sourceforge.jxdbcon.AbstractConnection
clearWarnings, clone, createStatement, createStatement, duplicate, finalize, getCatalog, getHoldability, getInfo, getTypeMap, getWarnings, isClosed, isReadOnly, nativeSQL, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setHoldability, setReadOnly, setSavepoint, setSavepoint, setTypeMap
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

autoCommit

protected boolean autoCommit
Are we in autoCommit mode?. Initially the connection will be in auto commit mode.


clientEncoding

protected String clientEncoding
What encoding uses the protocol?. This is the translated value usable inside Java.


databaseVersion

private int databaseVersion
The backend's version.


dbenc2jenc

private static final Map dbenc2jenc
Conversion map for encoding names returned by getdatabaseencoding() and names used by Java. This table is derived from conv.c of the PostgreSQL backend source with the following id: $Id: PGConnection.java,v 1.30 2002/05/07 21:42:38 kevem Exp $


dbEncoding

protected String dbEncoding
What encoding uses the database?. This is the translated value usable inside Java.


dbmeta

private DatabaseMetaData dbmeta
The metadata instance.


defCursor

private int defCursor
A counter for naming unnamed cursors.


isBigEndian

protected boolean isBigEndian
Is the backend sending data in Big Endian?


oidTypeMap

public Map oidTypeMap
Map from oid to AbstractType.


passByVal

private List passByVal
List of AbstractType values we should pass by value when calling functions. NB: Currently initialised, but not used.


proto

private PGProtocol proto
The Protocol instance that talks to the backend.

Constructor Detail

PGConnection

public PGConnection()
Method Detail

close

public void close()
           throws SQLException
Description copied from class: AbstractConnection
Close the connection. Null everything. This function is implicitely invoked on an open Connection when it gets finalized.

Specified by:
close in interface Connection
Overrides:
close in class AbstractConnection
Throws:
SQLException - if an error occurs

commit

public void commit()
            throws SQLException
Commit the transaction and start a new one.

Specified by:
commit in interface Connection
Overrides:
commit in class AbstractConnection
Throws:
SQLException - if a database error occurs

connect

protected abstract PGProtocol connect(Properties info)
                               throws SQLException
Open a connection.

SQLException

createStatement

public Statement createStatement(int resultSetType,
                                 int resultSetConcurrency)
                          throws SQLException
Description copied from class: AbstractConnection
Create a statement. Connection implementations override this.

Specified by:
createStatement in interface Connection
Specified by:
createStatement in class AbstractConnection
SQLException

exec

PGFuncResult exec(long oid,
                  byte[][] args)

exec

PGExecResult exec(String sql)

exec

PGFuncResult exec(String funcName,
                  byte[][] args)
            throws SQLException
Execute a function with arguments by name.

SQLException

executeBatch

int[] executeBatch(List batch)
             throws SQLException
SQLException

executeSQL

public PGExecResult executeSQL(String sql,
                               AbstractStatement stmt)
                        throws SQLException
SQLException

fillPropertyInfo

protected void fillPropertyInfo(ArrayList pi,
                                Properties info)
Description copied from class: AbstractConnection
Fill the given list with the DriverPropertyInfo structures recognized by the driver.

Overrides:
fillPropertyInfo in class AbstractConnection

findFunc

public PGFunc[] findFunc(long funcOid,
                         int argLen)
                  throws SQLException
Find a PostgreSQL function by oid and parameter list length.

Returns:
a zero length array if the function is not found, or a one length array if it is.
SQLException

findFunc

PGFunc[] findFunc(String funcName,
                  int argLen)
            throws SQLException
Find a function by name and parameter list length.

SQLException

findFunc

public PGFunc findFunc(String funcName,
                       long[] argOids)
                throws SQLException
Find a PostgreSQL function by name and parameter list oids.

Returns:
null, if no match is found
Throws:
SQLException - if more than one function matches.

getAutoCommit

public boolean getAutoCommit()
Return the auto commit state.

Specified by:
getAutoCommit in interface Connection
Overrides:
getAutoCommit in class AbstractConnection
Returns:
true.

getConversionContext

PGConversionContext getConversionContext(boolean isBinary)
Return a conversion context suitable to convert from database internal representation to Java types.

Parameters:
isBinary - whether a binary or a text converter is needed.

getEscapeContext

protected EscapeContext getEscapeContext(Object paramBuf,
                                         ConversionContext paramContext)
Description copied from class: AbstractConnection
Create an EscapeContext.

Specified by:
getEscapeContext in class AbstractConnection

getGeneratedKeys

public ResultSet getGeneratedKeys(String sql,
                                  PGExecResult res)
                           throws SQLException
SQLException

getMetaData

public DatabaseMetaData getMetaData()
Specified by:
getMetaData in interface Connection

getPGDatabaseMetaData

private DatabaseMetaData getPGDatabaseMetaData(String version,
                                               String url)
                                        throws SQLException
Creates an instance of PGDatabaseMetaData. As a side effect set the databaseVersion property.

SQLException

getProtocol

public PGProtocol getProtocol()

getResultSet

public ResultSet getResultSet(AbstractStatement stmt,
                              PGExecResult res)
                       throws SQLException
SQLException

getResultSet

public ResultSet getResultSet(AbstractStatement stmt,
                              PGExecResult res,
                              DefaultResultSetMetaData resMeta)
                       throws SQLException
SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws SQLException
Description copied from class: AbstractConnection
Get the transaction isolation level.

Specified by:
getTransactionIsolation in interface Connection
Overrides:
getTransactionIsolation in class AbstractConnection
Returns:
TRANSACTION_NONE.
Throws:
SQLException - if a database error occurs

getType

AbstractType getType(long oid,
                     int typmod)

getType

public AbstractType getType(String name)
                     throws SQLException
Get the AbstractType given its name.

SQLException

getTypeOid

public long getTypeOid(String name)
                throws SQLException
Get the oid of a given type.

SQLException

learnEndianness

private String learnEndianness()
                        throws SQLException
Learn about the endianness used by the database and its version. A binary query is issued and the result is analysed.

SQLException

learnTypes

private void learnTypes()
                 throws SQLException
Learn about the types supported by the database.

SQLException

open

protected final void open(String url,
                          Properties uinfo)
                   throws SQLException
Open a connection to the given URL. Establish a connection to the backend, then query it for important information.

Overrides:
open in class AbstractConnection
SQLException

prepareCall

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

prepareStatement

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

res2Types

Object[] res2Types(PGExecResult res)

rollback

public void rollback()
              throws SQLException
Description copied from class: AbstractConnection
Rollback work. Not supported, we defaulted to auto commit mode.

Specified by:
rollback in interface Connection
Overrides:
rollback in class AbstractConnection
Throws:
SQLException - if a database error occurs

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws SQLException
Set auto commit mode. If the auto commit state is the same, nothing is done. If a transaction is in progress and autocommit is requested, then the transaction is commited.

Specified by:
setAutoCommit in interface Connection
Overrides:
setAutoCommit in class AbstractConnection
Parameters:
autoCommit - the desired auto commit mode
Throws:
SQLException - if a database error occurs

setCatalog

public void setCatalog(String catalog)
                throws SQLException
Description copied from class: AbstractConnection
Set the current catalog. Default behaviour is to silently ignore this request, thus not supporting catalogs.

Specified by:
setCatalog in interface Connection
Overrides:
setCatalog in class AbstractConnection
Parameters:
catalog - the new catalog
Throws:
SQLException - if a database error occurs

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws SQLException
Description copied from class: AbstractConnection
Set the transaction isolation level. Anything but TRANSACTION_NONE is not supported.

Specified by:
setTransactionIsolation in interface Connection
Overrides:
setTransactionIsolation in class AbstractConnection
Parameters:
level - the desired isolation level
Throws:
SQLException - if a database error occurs

takeOver

protected void takeOver(AbstractConnection conn)
                 throws SQLException
Description copied from class: AbstractConnection
Take over the connection to the dbms created by a different instance.

Overrides:
takeOver in class AbstractConnection
SQLException

toString

public String toString()
Description copied from class: AbstractConnection
Format the connection's properties into a String.

Overrides:
toString in class AbstractConnection
Returns:
a verbose description of the connections properties

jxDBCon 0.9z

Copyright © 2001,2002 Keve Müller; see LICENSE file for details.