org.javasimon.jdbc
Class SimonConnection

java.lang.Object
  extended by org.javasimon.jdbc.SimonConnection
All Implemented Interfaces:
Connection, Wrapper

public final class SimonConnection
extends Object
implements Connection

Class implements Simon JDBC proxy connection.

Every method of this connection is implemented as call of real connection method. Several methods have added work with Simons (starting, stoping, etc.) for monitoring purposes.

From all statement-return-methods (createStatement(*), prepareStatement(*), prepareCall(*)) connection returns own implementation of statement classes. Those classes are also proxies and provides additional Simons for monitoring features of JDBC driver.

Monitoring connection ensure following Simons:

Since:
1.0
Version:
$Revision: 304 $ $Date: 2011-04-08 10:39:02 +0200 (Fri, 08 Apr 2011) $
Author:
Radovan Sninsky
See Also:
Connection

Field Summary
private  Counter commits
           
private  Connection conn
           
private  Split life
           
private  Counter rollbacks
           
private  String suffix
           
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
SimonConnection(Connection conn, String prefix)
          Class constructor, initializes Simons (lifespan, active, commits and rollbacks) related to DB connection.
 
Method Summary
 void clearWarnings()
          
 void close()
          Closes real connection, stops lifespan Simon and decrease active Simon.
 void commit()
          Commits real connection and increase commits Simon.
 Statement createStatement()
          Calls real createStatement and wraps returned statement by Simon's statement.
 Statement createStatement(int rsType, int rsConcurrency)
          Calls real createStatement and wraps returned statement by Simon's statement.
 Statement createStatement(int rsType, int rsConcurrency, int rsHoldability)
          Calls real createStatement and wraps returned statement by Simon's statement.
 boolean getAutoCommit()
          
 String getCatalog()
          
 int getHoldability()
          
 DatabaseMetaData getMetaData()
          
 int getTransactionIsolation()
          
 Map<String,Class<?>> getTypeMap()
          
 SQLWarning getWarnings()
          
 boolean isClosed()
          
 boolean isReadOnly()
          
 String nativeSQL(String s)
          
 CallableStatement prepareCall(String sql)
          Calls real prepareCall and wraps returned statement by Simon's statement.
 CallableStatement prepareCall(String sql, int rsType, int rsConcurrency)
          Calls real prepareCall and wraps returned statement by Simon's statement.
 CallableStatement prepareCall(String sql, int rsType, int rsConcurrency, int rsHoldability)
          Calls real prepareCall and wraps returned statement by Simon's statement.
 PreparedStatement prepareStatement(String sql)
          Calls real prepareStatement and wraps returned statement by Simon's statement.
 PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
          Calls real prepareStatement and wraps returned statement by Simon's statement.
 PreparedStatement prepareStatement(String sql, int[] columnIndexes)
          Calls real prepareStatement and wraps returned statement by Simon's statement.
 PreparedStatement prepareStatement(String sql, int rsType, int rsConcurrency)
          Calls real prepareStatement and wraps returned statement by Simon's statement.
 PreparedStatement prepareStatement(String sql, int rsType, int rsConcurrency, int rsHoldability)
          Calls real prepareStatement and wraps returned statement by Simon's statement.
 PreparedStatement prepareStatement(String sql, String[] columnNames)
          Calls real prepareStatement and wraps returned statement by Simon's statement.
 void releaseSavepoint(Savepoint savepoint)
          
 void rollback()
          Rollback real connection and increase rollbacks Simon.
 void rollback(Savepoint savepoint)
          Rollback real connection and increase rollbacks Simon.
 void setAutoCommit(boolean b)
          
 void setCatalog(String s)
          
 void setHoldability(int i)
          
 void setReadOnly(boolean b)
          
 Savepoint setSavepoint()
          
 Savepoint setSavepoint(String s)
          
 void setTransactionIsolation(int i)
          
 void setTypeMap(Map<String,Class<?>> stringClassMap)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.sql.Connection
createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStruct, getClientInfo, getClientInfo, isValid, setClientInfo, setClientInfo
 
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
 

Field Detail

conn

private Connection conn

suffix

private String suffix

life

private Split life

commits

private Counter commits

rollbacks

private Counter rollbacks
Constructor Detail

SimonConnection

public SimonConnection(Connection conn,
                       String prefix)
Class constructor, initializes Simons (lifespan, active, commits and rollbacks) related to DB connection.

Parameters:
conn - real DB connection
prefix - hierarchy prefix for connection Simons
Method Detail

close

public void close()
           throws SQLException
Closes real connection, stops lifespan Simon and decrease active Simon.

Specified by:
close in interface Connection
Throws:
SQLException - if real operation fails

commit

public void commit()
            throws SQLException
Commits real connection and increase commits Simon.

Specified by:
commit in interface Connection
Throws:
SQLException - if real commit fails

rollback

public void rollback()
              throws SQLException
Rollback real connection and increase rollbacks Simon.

Specified by:
rollback in interface Connection
Throws:
SQLException - if real operation fails

rollback

public void rollback(Savepoint savepoint)
              throws SQLException
Rollback real connection and increase rollbacks Simon.

Specified by:
rollback in interface Connection
Parameters:
savepoint - the Savepoint object to roll back to
Throws:
SQLException - if real operation fails

createStatement

public Statement createStatement()
                          throws SQLException
Calls real createStatement and wraps returned statement by Simon's statement.

Specified by:
createStatement in interface Connection
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

createStatement

public Statement createStatement(int rsType,
                                 int rsConcurrency)
                          throws SQLException
Calls real createStatement and wraps returned statement by Simon's statement.

Specified by:
createStatement in interface Connection
Parameters:
rsType - result set type
rsConcurrency - result set concurrency
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

createStatement

public Statement createStatement(int rsType,
                                 int rsConcurrency,
                                 int rsHoldability)
                          throws SQLException
Calls real createStatement and wraps returned statement by Simon's statement.

Specified by:
createStatement in interface Connection
Parameters:
rsType - result set type
rsConcurrency - result set concurrency
rsHoldability - result set holdability
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareStatement

public PreparedStatement prepareStatement(String sql)
                                   throws SQLException
Calls real prepareStatement and wraps returned statement by Simon's statement.

Specified by:
prepareStatement in interface Connection
Parameters:
sql - SQL statement
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          int autoGeneratedKeys)
                                   throws SQLException
Calls real prepareStatement and wraps returned statement by Simon's statement.

Specified by:
prepareStatement in interface Connection
Parameters:
sql - SQL statement
autoGeneratedKeys - auto generated keys
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          int rsType,
                                          int rsConcurrency)
                                   throws SQLException
Calls real prepareStatement and wraps returned statement by Simon's statement.

Specified by:
prepareStatement in interface Connection
Parameters:
sql - SQL statement
rsType - result set type
rsConcurrency - result set concurrency
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          int rsType,
                                          int rsConcurrency,
                                          int rsHoldability)
                                   throws SQLException
Calls real prepareStatement and wraps returned statement by Simon's statement.

Specified by:
prepareStatement in interface Connection
Parameters:
sql - SQL statement
rsType - result set type
rsConcurrency - result set concurrency
rsHoldability - result set holdability
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          int[] columnIndexes)
                                   throws SQLException
Calls real prepareStatement and wraps returned statement by Simon's statement.

Specified by:
prepareStatement in interface Connection
Parameters:
sql - SQL statement
columnIndexes - an array of column indexes indicating the columns that should be returned from the inserted row or rows
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          String[] columnNames)
                                   throws SQLException
Calls real prepareStatement and wraps returned statement by Simon's statement.

Specified by:
prepareStatement in interface Connection
Parameters:
sql - SQL statement
columnNames - an array of column names indicating the columns that should be returned from the inserted row or rows
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareCall

