com.amazon.carbonado.repo.jdbc
Interface JDBCConnectionCapability

All Superinterfaces:
Capability
All Known Subinterfaces:
JDBCSupport<S>

public interface JDBCConnectionCapability
extends Capability

Capability to directly access the JDBC connection being used by the current transaction, which is thread-local. If no transaction is in progress, then the connection is in auto-commit mode.

All connections retrieved from this capability must be properly yielded. Do not close the connection directly, as this interferes with the transaction's ability to properly manage it.

It is perfectly okay for other Carbonado calls to be made while the connection is in use. Also, it is okay to request more connections, although they will usually be the same instance. Failing to yield a connection has an undefined behavior.

 JDBCConnectionCapability cap = repo.getCapability(JDBCConnectionCapability.class);
 Transaction txn = repo.enterTransaction();
 try {
     Connection con = cap.getConnection();
     try {
         ...
     } finally {
         cap.yieldConnection(con);
     }
     ...
     txn.commit();
 } finally {
     txn.exit();
 }
 

Author:
Brian S O'Neill

Method Summary
 Connection getConnection()
          Any connection returned by this method must be closed by calling yieldConnection.
 String getDatabaseProductName()
          Returns the name of the database product connected to.
 boolean isTransactionForUpdate()
          Returns true if a transaction is in progress and it is for update.
 boolean isUniqueConstraintError(SQLException e)
          Examines the SQLSTATE code of the given SQL exception and determines if it is a unique constaint violation.
 FetchException toFetchException(Throwable e)
          Transforms the given throwable into an appropriate fetch exception.
 PersistException toPersistException(Throwable e)
          Transforms the given throwable into an appropriate persist exception.
 void yieldConnection(Connection con)
          Gives up a connection returned from getConnection.
 

Method Detail

getConnection

Connection getConnection()
                         throws FetchException
Any connection returned by this method must be closed by calling yieldConnection.

Throws:
FetchException

yieldConnection

void yieldConnection(Connection con)
                     throws FetchException
Gives up a connection returned from getConnection. Connection must be yielded in same thread that retrieved it.

Throws:
FetchException

toFetchException

FetchException toFetchException(Throwable e)
Transforms the given throwable into an appropriate fetch exception. If it already is a fetch exception, it is simply casted.

Parameters:
e - required exception to transform
Returns:
FetchException, never null
Since:
1.2

toPersistException

PersistException toPersistException(Throwable e)
Transforms the given throwable into an appropriate persist exception. If it already is a persist exception, it is simply casted.

Parameters:
e - required exception to transform
Returns:
PersistException, never null
Since:
1.2

isUniqueConstraintError

boolean isUniqueConstraintError(SQLException e)
Examines the SQLSTATE code of the given SQL exception and determines if it is a unique constaint violation.

Since:
1.2

isTransactionForUpdate

boolean isTransactionForUpdate()
Returns true if a transaction is in progress and it is for update.

Since:
1.2

getDatabaseProductName

String getDatabaseProductName()
Returns the name of the database product connected to.



Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.