org.exolab.castor.jdo.engine
Class GlobalDatabaseImpl

java.lang.Object
  extended byorg.exolab.castor.jdo.engine.AbstractDatabaseImpl
      extended byorg.exolab.castor.jdo.engine.GlobalDatabaseImpl
All Implemented Interfaces:
Database, javax.transaction.Synchronization

public class GlobalDatabaseImpl
extends AbstractDatabaseImpl
implements javax.transaction.Synchronization

An implementation of the JDO database supporting explicit transaction demarcation.

Version:
$Revision: 5951 $ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $
Author:
Werner Guttmann

Field Summary
(package private)  boolean _isPoolInUseForGlobalTransactions
          Flag to indicate whether Database instances should be cached on a per transaction base.
 
Fields inherited from class org.exolab.castor.jdo.engine.AbstractDatabaseImpl
_autoStore, _callback, _classLoader, _ctx, _dbName, _instanceFactory, _lockTimeout, _scope
 
Fields inherited from interface org.exolab.castor.jdo.Database
DbLocked, Exclusive, ReadOnly, Shared
 
Constructor Summary
GlobalDatabaseImpl(java.lang.String dbName, int lockTimeout, CallbackInterceptor callback, InstanceFactory instanceFactory, javax.transaction.Transaction transaction, java.lang.ClassLoader classLoader, boolean autoStore, boolean isPoolInUseForGlobalTransactions)
          Creates an instance of this class.
 
Method Summary
 void afterCompletion(int status)
           
 void beforeCompletion()
           
 void begin()
          Begin a new transaction.
 void close()
          Closes the database.
 void commit()
          Commits and closes the transaction.
protected  void finalize()
          Overrides Object.finalize().
 java.sql.Connection getJdbcConnection()
          Gets the underlying JDBC connection.
 void rollback()
          Rolls back and closes the transaction.
(package private)  void setTxMap(TxDatabaseMap txMap)
           
 
Methods inherited from class org.exolab.castor.jdo.engine.AbstractDatabaseImpl
create, getCacheManager, getClassLoader, getCurrentTransaction, getDatabaseName, getIdentity, getLockEngine, getNamedQuery, getOQLQuery, getOQLQuery, getQuery, getScope, getTransaction, isActive, isAutoStore, isClosed, isLocked, isPersistent, load, load, load, loadSynchronizables, lock, registerSynchronizables, remove, setAutoStore, toString, unregisterSynchronizables, update
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_isPoolInUseForGlobalTransactions

boolean _isPoolInUseForGlobalTransactions
Flag to indicate whether Database instances should be cached on a per transaction base.

Constructor Detail

GlobalDatabaseImpl

public GlobalDatabaseImpl(java.lang.String dbName,
                          int lockTimeout,
                          CallbackInterceptor callback,
                          InstanceFactory instanceFactory,
                          javax.transaction.Transaction transaction,
                          java.lang.ClassLoader classLoader,
                          boolean autoStore,
                          boolean isPoolInUseForGlobalTransactions)
                   throws DatabaseNotFoundException
Creates an instance of this class.

Parameters:
dbName - Database name
lockTimeout - Lock timeout.
callback - Callback interceptors.
instanceFactory - Instance factory to use.
transaction - Current XA transaction.
classLoader - Current class loader.
autoStore - True if auto-storing is enabled.
isPoolInUseForGlobalTransactions - True if Database instanced should be cached.
Throws:
DatabaseNotFoundException - If the specified database cannot be found.
Method Detail

close

public void close()
           throws PersistenceException
Description copied from interface: Database
Closes the database. If a client transaction is in progress the transaction will be rolled back and an exception thrown. If an app-server transaction is in progress, the transaction will commit/rollback when triggered by the application server.

Specified by:
close in interface Database
Specified by:
close in class AbstractDatabaseImpl
Throws:
PersistenceException
See Also:
Database.close()

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides Object.finalize(). Outputs a warning message to the logs if the current DatabaseImpl instance still has valid scope. In this condition - a condition that ideally should not occur at all - we close the instance as well to free up resources.

Throws:
java.lang.Throwable
See Also:
Object.finalize()

begin

public void begin()
           throws PersistenceException
Description copied from interface: Database
Begin a new transaction. A transaction must be open in order to query and persist objects.

Specified by:
begin in interface Database
Specified by:
begin in class AbstractDatabaseImpl
Throws:
PersistenceException
See Also:
Database.begin()

commit

public void commit()
            throws TransactionNotInProgressException,
                   TransactionAbortedException
Description copied from interface: Database
Commits and closes the transaction. All changes made to persistent objects during the transaction are made persistent; objects created during the transaction are made durable; and, objects removed during the transaction are removed from the database.

In other words, any modifications to any data objects which are queried/loaded/created/update to this database is automatically stored to the database and visible to subsequence transactions. (ie. update is solely used for long transaction support and should not be called for any data object queried/loaded/created in the this transaction.)

If the transaction cannot commit, the entire transaction rolls back and a TransactionAbortedException exception is thrown.

After this method returns, the transaction is closed and all persistent objects are transient. Using Database.begin() to open a new transaction will not restore objects to their persistent stage.

Specified by:
commit in interface Database
Specified by:
commit in class AbstractDatabaseImpl
Throws:
TransactionNotInProgressException
TransactionAbortedException
See Also:
Database.commit()

rollback

public void rollback()
              throws TransactionNotInProgressException
Description copied from interface: Database
Rolls back and closes the transaction. All changes made to persistent objects during the transaction are lost, objects created during the transaction are not made durable and objects removed during the transaction continue to exist.

Specified by:
rollback in interface Database
Specified by:
rollback in class AbstractDatabaseImpl
Throws:
TransactionNotInProgressException
See Also:
Database.rollback()

beforeCompletion

public void beforeCompletion()
Specified by:
beforeCompletion in interface javax.transaction.Synchronization
See Also:
Synchronization.beforeCompletion()

afterCompletion

public void afterCompletion(int status)
Specified by:
afterCompletion in interface javax.transaction.Synchronization
See Also:
Synchronization.afterCompletion(int)

setTxMap

void setTxMap(TxDatabaseMap txMap)

getJdbcConnection

public java.sql.Connection getJdbcConnection()
                                      throws PersistenceException
Description copied from interface: Database
Gets the underlying JDBC connection. This is for advanced use only. Please make sure that you never close this Connection instance, as it will be closed by Castor.

Specified by:
getJdbcConnection in interface Database
Specified by:
getJdbcConnection in class AbstractDatabaseImpl
Throws:
PersistenceException
See Also:
Database.getJdbcConnection()


Intalio Inc. (C) 1999-2007. All rights reserved http://www.intalio.com