|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.exolab.castor.jdo.engine.AbstractDatabaseImpl
public abstract class AbstractDatabaseImpl
An implementation of the JDO database supporting explicit transaction demarcation.
| 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 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, DBLOCKED, Exclusive, EXCLUSIVE, ReadOnly, READONLY, Shared, 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()
Begin a new transaction. |
|
abstract void |
close()
Closes the database. |
|
abstract void |
commit()
Commits and closes the transaction. |
|
void |
create(Object object)
Creates a new object in persistent storage. |
|
CacheManager |
getCacheManager()
Get's the CacheManager instance. |
|
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)
Returns the object's identity. |
|
abstract Connection |
getJdbcConnection()
Gets the underlying JDBC connection. |
|
OQLQuery |
getNamedQuery(String name)
Creates an OQL query based upon a named query as defined in the mapping file. |
|
OQLQuery |
getNativeQuery(String sql,
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(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(Class cls,
Object identity)
Returns true if the specified object is currently locked. |
|
boolean |
isPersistent(Object object)
Returns true if the entity is persistent. |
|
|
load(Class<T> type,
Object identity)
Load an object of the specified type and given identity. |
|
|
load(Class<T> type,
Object identity,
AccessMode mode)
Load an object of the specified type and given identity. |
|
|
load(Class<T> type,
Object identity,
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(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(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. |
|
String |
toString()
|
|
protected void |
unregisterSynchronizables()
Unregister the TxSynchronizable implementations at the
TransactionContect after commit() or rollback(). |
|
void |
update(Object object)
Update a data object which is queried/loaded/created in another transaction. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected PersistenceInfoGroup _scope
protected TransactionContext _ctx
XAResource.
protected int _lockTimeout
protected CallbackInterceptor _callback
protected InstanceFactory _instanceFactory
protected String _dbName
protected boolean _autoStore
protected ClassLoader _classLoader
| Constructor Detail |
|---|
public AbstractDatabaseImpl(String dbName,
int lockTimeout,
CallbackInterceptor callback,
InstanceFactory instanceFactory,
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.| Method Detail |
|---|
public PersistenceInfoGroup getScope()
getScope in interface Databasepublic void setAutoStore(boolean autoStore)
setAutoStore in interface DatabaseautoStore - True to indicate that 'autoStore' mode should be used.public boolean isAutoStore()
isAutoStore in interface Databasepublic ClassLoader getClassLoader()
getClassLoader in interface Databasenull if not providedpublic String getDatabaseName()
getDatabaseName in interface Database
public abstract void close()
throws PersistenceException
close in interface DatabasePersistenceException - An error occured while
attempting to close the databasepublic boolean isClosed()
isClosed in interface Database
public boolean isLocked(Class cls,
Object identity)
throws PersistenceException
isLocked in interface Databasecls - Class instance.identity - Object identity.
PersistenceException
public <T> T load(Class<T> type,
Object identity)
throws PersistenceException
load in interface Databasetype - The object's typeidentity - The object's identity
ObjectNotFoundException - No object of the given type and
identity was found in persistent storage
LockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the object
TransactionNotInProgressException - Method called while
transaction is not in progress
PersistenceException - An error reported by the
persistence engine
public <T> T load(Class<T> type,
Object identity,
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 Databasetype - The object's typeidentity - The object's identityobject - The object instance to be loaded into
ObjectNotFoundException - No object of the given type and
identity was found in persistent storage
LockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the object
TransactionNotInProgressException - Method called while
transaction is not in progress
PersistenceException - An error reported by the
persistence engine
public <T> T load(Class<T> type,
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 Databasetype - The object's typeidentity - The object's identitymode - The access mode
ObjectNotFoundException - No object of the given type and
identity was found in persistent storage
LockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the object
TransactionNotInProgressException - Method called while
transaction is not in progress
PersistenceException - An error reported by the
persistence engine
public void create(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 Databaseobject - The object to create
TransactionNotInProgressException - Method called while
transaction is not in progress
DuplicateIdentityException - An object with this identity
already exists in persistent storage
ClassNotPersistenceCapableException - The class is not
persistent capable
PersistenceException - An error reported by the
persistence enginepublic CacheManager getCacheManager()
getCacheManager in interface Database
public void update(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 Databaseobject - The object to create
TransactionNotInProgressException - Method called while
transaction is not in progress
ClassNotPersistenceCapableException - The class is not
persistent capable
PersistenceException - An error reported by the
persistence engine
public void remove(Object object)
throws PersistenceException
remove in interface Databaseobject - The object to remove
TransactionNotInProgressException - Method called while
transaction is not in progress
ObjectNotPersistentException - The object has not been
queried or created in this transaction
LockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the object
PersistenceException - An error reported by the
persistence enginepublic boolean isPersistent(Object object)
isPersistent in interface Databaseobject - The entity.
public Identity getIdentity(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 Databaseobject - The object.
PersistenceException - The class is not persistent capable.
public void lock(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 Databaseobject - The object to lock
TransactionNotInProgressException - Method called while
transaction is not in progress
ObjectNotPersistentException - The object has not been
queried or created in this transaction
LockNotGrantedException - Timeout or deadlock occured
attempting to acquire a lock on the object
PersistenceException - 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(String name)
throws PersistenceException
OQLQuery.create(java.lang.String)
getNamedQuery in interface Databasename - Name of the (named) query to create.
PersistenceException
public final OQLQuery getNativeQuery(String sql,
Class<?> result)
throws PersistenceException
getNativeQuery in interface Databasesql - Native SQL query to be used.result - Class that is result of the query.
PersistenceException
public OQLQuery getOQLQuery(String oql)
throws PersistenceException
getOQLQuery in interface Databaseoql - An OQL query statement
PersistenceExceptionpublic Query getQuery()
getQuery in interface Database
protected TransactionContext getTransaction()
throws TransactionNotInProgressException
TransactionNotInProgressException - If there's no active transaction.
public abstract void begin()
throws PersistenceException
begin in interface DatabasePersistenceException - A transaction is already open on
this database, or an error reported by the persistence engine
public 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 DatabaseTransactionNotInProgressException - Method called while
transaction is not in progress
TransactionAbortedException - The transaction cannot
commit and has been rolled back
public abstract void rollback()
throws TransactionNotInProgressException
rollback in interface DatabaseTransactionNotInProgressException - Method called while
transaction is not in progresspublic boolean isActive()
isActive in interface Databasepublic String toString()
toString in class Object
public abstract Connection getJdbcConnection()
throws PersistenceException
getJdbcConnection in interface DatabasePersistenceException - 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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||