org.dmonix.jdbc
Class DMConnection

java.lang.Object
  extended byorg.dmonix.jdbc.DMConnection
All Implemented Interfaces:
java.sql.Connection

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

The class represents a JDBC connection in the connection pool.
It is essentially a wrapper around a real JDBC connection.
The DMConnection object maintains a state flag to indicate if the connection is in use and the time the connection was taken from the pool.
This time is used by the ConnectionReaper class to identify hanging connections

Copyright: Copyright (c) 2003

Company: dmonix.org

Version:
1.0
Author:
Peter Nerg

Field Summary
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
DMConnection(java.sql.Connection conn, DMConnectionPool pool)
           
 
Method Summary
 void clearWarnings()
          See the corresponding method on java.sql.Connection
 void close()
          Returns the connection to the pool.
 void commit()
          See the corresponding method on java.sql.Connection
 java.sql.Statement createStatement()
          See the corresponding method on java.sql.Connection
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
          See the corresponding method on java.sql.Connection
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          See the corresponding method on java.sql.Connection
 void destroy()
          Permanently closes the connection and removes it from the pool.
protected  void expireLease()
          Marks the connection as free.
 boolean getAutoCommit()
          See the corresponding method on java.sql.Connection
 java.lang.String getCatalog()
          See the corresponding method on java.sql.Connection
protected  java.sql.Connection getConnection()
          Returns the connection object.
 int getHoldability()
          See the corresponding method on java.sql.Connection
 long getLastUse()
          Returns the time when this connection was last used.
 java.sql.DatabaseMetaData getMetaData()
          See the corresponding method on java.sql.Connection
 int getTransactionIsolation()
          See the corresponding method on java.sql.Connection
 java.util.Map getTypeMap()
          See the corresponding method on java.sql.Connection
 java.sql.SQLWarning getWarnings()
          See the corresponding method on java.sql.Connection
 boolean inUse()
          Returns the status flag for this connection.
 boolean isClosed()
          See the corresponding method on java.sql.Connection
 boolean isReadOnly()
          See the corresponding method on java.sql.Connection
 boolean lease()
          The method attempts to mark a connection as busy.
 java.lang.String nativeSQL(java.lang.String sql)
          See the corresponding method on java.sql.Connection
 java.sql.CallableStatement prepareCall(java.lang.String sql)
          See the corresponding method on java.sql.Connection
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          See the corresponding method on java.sql.Connection
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          See the corresponding method on java.sql.Connection
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          See the corresponding method on java.sql.Connection
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autogeneratedKeys)
          See the corresponding method on java.sql.Connection
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes)
          See the corresponding method on java.sql.Connection
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          See the corresponding method on java.sql.Connection
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          See the corresponding method on java.sql.Connection
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames)
          See the corresponding method on java.sql.Connection
 void releaseSavepoint(java.sql.Savepoint savepoint)
          See the corresponding method on java.sql.Connection
 void rollback()
          See the corresponding method on java.sql.Connection
 void rollback(java.sql.Savepoint savepoint)
          See the corresponding method on java.sql.Connection
 void setAutoCommit(boolean autoCommit)
          See the corresponding method on java.sql.Connection
 void setCatalog(java.lang.String catalog)
          See the corresponding method on java.sql.Connection
 void setHoldability(int holdability)
          See the corresponding method on java.sql.Connection
 void setReadOnly(boolean readOnly)
          See the corresponding method on java.sql.Connection
 java.sql.Savepoint setSavepoint()
          See the corresponding method on java.sql.Connection
 java.sql.Savepoint setSavepoint(java.lang.String savepoint)
          See the corresponding method on java.sql.Connection
 void setTransactionIsolation(int level)
          See the corresponding method on java.sql.Connection
 void setTypeMap(java.util.Map map)
          See the corresponding method on java.sql.Connection
 java.lang.String toString()
           
 boolean validate()
          The method attempts to validate if the connection is busy or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DMConnection

public DMConnection(java.sql.Connection conn,
                    DMConnectionPool pool)
Method Detail

lease

public boolean lease()
The method attempts to mark a connection as busy.

Returns:
true if the connection was free, false otherwise

validate

public boolean validate()
The method attempts to validate if the connection is busy or not.
The validation check runs a simple SQL query over the connection to see if it throws an exception.

Returns:
false if an exception is caught, true otherwise

inUse

public boolean inUse()
Returns the status flag for this connection.

Returns:

getLastUse

public long getLastUse()
Returns the time when this connection was last used.

Returns:

close

public void close()
           throws java.sql.SQLException
Returns the connection to the pool.
The method will not close the connection, it will only be returned to the connection pool.
If the connection needs to be closed permanently the method destroy() should be used.

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

destroy

public void destroy()
             throws java.sql.SQLException
Permanently closes the connection and removes it from the pool.

Throws:
java.sql.SQLException

expireLease

protected void expireLease()
Marks the connection as free.


getConnection

protected java.sql.Connection getConnection()
Returns the connection object.

Returns:
The connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency,
                                                   int resultSetHoldability)
                                            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
sql -
resultSetType -
resultSetConcurrency -
resultSetHoldability -
Returns:
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int autogeneratedKeys)
                                            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
sql -
autogeneratedKeys -
Returns:
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int[] columnIndexes)
                                            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
sql -
columnIndexes -
Returns:
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   java.lang.String[] columnNames)
                                            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
sql -
columnNames -
Returns:
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
sql -
Returns:
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareStatement in interface java.sql.Connection
Parameters:
sql -
resultSetType -
resultSetConcurrency -
Returns:
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency,
                                              int resultSetHoldability)
                                       throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareCall in interface java.sql.Connection
Parameters:
sql -
resultSetType -
resultSetConcurrency -
resultSetHoldability -
Returns:
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareCall in interface java.sql.Connection
Parameters:
sql -
resultSetType -
resultSetConcurrency -
Returns:
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
prepareCall in interface java.sql.Connection
Parameters:
sql -
Returns:
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency,
                                          int resultSetHoldability)
                                   throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
createStatement in interface java.sql.Connection
Parameters:
resultSetType -
resultSetConcurrency -
resultSetHoldability -
Returns:
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency)
                                   throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
createStatement in interface java.sql.Connection
Parameters:
resultSetType -
resultSetConcurrency -
Returns:
Throws:
java.sql.SQLException

nativeSQL

public java.lang.String nativeSQL(java.lang.String sql)
                           throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
nativeSQL in interface java.sql.Connection
Parameters:
sql -
Returns:
Throws:
java.sql.SQLException

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

commit

public void commit()
            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

rollback

public void rollback()
              throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

rollback

public void rollback(java.sql.Savepoint savepoint)
              throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

setHoldability

public void setHoldability(int holdability)
                    throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
setReadOnly in interface java.sql.Connection
Parameters:
readOnly -
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
setSavepoint in interface java.sql.Connection
Returns:
The savepoint
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String savepoint)
                                throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
See the corresponding method on java.sql.Connection

Specified by:
setTransactionIsolation in interface java.sql.Connection
Parameters:
level -
Throws:
java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
See the corresponding method on java.sql.Connection

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

toString

public java.lang.String toString()


Copyright © 1998-2005 dmonix.org Peter Nerg, All Rights Reserved.