Database
GlobalDatabaseImpl
, LocalDatabaseImpl
public abstract class AbstractDatabaseImpl extends java.lang.Object implements Database
Modifier and Type | Field | 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 | 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 | 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 |
getNativeQuery(java.lang.String sql,
java.lang.Class<?> result) |
Creates an OQL query instance based upon a native SQL query and a returning
(resulting) class.
|
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 entity is persistent.
|
<T> T |
load(java.lang.Class<T> type,
java.lang.Object identity) |
Load an object of the specified type and given identity.
|
<T> T |
load(java.lang.Class<T> 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.
|
<T> T |
load(java.lang.Class<T> type,
java.lang.Object identity,
AccessMode mode) |
Load an object of the specified type and given identity.
|
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 use.callback
- Callback interceptors.instanceFactory
- Instance factory.classLoader
- 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()
public void setAutoStore(boolean autoStore)
setAutoStore
in interface Database
autoStore
- True to indicate that 'autoStore' mode should be used.public boolean isAutoStore()
isAutoStore
in interface Database
public java.lang.ClassLoader getClassLoader()
getClassLoader
in interface Database
null
if not providedpublic java.lang.String getDatabaseName()
getDatabaseName
in interface Database
public abstract void close() throws PersistenceException
close
in interface Database
PersistenceException
- An error occured while
attempting to close the databasepublic boolean isClosed()
public boolean isLocked(java.lang.Class cls, java.lang.Object identity) throws PersistenceException
isLocked
in interface Database
cls
- Class instance.identity
- Object identity.PersistenceException
public <T> T load(java.lang.Class<T> type, java.lang.Object identity) throws PersistenceException
load
in interface Database
type
- 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 enginepublic <T> T load(java.lang.Class<T> type, java.lang.Object identity, java.lang.Object object) throws PersistenceException
Load 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 Database
type
- The object's typeidentity
- The object's identityobject
- The object instance to be loaded intoObjectNotFoundException
- 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 enginepublic <T> T load(java.lang.Class<T> type, java.lang.Object identity, AccessMode mode) throws PersistenceException
Load 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 Database
type
- The object's typeidentity
- The object's identitymode
- The access modeObjectNotFoundException
- 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 enginepublic void create(java.lang.Object object) throws PersistenceException
If 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 Database
object
- The object to createTransactionNotInProgressException
- Method called while
transaction is not in progressDuplicateIdentityException
- An object with this identity
already exists in persistent storageClassNotPersistenceCapableException
- The class is not
persistent capablePersistenceException
- An error reported by the
persistence enginepublic CacheManager getCacheManager()
getCacheManager
in interface Database
public void update(java.lang.Object object) throws PersistenceException
For 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 Database
object
- The object to createTransactionNotInProgressException
- Method called while
transaction is not in progressClassNotPersistenceCapableException
- The class is not
persistent capablePersistenceException
- An error reported by the
persistence enginepublic void remove(java.lang.Object object) throws PersistenceException
remove
in interface Database
object
- The object to removeTransactionNotInProgressException
- Method called while
transaction is not in progressObjectNotPersistentException
- The object has not been
queried or created in this transactionLockNotGrantedException
- Timeout or deadlock occured
attempting to acquire a lock on the objectPersistenceException
- An error reported by the
persistence enginepublic boolean isPersistent(java.lang.Object object)
isPersistent
in interface Database
object
- The entity.public Identity getIdentity(java.lang.Object object) throws PersistenceException
Note: 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 Database
object
- The object.PersistenceException
- The class is not persistent capable.public void lock(java.lang.Object object) throws PersistenceException
A 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 Database
object
- The object to lockTransactionNotInProgressException
- Method called while
transaction is not in progressObjectNotPersistentException
- The object has not been
queried or created in this transactionLockNotGrantedException
- Timeout or deadlock occured
attempting to acquire a lock on the objectPersistenceException
- An error reported by the
persistence enginepublic OQLQuery getOQLQuery()
OQLQuery.create(java.lang.String)
must be called before the query can be executed.getOQLQuery
in interface Database
public final OQLQuery getNamedQuery(java.lang.String name) throws PersistenceException
OQLQuery.create(java.lang.String)
getNamedQuery
in interface Database
name
- Name of the (named) query to create.PersistenceException
public final OQLQuery getNativeQuery(java.lang.String sql, java.lang.Class<?> result) throws PersistenceException
getNativeQuery
in interface Database
sql
- Native SQL query to be used.result
- Class that is result of the query.PersistenceException
public OQLQuery getOQLQuery(java.lang.String oql) throws PersistenceException
getOQLQuery
in interface Database
oql
- An OQL query statementPersistenceException
public Query getQuery()
protected TransactionContext getTransaction() throws TransactionNotInProgressException
TransactionNotInProgressException
- If there's no active transaction.public abstract void begin() throws PersistenceException
begin
in interface Database
PersistenceException
- A transaction is already open on
this database, or an error reported by the persistence enginepublic abstract void commit() throws TransactionNotInProgressException, TransactionAbortedException
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.
commit
in interface Database
TransactionNotInProgressException
- Method called while
transaction is not in progressTransactionAbortedException
- The transaction cannot
commit and has been rolled backpublic abstract void rollback() throws TransactionNotInProgressException
rollback
in interface Database
TransactionNotInProgressException
- Method called while
transaction is not in progresspublic boolean isActive()
public java.lang.String toString()
toString
in class java.lang.Object
public abstract java.sql.Connection getJdbcConnection() throws PersistenceException
getJdbcConnection
in interface Database
PersistenceException
- If the underlying JDBC connection cannot be obtained.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-2008. All rights reserved http://www.intalio.com