public abstract class AbstractDatabaseImpl extends java.lang.Object implements Database
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
_autoStore
True if user prefer all reachable object to be stored automatically.
|
protected CallbackInterceptor |
_callback
The default callback interceptor for transaction
|
protected java.lang.ClassLoader |
_classLoader
The class loader for application classes (may be null).
|
protected TransactionContext |
_ctx
The transaction context is this database was accessed with an
XAResource. |
protected java.lang.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.
|
| Constructor and Description |
|---|
AbstractDatabaseImpl(java.lang.String dbName,
int lockTimeout,
CallbackInterceptor callback,
InstanceFactory instanceFactory,
java.lang.ClassLoader classLoader,
boolean autoStore)
Creates an instance of this class
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
begin()
Begin a new transaction.
|
abstract void |
close()
Closes the database.
|
abstract void |
commit()
Commits and closes the transaction.
|
void |
create(java.lang.Object object)
Creates a new object in persistent storage.
|
CacheManager |
getCacheManager()
Get's the CacheManager instance.
|
java.lang.ClassLoader |
getClassLoader()
Gets the current application ClassLoader's instance.
|
TransactionContext |
getCurrentTransaction()
Gets the current Castor transaction in use.
|
java.lang.String |
getDatabaseName()
Return the name of the database
|
Identity |
getIdentity(java.lang.Object object)
Returns the object's identity.
|
abstract java.sql.Connection |
getJdbcConnection()
Gets the underlying JDBC connection.
|
(package private) LockEngine |
getLockEngine()
Returns the
LockEngine in use by this database instance. |
OQLQuery |
getNamedQuery(java.lang.String name)
Creates an OQL query based upon a named query as defined in the
mapping file.
|
OQLQuery |
getOQLQuery()
Creates an OQL query with no statement.
|
OQLQuery |
getOQLQuery(java.lang.String oql)
Creates an OQL query from the supplied statement.
|
Query |
getQuery()
Creates an empty query.
|
PersistenceInfoGroup |
getScope() |
protected TransactionContext |
getTransaction()
Returns the currently active transaction, if any.
|
boolean |
isActive()
Returns true if a transaction is currently active.
|
boolean |
isAutoStore()
Return if the current transaction is set to autoStore, it there is
transaction active.
|
boolean |
isClosed()
Returns true if the database is closed.
|
boolean |
isLocked(java.lang.Class cls,
java.lang.Object identity)
Returns true if the specified object is currently locked.
|
boolean |
isPersistent(java.lang.Object object)
Returns true if the object is persistent.
|
java.lang.Object |
load(java.lang.Class type,
java.lang.Object identity)
Load an object of the specified type and given identity.
|
java.lang.Object |
load(java.lang.Class type,
java.lang.Object identity,
AccessMode mode)
Load an object of the specified type and given identity.
|
java.lang.Object |
load(java.lang.Class type,
java.lang.Object identity,
java.lang.Object object)
Load an object of the specified type and given identity into
a given instance of object.
|
protected void |
loadSynchronizables()
Load the
TxSynchronizable implementations from the
properties file, if not loaded before. |
void |
lock(java.lang.Object object)
Acquire a soft write lock on the object.
|
protected void |
registerSynchronizables()
Register the
TxSynchronizable implementations at the
TransactionContect at end of begin(). |
void |
remove(java.lang.Object object)
Removes the object from persistent storage.
|
abstract void |
rollback()
Rolls back and closes the transaction.
|
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.
|
java.lang.String |
toString() |
protected void |
unregisterSynchronizables()
Unregister the
TxSynchronizable implementations at the
TransactionContect after commit() or rollback(). |
void |
update(java.lang.Object object)
Update a data object which is queried/loaded/created in another
transaction.
|
protected PersistenceInfoGroup _scope
protected TransactionContext _ctx
XAResource.protected int _lockTimeout
protected CallbackInterceptor _callback
protected InstanceFactory _instanceFactory
protected java.lang.String _dbName
protected boolean _autoStore
protected java.lang.ClassLoader _classLoader
public AbstractDatabaseImpl(java.lang.String dbName,
int lockTimeout,
CallbackInterceptor callback,
InstanceFactory instanceFactory,
java.lang.ClassLoader classLoader,
boolean autoStore)
throws DatabaseNotFoundException
dbName - Name of the database.lockTimeout - Lock timeout to usecallback - Callback interceptorsinstanceFactory - Instance factoryclassLoader - Current class loader.autoStore - True if auto storing is enabled.DatabaseNotFoundException - If there's no database configuration for the given name.LockEngine getLockEngine()
LockEngine in use by this database instance.LockEngine in use by this database instance.public PersistenceInfoGroup getScope()
getScope in interface DatabaseDatabase.getScope()public void setAutoStore(boolean autoStore)
setAutoStore in interface DatabaseautoStore - True to indicate that 'autoStore' mode should be used.public boolean isAutoStore()
isAutoStore in interface Databasepublic java.lang.ClassLoader getClassLoader()
getClassLoader in interface Databasenull if not providedpublic java.lang.String getDatabaseName()
getDatabaseName in interface Databasepublic abstract void close()
throws PersistenceException
Databaseclose in interface DatabasePersistenceException - An error occured while
attempting to close the databaseDatabase.close()public boolean isClosed()
DatabaseisClosed in interface DatabaseDatabase.isClosed()public boolean isLocked(java.lang.Class cls,
java.lang.Object identity)
throws PersistenceException
DatabaseisLocked in interface Databasecls - Class instance.identity - Object identity.PersistenceExceptionDatabase.isLocked(java.lang.Class, java.lang.Object)public java.lang.Object load(java.lang.Class type,
java.lang.Object identity)
throws ObjectNotFoundException,
LockNotGrantedException,
TransactionNotInProgressException,
PersistenceException
Databaseload in interface Databasetype - The object's typeidentity - The object's identityObjectNotFoundException - No object of the given type and
identity was found in persistent storageLockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the objectTransactionNotInProgressException - Method called while
transaction is not in progressPersistenceException - An error reported by the
persistence engine{@inheritDoc}public java.lang.Object load(java.lang.Class type,
java.lang.Object identity,
java.lang.Object object)
throws TransactionNotInProgressException,
ObjectNotFoundException,
LockNotGrantedException,
PersistenceException
DatabaseLoad an object of the specified type and given identity into a given instance of object. Once loaded the object is persistent. Calling this method with the same identity in the same transaction will return the same object. This method is equivalent to a query that returns a single object. If the identity spans on more than one field, all of the identity fields can be wrapped in a Complex object.
load in interface Databasetype - The object's typeidentity - The object's identityobject - The object instance to be loaded intoTransactionNotInProgressException - Method called while
transaction is not in progressObjectNotFoundException - No object of the given type and
identity was found in persistent storageLockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the objectPersistenceException - An error reported by the
persistence engine{@inheritDoc}public java.lang.Object load(java.lang.Class type,
java.lang.Object identity,
AccessMode mode)
throws TransactionNotInProgressException,
ObjectNotFoundException,
LockNotGrantedException,
PersistenceException
DatabaseLoad an object of the specified type and given identity. Once loaded the object is persistent. Calling this method with the same identity in the same transaction will return the same object. This method is equivalent to a query that returns a single object.
load in interface Databasetype - The object's typeidentity - The object's identitymode - The access modeTransactionNotInProgressException - Method called while
transaction is not in progressObjectNotFoundException - No object of the given type and
identity was found in persistent storageLockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the objectPersistenceException - An error reported by the
persistence engine{@inheritDoc}public void create(java.lang.Object object)
throws ClassNotPersistenceCapableException,
DuplicateIdentityException,
TransactionNotInProgressException,
PersistenceException
DatabaseIf the object has an identity then duplicate identity check happens in this method, and the object is visible to queries in this transaction. If the identity is null, duplicate identity check occurs when the transaction completes and the object is not visible to queries until the transaction commits.
create in interface Databaseobject - The object to createClassNotPersistenceCapableException - The class is not
persistent capableDuplicateIdentityException - An object with this identity
already exists in persistent storageTransactionNotInProgressException - Method called while
transaction is not in progressPersistenceException - An error reported by the
persistence engineDatabase.create(java.lang.Object)public CacheManager getCacheManager()
DatabasegetCacheManager in interface DatabaseDatabase.getCacheManager()public void update(java.lang.Object object)
throws ClassNotPersistenceCapableException,
ObjectModifiedException,
TransactionNotInProgressException,
PersistenceException
DatabaseFor example, the data object may be sent to a client application and dispayed to a user. After that the objects is being modified in the client application, the object returns back and is update to the database in the second transaction.
See Long Transaction on Castor website.
update in interface Databaseobject - The object to createClassNotPersistenceCapableException - The class is not
persistent capableTransactionNotInProgressException - Method called while
transaction is not in progressPersistenceException - An error reported by the
persistence engineObjectModifiedExceptionDatabase.update(java.lang.Object)public void remove(java.lang.Object object)
throws ObjectNotPersistentException,
LockNotGrantedException,
TransactionNotInProgressException,
PersistenceException
Databaseremove in interface Databaseobject - The object to removeObjectNotPersistentException - The object has not been
queried or created in this transactionLockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the objectTransactionNotInProgressException - Method called while
transaction is not in progressPersistenceException - An error reported by the
persistence engineDatabase.remove(java.lang.Object)public boolean isPersistent(java.lang.Object object)
DatabaseisPersistent in interface Databaseobject - The objectDatabase.isPersistent(java.lang.Object)public Identity getIdentity(java.lang.Object object) throws PersistenceException
DatabaseNote: Prior to 0.9.9.1 release of castor the identity could only be determined if the object took part in the transaction. If this was not the case, the previous implementation also returned null.
getIdentity in interface Databaseobject - The object.PersistenceException - The class is not persistent capable.Database.getIdentity(java.lang.Object)public void lock(java.lang.Object object)
throws LockNotGrantedException,
ObjectNotPersistentException,
TransactionNotInProgressException,
PersistenceException
DatabaseA soft lock is acquired in memory, not in the database. To acquire a lock in the database, use the locked access mode.
If the object already has a write lock in this transaction or a read lock in this transaction but no read lock in any other transaction, a write lock is obtained. If this object has a read lock in any other transaction this method will block until the other transaction will release its lock. If the timeout has elapsed or a deadlock has been detected, an exception will be thrown but the current lock will be retained.
lock in interface Databaseobject - The object to lockLockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the objectObjectNotPersistentException - The object has not been
queried or created in this transactionTransactionNotInProgressException - Method called while
transaction is not in progressPersistenceException - An error reported by the
persistence engineDatabase.lock(java.lang.Object)public OQLQuery getOQLQuery()
DatabaseOQLQuery.create(java.lang.String)
must be called before the query can be executed.getOQLQuery in interface DatabaseDatabase.getOQLQuery()public OQLQuery getNamedQuery(java.lang.String name) throws PersistenceException
DatabaseOQLQuery.create(java.lang.String)getNamedQuery in interface Databasename - Name of the (named) query to create.PersistenceExceptionDatabase.getNamedQuery(java.lang.String)public OQLQuery getOQLQuery(java.lang.String oql) throws PersistenceException
DatabasegetOQLQuery in interface Databaseoql - An OQL query statementPersistenceExceptionDatabase.getOQLQuery(java.lang.String)public Query getQuery()
DatabasegetQuery in interface DatabaseDatabase.getQuery()protected TransactionContext getTransaction() throws TransactionNotInProgressException
TransactionNotInProgressException - If there's no active transaction.public abstract void begin()
throws PersistenceException
Databasebegin in interface DatabasePersistenceException - A transaction is already open on
this database, or an error reported by the persistence engineDatabase.begin()public abstract void commit()
throws TransactionNotInProgressException,
TransactionAbortedException
DatabaseIn 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.
commit in interface DatabaseTransactionNotInProgressException - Method called while
transaction is not in progressTransactionAbortedException - The transaction cannot
commit and has been rolled backDatabase.commit()public abstract void rollback()
throws TransactionNotInProgressException
Databaserollback in interface DatabaseTransactionNotInProgressException - Method called while
transaction is not in progressDatabase.rollback()public boolean isActive()
DatabaseisActive in interface DatabaseDatabase.isActive()public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()public abstract java.sql.Connection getJdbcConnection()
throws PersistenceException
DatabasegetJdbcConnection in interface DatabasePersistenceException - If the underlying JDBC connection cannot be obtained.Database.getJdbcConnection()protected void loadSynchronizables()
TxSynchronizable implementations from the
properties file, if not loaded before.protected void registerSynchronizables()
TxSynchronizable implementations at the
TransactionContect at end of begin().protected void unregisterSynchronizables()
TxSynchronizable implementations at the
TransactionContect after commit() or rollback().public TransactionContext getCurrentTransaction() throws TransactionNotInProgressException
TransactionNotInProgressException - If there's no transaction in progress.Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com