org.apache.jetspeed.components.rdbms.ojb
Class ConnectionManagerImpl

java.lang.Object
  extended by org.apache.jetspeed.components.rdbms.ojb.ConnectionManagerImpl
All Implemented Interfaces:
org.apache.ojb.broker.accesslayer.ConnectionManagerIF

public class ConnectionManagerImpl
extends Object
implements org.apache.ojb.broker.accesslayer.ConnectionManagerIF

Manages Connection ressources. This class is a replacement for the default ConnectionManagerImpl that comes with OJB. It differs from this class only in its way to get a connection factory. The default OJB class always uses the class configured in OJB.properties. This implementation looks up the factory configured for the given JCD first and uses the default factory class only if no class is configured in the JCD.

Version:
$Id$
Author:
Thomas Mahler
See Also:
ConnectionManagerIF

Field Summary
private  org.apache.ojb.broker.util.batch.BatchConnection batchCon
           
private  boolean batchMode
           
private  org.apache.ojb.broker.PersistenceBroker broker
           
private  Connection con
           
private static Map connectionFactories
           
private  org.apache.ojb.broker.accesslayer.ConnectionFactory connectionFactory
           
private  boolean isInLocalTransaction
           
private  org.apache.ojb.broker.metadata.JdbcConnectionDescriptor jcd
           
private  org.apache.ojb.broker.util.logging.Logger log
           
private  boolean originalAutoCommitState
           
private  org.apache.ojb.broker.PBKey pbKey
           
private  org.apache.ojb.broker.platforms.Platform platform
           
 
Constructor Summary
ConnectionManagerImpl(org.apache.ojb.broker.PersistenceBroker broker)
           
 
Method Summary
 void clearBatch()
          Clear batch (if the batch mode where used).
 void executeBatch()
          Execute batch (if the batch mode where used).
 void executeBatchIfNecessary()
          Execute batch if the number of statements in it exceeded the limit (if the batch mode where used).
 Connection getConnection()
          Returns the underlying connection, requested from ConnectionFactory.
 org.apache.ojb.broker.metadata.JdbcConnectionDescriptor getConnectionDescriptor()
          Returns the associated JdbcConnectionDescriptor
 org.apache.ojb.broker.platforms.Platform getSupportedPlatform()
           
 org.apache.ojb.broker.accesslayer.ConnectionFactory getUnderlyingConnectionFactory()
          Returns the underlying used ConnectionFactory implementation.
 boolean isAlive(Connection conn)
          Check if underlying connection was alive.
 boolean isBatchMode()
           
 boolean isInLocalTransaction()
           
 void localBegin()
          Start transaction on the underlying connection.
 void localCommit()
          Call commit on the underlying connection.
 void localRollback()
          Call rollback on the underlying connection.
 void releaseConnection()
          Release connection to the ConnectionFactory, make sure that you call the method in either case, it's the only way to free the connection.
protected  void restoreAutoCommitState()
          Reset autoCommit state.
 void setBatchMode(boolean mode)
          Sets the batch mode on or off - this switch only works if you set attribute batch-mode in jdbc-connection-descriptor true and your database support batch mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.ojb.broker.util.logging.Logger log

broker

private org.apache.ojb.broker.PersistenceBroker broker

connectionFactory

private org.apache.ojb.broker.accesslayer.ConnectionFactory connectionFactory

jcd

private org.apache.ojb.broker.metadata.JdbcConnectionDescriptor jcd

platform

private org.apache.ojb.broker.platforms.Platform platform

con

private Connection con

pbKey

private org.apache.ojb.broker.PBKey pbKey

originalAutoCommitState

private boolean originalAutoCommitState

isInLocalTransaction

private boolean isInLocalTransaction

batchMode

private boolean batchMode

batchCon

private org.apache.ojb.broker.util.batch.BatchConnection batchCon

connectionFactories

private static Map connectionFactories
Constructor Detail

ConnectionManagerImpl

public ConnectionManagerImpl(org.apache.ojb.broker.PersistenceBroker broker)
Method Detail

getConnectionDescriptor

public org.apache.ojb.broker.metadata.JdbcConnectionDescriptor getConnectionDescriptor()
Returns the associated JdbcConnectionDescriptor

Specified by:
getConnectionDescriptor in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF

getSupportedPlatform

public org.apache.ojb.broker.platforms.Platform getSupportedPlatform()
Specified by:
getSupportedPlatform in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF

getConnection

public Connection getConnection()
                         throws org.apache.ojb.broker.accesslayer.LookupException
Returns the underlying connection, requested from ConnectionFactory.

PB#beginTransaction() opens a single jdbc connection via PB#serviceConnectionManager().localBegin(). If you call PB#serviceConnectionManager().getConnection() later it returns the already opened connection. The PB instance will release the used connection during PB#commitTransaction() or PB#abortTransaction() or PB#close().

NOTE: Never call Connection.close() on the connection requested from the ConnectionManager. Cleanup of used connection is done by OJB itself. If you need to release a used connection call releaseConnection().

Specified by:
getConnection in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF
Throws:
org.apache.ojb.broker.accesslayer.LookupException

localBegin

public void localBegin()
Start transaction on the underlying connection.

Specified by:
localBegin in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF

localCommit

public void localCommit()
Call commit on the underlying connection.

Specified by:
localCommit in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF

localRollback

public void localRollback()
Call rollback on the underlying connection.

Specified by:
localRollback in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF

restoreAutoCommitState

protected void restoreAutoCommitState()
Reset autoCommit state.


isAlive

public boolean isAlive(Connection conn)
Check if underlying connection was alive.

Specified by:
isAlive in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF

isInLocalTransaction

public boolean isInLocalTransaction()
Specified by:
isInLocalTransaction in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF

releaseConnection

public void releaseConnection()
Release connection to the ConnectionFactory, make sure that you call the method in either case, it's the only way to free the connection.

Specified by:
releaseConnection in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF

getUnderlyingConnectionFactory

public org.apache.ojb.broker.accesslayer.ConnectionFactory getUnderlyingConnectionFactory()
Returns the underlying used ConnectionFactory implementation.


setBatchMode

public void setBatchMode(boolean mode)
Sets the batch mode on or off - this switch only works if you set attribute batch-mode in jdbc-connection-descriptor true and your database support batch mode.

Specified by:
setBatchMode in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF
Parameters:
mode - the batch mode

isBatchMode

public boolean isBatchMode()
Specified by:
isBatchMode in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF
Returns:
the batch mode.

executeBatch

public void executeBatch()
                  throws org.apache.ojb.broker.accesslayer.OJBBatchUpdateException
Execute batch (if the batch mode where used).

Specified by:
executeBatch in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF
Throws:
org.apache.ojb.broker.accesslayer.OJBBatchUpdateException

executeBatchIfNecessary

public void executeBatchIfNecessary()
                             throws org.apache.ojb.broker.accesslayer.OJBBatchUpdateException
Execute batch if the number of statements in it exceeded the limit (if the batch mode where used).

Specified by:
executeBatchIfNecessary in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF
Throws:
org.apache.ojb.broker.accesslayer.OJBBatchUpdateException

clearBatch

public void clearBatch()
Clear batch (if the batch mode where used).

Specified by:
clearBatch in interface org.apache.ojb.broker.accesslayer.ConnectionManagerIF


Copyright © 1999-2007 Apache Software Foundation. All Rights Reserved.