org.exolab.castor.jdo.engine

Class AbstractDatabaseImpl

Implemented Interfaces:
Database
Known Direct Subclasses:
GlobalDatabaseImpl, LocalDatabaseImpl

public abstract class AbstractDatabaseImpl
extends java.lang.Object
implements Database

An implementation of the JDO database supporting explicit transaction demarcation.
Version:
$Revision: 6230 $ $Date: 2006-04-22 11:05:30 -0600 (Sat, 22 Apr 2006) $
Authors:
Assaf Arkin
Bruce Snyder

Field Summary

protected boolean
_autoStore
True if user prefer all reachable object to be stored automatically.
protected CallbackInterceptor
_callback
The default callback interceptor for transaction
protected ClassLoader
_classLoader
The class loader for application classes (may be null).
protected TransactionContext
_ctx
The transaction context is this database was accessed with an javax.transaction.xa.XAResource.
protected String
_dbName
The name of this database.
protected InstanceFactory
_instanceFactory
The instance factory to that creates new instances of data object
protected int
_lockTimeout
The lock timeout for this database.
protected PersistenceInfoGroup
_scope
The database engine used to access the underlying SQL database.

Fields inherited from interface org.exolab.castor.jdo.Database

DbLocked, Exclusive, ReadOnly, Shared

Constructor Summary

AbstractDatabaseImpl(String dbName, int lockTimeout, CallbackInterceptor callback, InstanceFactory instanceFactory, ClassLoader classLoader, boolean autoStore)
Creates an instance of this class

Method Summary

abstract void
begin()
abstract void
close()
abstract void
commit()
void
create(Object object)
CacheManager
getCacheManager()
ClassLoader
getClassLoader()
Gets the current application ClassLoader's instance.
TransactionContext
getCurrentTransaction()
Gets the current Castor transaction in use.
String
getDatabaseName()
Return the name of the database
Identity
getIdentity(Object object)
abstract Connection
getJdbcConnection()
(package private) LockEngine
getLockEngine()
Returns the LockEngine in use by this database instance.
OQLQuery
getNamedQuery(String name)
OQLQuery
getOQLQuery()
OQLQuery
getOQLQuery(String oql)
Query
getQuery()
PersistenceInfoGroup
getScope()
protected TransactionContext
getTransaction()
Returns the currently active transaction, if any.
boolean
isActive()
boolean
isAutoStore()
Return if the current transaction is set to autoStore, it there is transaction active.
boolean
isClosed()
boolean
isLocked(Class cls, Object identity)
boolean
isPersistent(Object object)
Object
load(Class type, Object identity)
Object
load(Class type, Object identity, Object object)
Object
load(Class type, Object identity, AccessMode mode)
protected void
loadSynchronizables()
Load the TxSynchronizable implementations from the properties file, if not loaded before.
void
lock(Object object)
protected void
registerSynchronizables()
Register the TxSynchronizable implementations at the TransactionContect at end of begin().
void
remove(Object object)
abstract void
rollback()
void
setAutoStore(boolean autoStore)
Indicates whether user prefer all reachable object to be stored automatically; false if user wants dependent object only to be stored.
String
toString()
protected void
unregisterSynchronizables()
Unregister the TxSynchronizable implementations at the TransactionContect after commit() or rollback().
void
update(Object object)

Field Details

_autoStore

protected boolean _autoStore
True if user prefer all reachable object to be stored automatically. False if user want only dependent object to be stored.

_callback

protected CallbackInterceptor _callback
The default callback interceptor for transaction

_classLoader

protected ClassLoader _classLoader
The class loader for application classes (may be null).

_ctx

protected TransactionContext _ctx
The transaction context is this database was accessed with an javax.transaction.xa.XAResource.

_dbName

protected String _dbName
The name of this database.

_instanceFactory

protected InstanceFactory _instanceFactory
The instance factory to that creates new instances of data object

_lockTimeout

protected int _lockTimeout
The lock timeout for this database. Zero for immediate timeout, an infinite value for no timeout. The timeout is specified in seconds.

_scope

protected PersistenceInfoGroup _scope
The database engine used to access the underlying SQL database.

Constructor Details

AbstractDatabaseImpl

public AbstractDatabaseImpl(String dbName,
                            int lockTimeout,
                            CallbackInterceptor callback,
                            InstanceFactory instanceFactory,
                            ClassLoader classLoader,
                            boolean autoStore)
            throws DatabaseNotFoundException
Creates an instance of this class
Parameters:
dbName - Name of the database.
lockTimeout - Lock timeout to use
callback - Callback interceptors
instanceFactory - Instance factory
classLoader - Current class loader.
autoStore - True if auto storing is enabled.
Throws:
DatabaseNotFoundException - If there's no database configuration for the given name.

Method Details

begin

public abstract void begin()
            throws PersistenceException
Specified by:
begin in interface Database

close

public abstract void close()
            throws PersistenceException
Specified by:
close in interface Database

commit

public abstract void commit()
            throws TransactionNotInProgressException,
                   TransactionAbortedException
Specified by:
commit in interface Database

create

public void create(Object object)
            throws ClassNotPersistenceCapableException,
                   DuplicateIdentityException,
                   TransactionNotInProgressException,
                   PersistenceException
Specified by:
create in interface Database
See Also:
org.exolab.castor.jdo.Database.create(java.lang.Object)

getCacheManager

public CacheManager getCacheManager()
Specified by:
getCacheManager in interface Database

