velosurf.sql
Class ConnectionWrapper

java.lang.Object
  extended by velosurf.sql.ConnectionWrapper
All Implemented Interfaces:
java.sql.Connection, java.sql.Wrapper

public class ConnectionWrapper
extends java.lang.Object
implements java.sql.Connection

Connection wrapper class. Allows the handling of a busy state

Author:
Claude Brisson

Field Summary
(package private) static java.lang.reflect.Method _createArrayOf
           
(package private) static java.lang.reflect.Method _createBlob
           
(package private) static java.lang.reflect.Method _createClob
           
(package private) static java.lang.reflect.Method _createNClob
           
(package private) static java.lang.reflect.Method _createSQLXML
           
(package private) static java.lang.reflect.Method _createStruct
           
(package private) static java.lang.reflect.Method _getClientInfo
           
(package private) static java.lang.reflect.Method _getClientInfo2
           
(package private) static java.lang.reflect.Method _isValid
           
(package private) static java.lang.reflect.Method _isWrapperFor
           
(package private) static java.lang.reflect.Method _setClientInfo
           
(package private) static java.lang.reflect.Method _setClientInfo2
           
private  int busy
          Busy state.
private  java.sql.PreparedStatement checkStatement
          statement used to check connection ("select 1").
private  boolean closed
          Closed state.
private  java.sql.Connection connection
          Wrapped connection.
private  DriverInfo driver
          Infos on the driver.
private  long lastUse
          Last use
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
ConnectionWrapper(DriverInfo driver, java.sql.Connection connection)
          Constructor.
 
Method Summary
 boolean check()
          Check connection.
 void clearWarnings()
          Clear SQL warnings.
 void close()
          Close.
 void commit()
          Commit.
 java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements)
           
 java.sql.Blob createBlob()
           
 java.sql.Clob createClob()
           
 java.sql.NClob createNClob()
           
 java.sql.SQLXML createSQLXML()
           
 java.sql.Statement createStatement()
          Create a statement.
 java.sql.Statement createStatement(int i, int j)
          Create a statement.
 java.sql.Statement createStatement(int i, int j, int k)
          Create a statement.
 java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes)
           
 void enterBusyState()
          Enter busy state.
 boolean getAutoCommit()
          Get autocommit flag.
 java.lang.String getCatalog()
          Catalog getter.
 java.util.Properties getClientInfo()
           
 java.lang.String getClientInfo(java.lang.String name)
           
private static java.lang.reflect.Method getConnectionMethod(java.lang.String name, java.lang.Class[] parameterTypes)
           
 int getHoldability()
          Get holdability.
 long getLastInsertId(java.sql.Statement statement)
          Get last inserted ID.
 long getLastUse()
          Get last use timestamp
 java.sql.DatabaseMetaData getMetaData()
          Get meta data
 int getTransactionIsolation()
          Transaction isolation getter.
 java.util.Map getTypeMap()
          Get type map.
 java.sql.SQLWarning getWarnings()
          Get SQL warnings.
 boolean isBusy()
          Check busy state.
 boolean isClosed()
          Check the closed state.
 boolean isReadOnly()
          Check the read-only state.
 boolean isValid(int timeout)
           
 boolean isWrapperFor(java.lang.Class<?> iface)
           
 void leaveBusyState()
          Leave busy state.
 java.lang.String nativeSQL(java.lang.String s)
          Gets native SQL for a query.
 java.sql.CallableStatement prepareCall(java.lang.String s)
          Prepare a callable statement.
 java.sql.CallableStatement prepareCall(java.lang.String s, int i, int j)
          Prepare a call.
 java.sql.CallableStatement prepareCall(java.lang.String s, int i, int j, int k)
          Prepare a callable statement.
 java.sql.PreparedStatement prepareStatement(java.lang.String s)
          Prepare a statement.
 java.sql.PreparedStatement prepareStatement(java.lang.String s, int i)
          Prepare a statement.
 java.sql.PreparedStatement prepareStatement(java.lang.String s, int[] ai)
          Prepare a statement.
 java.sql.PreparedStatement prepareStatement(java.lang.String s, int i, int j)
          Prepare a statement.
 java.sql.PreparedStatement prepareStatement(java.lang.String s, int i, int j, int k)
          Prepare a statement.
 java.sql.PreparedStatement prepareStatement(java.lang.String s, java.lang.String[] as)
          Prepare a statement.
 void releaseSavepoint(java.sql.Savepoint savepoint)
          Release savepoint.
 void rollback()
          Rollback.
 void rollback(java.sql.Savepoint savepoint)
          Rollback.
 void setAutoCommit(boolean flag)
          Set autocommit flag.
 void setCatalog(java.lang.String s)
          Catalog setter.
 void setClientInfo(java.util.Properties properties)
           
 void setClientInfo(java.lang.String name, java.lang.String value)
           
 void setHoldability(int i)
          Set holdability.
 void setReadOnly(boolean flag)
          set read-only flag
 java.sql.Savepoint setSavepoint()
          Savepoint setter.
 java.sql.Savepoint setSavepoint(java.lang.String s)
          Set named savepoint.
 void setTransactionIsolation(int i)
          Transaction isolation setter.
 void setTypeMap(java.util.Map map)
          Set type map.
 java.sql.Connection unwrap()
          Unwrap the connection.