public CallableStatement prepareCall(String sql)
                              throws SQLException
Calls real prepareCall and wraps returned statement by Simon's statement.

Specified by:
prepareCall in interface Connection
Parameters:
sql - an SQL statement, typically a JDBC function call escape string
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareCall

public CallableStatement prepareCall(String sql,
                                     int rsType,
                                     int rsConcurrency)
                              throws SQLException
Calls real prepareCall and wraps returned statement by Simon's statement.

Specified by:
prepareCall in interface Connection
Parameters:
sql - an SQL statement, typically a JDBC function call escape string
rsType - result set type
rsConcurrency - result set concurrency
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

prepareCall

public CallableStatement prepareCall(String sql,
                                     int rsType,
                                     int rsConcurrency,
                                     int rsHoldability)
                              throws SQLException
Calls real prepareCall and wraps returned statement by Simon's statement.

Specified by:
prepareCall in interface Connection
Parameters:
sql - an SQL statement, typically a JDBC function call escape string
rsType - result set type
rsConcurrency - result set concurrency
rsHoldability - result set holdability
Returns:
Simon's statement with wraped real statement
Throws:
SQLException - if real operation fails

nativeSQL

public String nativeSQL(String s)
                 throws SQLException

Specified by:
nativeSQL in interface Connection
Throws:
SQLException

setAutoCommit

public void setAutoCommit(boolean b)
                   throws SQLException

Specified by:
setAutoCommit in interface Connection
Throws:
SQLException

getAutoCommit

public boolean getAutoCommit()
                      throws SQLException

Specified by:
getAutoCommit in interface Connection
Throws:
SQLException

isClosed

public boolean isClosed()
                 throws SQLException

Specified by:
isClosed in interface Connection
Throws:
SQLException

getMetaData

public DatabaseMetaData getMetaData()
                             throws SQLException

Specified by:
getMetaData in interface Connection
Throws:
SQLException

setReadOnly

public void setReadOnly(boolean b)
                 throws SQLException

Specified by:
setReadOnly in interface Connection
Throws:
SQLException

isReadOnly

public boolean isReadOnly()
                   throws SQLException

Specified by:
isReadOnly in interface Connection
Throws:
SQLException

setCatalog

public void setCatalog(String s)
                throws SQLException

Specified by:
setCatalog in interface Connection
Throws:
SQLException

getCatalog

public String getCatalog()
                  throws SQLException

Specified by:
getCatalog in interface Connection
Throws:
SQLException

setTransactionIsolation

public void setTransactionIsolation(int i)
                             throws SQLException

Specified by:
setTransactionIsolation in interface Connection
Throws:
SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws SQLException

Specified by:
getTransactionIsolation 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

getTypeMap

public Map<String,Class<?>> getTypeMap()
                                throws SQLException

Specified by:
getTypeMap in interface Connection
Throws:
SQLException

setTypeMap

public void setTypeMap(Map<String,Class<?>> stringClassMap)
                throws SQLException

Specified by:
setTypeMap in interface Connection
Throws:
SQLException

setHoldability

public void setHoldability(int i)
                    throws SQLException

Specified by:
setHoldability in interface Connection
Throws:
SQLException

getHoldability

public int getHoldability()
                   throws SQLException

Specified by:
getHoldability in interface Connection
Throws:
SQLException

setSavepoint

public Savepoint setSavepoint()
                       throws SQLException

Specified by:
setSavepoint in interface Connection
Throws:
SQLException

setSavepoint

public Savepoint setSavepoint(String s)
                       throws SQLException

Specified by:
setSavepoint in interface Connection
Throws:
SQLException

releaseSavepoint

public void releaseSavepoint(Savepoint savepoint)
                      throws SQLException

Specified by:
releaseSavepoint in interface Connection
Throws:
SQLException


Copyright © 2011. All Rights Reserved.