getClassLoader

public ClassLoader getClassLoader()
Gets the current application ClassLoader's instance.
Specified by:
getClassLoader in interface Database
Returns:
the current ClassLoader's instance, or null if not provided

getCurrentTransaction

public TransactionContext getCurrentTransaction()
            throws TransactionNotInProgressException
Gets the current Castor transaction in use.
Returns:
the current Castor
Throws:
TransactionNotInProgressException - If there's no transaction in progress.

getDatabaseName

public String getDatabaseName()
Return the name of the database
Specified by:
getDatabaseName in interface Database
Returns:
Name of the database.

getIdentity

public Identity getIdentity(Object object)
            throws PersistenceException
Specified by:
getIdentity in interface Database
See Also:
org.exolab.castor.jdo.Database.getIdentity(java.lang.Object)

getJdbcConnection

public abstract Connection getJdbcConnection()
            throws PersistenceException
Specified by:
getJdbcConnection in interface Database

getLockEngine

(package private)  LockEngine getLockEngine()
Returns the LockEngine in use by this database instance.
Returns:
the LockEngine in use by this database instance.

getNamedQuery

public OQLQuery getNamedQuery(String name)
            throws PersistenceException
Specified by:
getNamedQuery in interface Database
See Also:
org.exolab.castor.jdo.Database.getNamedQuery(java.lang.String)

getOQLQuery

public OQLQuery getOQLQuery()
Specified by:
getOQLQuery in interface Database

getOQLQuery

public OQLQuery getOQLQuery(String oql)
            throws PersistenceException
Specified by:
getOQLQuery in interface Database
See Also:
org.exolab.castor.jdo.Database.getOQLQuery(java.lang.String)

getQuery

public Query getQuery()
Specified by:
getQuery in interface Database

getScope

public PersistenceInfoGroup getScope()
Specified by:
getScope in interface Database

getTransaction

protected TransactionContext getTransaction()
            throws TransactionNotInProgressException
Returns the currently active transaction, if any.
Returns:
The current active transaction.
Throws:
TransactionNotInProgressException - If there's no active transaction.

isActive

public boolean isActive()
Specified by:
isActive in interface Database

isAutoStore

public boolean isAutoStore()
Return if the current transaction is set to autoStore, it there is transaction active. If there is no active transaction, return if the next transaction will be set to autoStore.
Specified by:
isAutoStore in interface Database
Returns:
True if 'auto-store' mode is in use.

isClosed

public boolean isClosed()
Specified by:
isClosed in interface Database

isLocked

public boolean isLocked(Class cls,
                        Object identity)
            throws PersistenceException
Specified by:
isLocked in interface Database
See Also:
org.exolab.castor.jdo.Database.isLocked(java.lang.Class, java.lang.Object)

isPersistent

public boolean isPersistent(Object object)
Specified by:
isPersistent in interface Database
See Also:
org.exolab.castor.jdo.Database.isPersistent(java.lang.Object)

load

public Object load(Class type,
                   Object identity)
            throws ObjectNotFoundException,
                   LockNotGrantedException,
                   TransactionNotInProgressException,
                   PersistenceException
Specified by:
load in interface Database
See Also:
{@inheritDoc}

load

public Object load(Class type,
                   Object identity,
                   Object object)
            throws TransactionNotInProgressException,
                   ObjectNotFoundException,
                   LockNotGrantedException,
                   PersistenceException
Specified by:
load in interface Database
See Also:
{@inheritDoc}

load

public Object load(Class type,
                   Object identity,
                   AccessMode mode)
            throws TransactionNotInProgressException,
                   ObjectNotFoundException,
                   LockNotGrantedException,
                   PersistenceException
Specified by:
load in interface Database
See Also:
{@inheritDoc}

loadSynchronizables

protected void loadSynchronizables()
Load the TxSynchronizable implementations from the properties file, if not loaded before.

lock

public void lock(Object object)
            throws LockNotGrantedException,
                   ObjectNotPersistentException,
                   TransactionNotInProgressException,
                   PersistenceException
Specified by:
lock in interface Database
See Also:
org.exolab.castor.jdo.Database.lock(java.lang.Object)

registerSynchronizables

protected void registerSynchronizables()
Register the TxSynchronizable implementations at the TransactionContect at end of begin().

remove

public void remove(Object object)
            throws ObjectNotPersistentException,
                   LockNotGrantedException,
                   TransactionNotInProgressException,
                   PersistenceException
Specified by:
remove in interface Database
See Also:
org.exolab.castor.jdo.Database.remove(java.lang.Object)

rollback

public abstract void rollback()
            throws TransactionNotInProgressException
Specified by:
rollback in interface Database

setAutoStore

public void setAutoStore(boolean autoStore)
Indicates whether user prefer all reachable object to be stored automatically; false if user wants dependent object only to be stored.
Specified by:
setAutoStore in interface Database
Parameters:
autoStore - True to indicate that 'autoStore' mode should be used.

toString

public String toString()
See Also:
java.lang.Object.toString()

unregisterSynchronizables

protected void unregisterSynchronizables()
Unregister the TxSynchronizable implementations at the TransactionContect after commit() or rollback().

update

public void update(Object object)
            throws ClassNotPersistenceCapableException,
                   ObjectModifiedException,
                   TransactionNotInProgressException,
                   PersistenceException
Specified by:
update in interface Database
See Also:
org.exolab.castor.jdo.Database.update(java.lang.Object)

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