<T> T
unwrap(java.lang.Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

driver

private DriverInfo driver
Infos on the driver.


connection

private java.sql.Connection connection
Wrapped connection.


busy

private int busy
Busy state.


lastUse

private long lastUse
Last use


closed

private boolean closed
Closed state.


checkStatement

private java.sql.PreparedStatement checkStatement
statement used to check connection ("select 1").


_createClob

static java.lang.reflect.Method _createClob

_createBlob

static java.lang.reflect.Method _createBlob

_createNClob

static java.lang.reflect.Method _createNClob

_createSQLXML

static java.lang.reflect.Method _createSQLXML

_isValid

static java.lang.reflect.Method _isValid

_setClientInfo

static java.lang.reflect.Method _setClientInfo

_setClientInfo2

static java.lang.reflect.Method _setClientInfo2

_getClientInfo

static java.lang.reflect.Method _getClientInfo

_getClientInfo2

static java.lang.reflect.Method _getClientInfo2

_createArrayOf

static java.lang.reflect.Method _createArrayOf

_createStruct

static java.lang.reflect.Method _createStruct

_isWrapperFor

static java.lang.reflect.Method _isWrapperFor
Constructor Detail

ConnectionWrapper

public ConnectionWrapper(DriverInfo driver,
                         java.sql.Connection connection)
Constructor.

Parameters:
driver - infos on the driver
connection - connection to be wrapped
Method Detail

unwrap

public java.sql.Connection unwrap()
Unwrap the connection.

Returns:
the unwrapped connection

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Create a statement.

Specified by:
createStatement in interface java.sql.Connection
Returns:
created statement
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String s)
                                            throws java.sql.SQLException
Prepare a statement.

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
s - SQL query
Returns:
prepared statement
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String s)
                                       throws java.sql.SQLException
Prepare a callable statement.

Specified by:
prepareCall in interface java.sql.Connection
Parameters:
s - SQL query
Returns:
prepared callable statement
Throws:
java.sql.SQLException

nativeSQL

public java.lang.String nativeSQL(java.lang.String s)
                           throws java.sql.SQLException
Gets native SQL for a query.

Specified by:
nativeSQL in interface java.sql.Connection
Parameters:
s - query
Returns:
native SQL
Throws:
java.sql.SQLException

setAutoCommit

public void setAutoCommit(boolean flag)
                   throws java.sql.SQLException
Set autocommit flag.

Specified by:
setAutoCommit in interface java.sql.Connection
Parameters:
flag - autocommit
Throws:
java.sql.SQLException

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Get autocommit flag.

Specified by:
getAutoCommit in interface java.sql.Connection
Returns:
autocommit flag
Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Commit.

Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback()
              throws java.sql.SQLException
Rollback.

Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
Close.

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Check the closed state.

Specified by:
isClosed in interface java.sql.Connection
Returns:
closed state
Throws:
java.sql.SQLException

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Get meta data

Specified by:
getMetaData in interface java.sql.Connection
Returns:
database meta data
Throws:
java.sql.SQLException

setReadOnly

public void setReadOnly(boolean flag)
                 throws java.sql.SQLException
set read-only flag

Specified by:
setReadOnly in interface java.sql.Connection
Parameters:
flag - read-only
Throws:
java.sql.SQLException

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Check the read-only state.

Specified by:
isReadOnly in interface java.sql.Connection
Returns:
read-only state
Throws:
java.sql.SQLException

setCatalog

public void setCatalog(java.lang.String s)
                throws java.sql.SQLException
Catalog setter.

Specified by:
setCatalog in interface java.sql.Connection
Parameters:
s - catalog
Throws:
java.sql.SQLException

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Catalog getter.

Specified by:
getCatalog in interface java.sql.Connection
Returns:
catalog
Throws:
java.sql.SQLException

setTransactionIsolation

public void setTransactionIsolation(int i)
                             throws java.sql.SQLException
Transaction isolation setter.

Specified by:
setTransactionIsolation in interface java.sql.Connection
Parameters:
i - transaction isolation
Throws:
java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Transaction isolation getter.

Specified by:
getTransactionIsolation in interface java.sql.Connection
Returns:
transaction isolation
Throws:
java.sql.SQLException

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Get SQL warnings.

Specified by:
getWarnings in interface java.sql.Connection
Returns:
next SQL Warning.
Throws:
java.sql.SQLException

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Clear SQL warnings.

Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int i,
                                          int j)
                                   throws java.sql.SQLException
Create a statement.

Specified by:
createStatement in interface java.sql.Connection
Parameters:
i - result set type
j - result set concurrency
Returns:
new statement
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String s,
                                                   int i,
                                                   int j)
                                            throws java.sql.SQLException
Prepare a statement.

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
s - SQL query
i - result set type
j - result set concurrency
Returns:
prepared statement
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String s,
                                              int i,
                                              int j)
                                       throws java.sql.SQLException
Prepare a call.

