velosurf.sql
Class ConnectionWrapper

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

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
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.
 
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.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.
 void enterBusyState()
          Enter busy state.
 boolean getAutoCommit()
          Get autocommit flag.
 java.lang.String getCatalog()
          Catalog getter.
 int getHoldability()
          Get holdability.
 long getLastInsertId(java.sql.Statement statement)
          Get last inserted ID.
 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.
 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 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.
 
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.


closed

private boolean closed
Closed state.


checkStatement

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

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

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


~ooOoo~