Specified by:
prepareCall in interface java.sql.Connection
Parameters:
s - SQL query
i - result set type
j - result set concurrency
Returns:
callable statement
Throws:
java.sql.SQLException

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Get type map.

Specified by:
getTypeMap in interface java.sql.Connection
Returns:
type map
Throws:
java.sql.SQLException

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
Set type map.

Specified by:
setTypeMap in interface java.sql.Connection
Parameters:
map - type map
Throws:
java.sql.SQLException

setHoldability

public void setHoldability(int i)
                    throws java.sql.SQLException
Set holdability.

Specified by:
setHoldability in interface java.sql.Connection
Parameters:
i - holdability
Throws:
java.sql.SQLException

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
Get holdability.

Specified by:
getHoldability in interface java.sql.Connection
Returns:
holdability
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
Savepoint setter.

Specified by:
setSavepoint in interface java.sql.Connection
Returns:
save point
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String s)
                                throws java.sql.SQLException
Set named savepoint.

Specified by:
setSavepoint in interface java.sql.Connection
Parameters:
s - savepoint name
Returns:
savepoint
Throws:
java.sql.SQLException

rollback

public void rollback(java.sql.Savepoint savepoint)
              throws java.sql.SQLException
Rollback.

Specified by:
rollback in interface java.sql.Connection
Parameters:
savepoint - savepoint
Throws:
java.sql.SQLException

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
Release savepoint.

Specified by:
releaseSavepoint in interface java.sql.Connection
Parameters:
savepoint - savepoint
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int i,
                                          int j,
                                          int k)
                                   throws java.sql.SQLException
Create a statement.

Specified by:
createStatement in interface java.sql.Connection
Parameters:
i - result set type
j - result set concurrency
k - result set holdability
Returns:
created statement
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String s,
                                                   int i,
                                                   int j,
                                                   int k)
                                            throws java.sql.SQLException
Prepare a statement.

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
s - SQL query
i - result set type
j - result set concurrency
k - result set holdability
Returns:
prepared statement
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String s,
                                              int i,
                                              int j,
                                              int k)
                                       throws java.sql.SQLException
Prepare a callable statement.

Specified by:
prepareCall in interface java.sql.Connection
Parameters:
s - SQL query
i - result set type
j - result set concurrency
k - result set holdability
Returns:
prepared statement
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String s,
                                                   int i)
                                            throws java.sql.SQLException
Prepare a statement.

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
s - SQL query
i - autogenerated keys
Returns:
prepared statement
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String s,
                                                   int[] ai)
                                            throws java.sql.SQLException
Prepare a statement.

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
s - SQL query
ai - autogenerated keys column indexes
Returns:
prepared statement
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String s,
                                                   java.lang.String[] as)
                                            throws java.sql.SQLException
Prepare a statement.

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
s - SQL query
as - autogenerated keys column names
Returns:
prepared statement
Throws:
java.sql.SQLException

enterBusyState

public void enterBusyState()
Enter busy state.


leaveBusyState

public void leaveBusyState()
Leave busy state.


isBusy

public boolean isBusy()
Check busy state.

Returns:
busy state

getLastUse

public long getLastUse()
Get last use timestamp

Returns:
last use

getLastInsertId

public long getLastInsertId(java.sql.Statement statement)
                     throws java.sql.SQLException
Get last inserted ID.

Parameters:
statement -
Returns:
last inserted id
Throws:
java.sql.SQLException

check

public boolean check()
Check connection.

Returns:
true if the connection is ok

getConnectionMethod

private static java.lang.reflect.Method getConnectionMethod(java.lang.String name,
                                                            java.lang.Class[] parameterTypes)

createClob

public java.sql.Clob createClob()
                         throws java.sql.SQLException
Specified by:
createClob in interface java.sql.Connection
Throws:
java.sql.SQLException

createBlob

public java.sql.Blob createBlob()
                         throws java.sql.SQLException
Specified by:
createBlob in interface java.sql.Connection
Throws:
java.sql.SQLException

createNClob

public java.sql.NClob createNClob()
                           throws java.sql.SQLException
Specified by:
createNClob in interface java.sql.Connection
Throws:
java.sql.SQLException

createSQLXML

public java.sql.SQLXML createSQLXML()
                             throws java.sql.SQLException
Specified by:
createSQLXML in interface java.sql.Connection
Throws:
java.sql.SQLException

isValid

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

setClientInfo

public void setClientInfo(java.lang.String name,
                          java.lang.String value)
Specified by:
setClientInfo in interface java.sql.Connection

setClientInfo

public void setClientInfo(java.util.Properties properties)
Specified by:
setClientInfo in interface java.sql.Connection

getClientInfo

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

getClientInfo

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

createArrayOf

public java.sql.Array createArrayOf(java.lang.String typeName,
                                    java.lang.Object[] elements)
                             throws java.sql.SQLException
Specified by:
createArrayOf in interface java.sql.Connection
Throws:
java.sql.SQLException

createStruct

public java.sql.Struct createStruct(java.lang.String typeName,
                                    java.lang.Object[] attributes)
                             throws java.sql.SQLException
Specified by:
createStruct in interface java.sql.Connection
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException


~ooOoo~