|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.castor.jdo.engine.DatabaseImpl
public class DatabaseImpl
An implementation of the JDO database supporting explicit transaction demarcation.
Field Summary | |
---|---|
protected TransactionContext |
_ctx
The transaction context is this database was accessed with an XAResource . |
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 | |
---|---|
DatabaseImpl(java.lang.String dbName,
int lockTimeout,
CallbackInterceptor callback,
InstanceFactory instanceFactory,
javax.transaction.Transaction transaction,
java.lang.ClassLoader classLoader,
boolean autoStore)
|
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. |
void |
create(java.lang.Object object)
Creates a new object in persistent storage. |
void |
expireCache(java.lang.Class[] type,
java.lang.Object[] identity)
Deprecated. Please use the new CacheManager which can be
obtained by calling getCacheManager() . |
protected void |
finalize()
Overrides Object.finalize(). |
CacheManager |
getCacheManager()
Get's the CacheManager instance. |
java.lang.ClassLoader |
getClassLoader()
Gets the current application ClassLoader's instance. |
java.lang.String |
getDatabaseName()
} Return the name of the database |
java.lang.Object |
getIdentity(java.lang.Object object)
Returns the object's identity. |
java.sql.Connection |
getJdbcConnection()
Get the underlying JDBC Connection. |
(package private) LockEngine |
getLockEngine()
|
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()
|
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 |
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. |
java.lang.Object |
load(java.lang.Class type,
java.lang.Object identity,
short accessMode)
Load an object of the specified type and given identity. |
void |
lock(java.lang.Object object)
Acquire a soft write lock on the object. |
void |
remove(java.lang.Object object)
Removes the object from persistent storage. |
void |
rollback()
Rolls back and closes the transaction. |
void |
setAutoStore(boolean autoStore)
True if user prefer all reachable object to be stored automatically. |
(package private) void |
setTxMap(TxDatabaseMap txMap)
|
java.lang.String |
toString()
|
void |
update(java.lang.Object object)
Update a data object which is queried/loaded/created in another transaction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected PersistenceInfoGroup _scope
protected TransactionContext _ctx
XAResource
.
Constructor Detail |
---|
public DatabaseImpl(java.lang.String dbName, int lockTimeout, CallbackInterceptor callback, InstanceFactory instanceFactory, javax.transaction.Transaction transaction, java.lang.ClassLoader classLoader, boolean autoStore) throws DatabaseNotFoundException
DatabaseNotFoundException
Method Detail |
---|
LockEngine getLockEngine()
public PersistenceInfoGroup getScope()
getScope
in interface Database
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 void close() throws PersistenceException
Database
close
in interface Database
PersistenceException
- An error occured while
attempting to close the databasepublic boolean isClosed()
Database
isClosed
in interface Database
public java.lang.Object load(java.lang.Class type, java.lang.Object identity) throws ObjectNotFoundException, LockNotGrantedException, TransactionNotInProgressException, PersistenceException
Database
load
in interface Database
type
- 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 enginepublic java.lang.Object load(java.lang.Class type, java.lang.Object identity, java.lang.Object object) throws TransactionNotInProgressException, ObjectNotFoundException, LockNotGrantedException, PersistenceException
Database
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 into
TransactionNotInProgressException
- Method called while
transaction is not in progress
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
PersistenceException
- An error reported by the
persistence enginepublic java.lang.Object load(java.lang.Class type, java.lang.Object identity, short accessMode) throws ObjectNotFoundException, LockNotGrantedException, TransactionNotInProgressException, PersistenceException
Database
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 identityaccessMode
- 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 enginepublic java.lang.Object load(java.lang.Class type, java.lang.Object identity, AccessMode mode) throws TransactionNotInProgressException, ObjectNotFoundException, LockNotGrantedException, PersistenceException
Database
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 mode
TransactionNotInProgressException
- Method called while
transaction is not in progress
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
PersistenceException
- An error reported by the
persistence enginepublic void create(java.lang.Object object) throws ClassNotPersistenceCapableException, DuplicateIdentityException, TransactionNotInProgressException, PersistenceException
Database
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 create
ClassNotPersistenceCapableException
- The class is not
persistent capable
DuplicateIdentityException
- An object with this identity
already exists in persistent storage
TransactionNotInProgressException
- Method called while
transaction is not in progress
PersistenceException
- An error reported by the
persistence enginepublic CacheManager getCacheManager()
Database
getCacheManager
in interface Database
Database.getCacheManager()
public void update(java.lang.Object object) throws ClassNotPersistenceCapableException, ObjectModifiedException, TransactionNotInProgressException, PersistenceException
Database
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 create
ClassNotPersistenceCapableException
- The class is not
persistent capable
TransactionNotInProgressException
- Method called while
transaction is not in progress
PersistenceException
- An error reported by the
persistence engine
ObjectModifiedException
public void remove(java.lang.Object object) throws ObjectNotPersistentException, LockNotGrantedException, TransactionNotInProgressException, PersistenceException
Database
remove
in interface Database
object
- The object to remove
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
TransactionNotInProgressException
- Method called while
transaction is not in progress
PersistenceException
- An error reported by the
persistence enginepublic boolean isPersistent(java.lang.Object object)
Database
isPersistent
in interface Database
object
- The object
public java.lang.Object getIdentity(java.lang.Object object) throws ClassNotPersistenceCapableException
Database
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.
ClassNotPersistenceCapableException
- The class is not persistent capable.public void lock(java.lang.Object object) throws LockNotGrantedException, ObjectNotPersistentException, TransactionNotInProgressException, PersistenceException
Database
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 lock
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire a lock on the object
ObjectNotPersistentException
- The object has not been
queried or created in this transaction
TransactionNotInProgressException
- Method called while
transaction is not in progress
PersistenceException
- An error reported by the
persistence enginepublic OQLQuery getOQLQuery()
Database
OQLQuery.create(java.lang.String)
must be called before the query can be executed.
getOQLQuery
in interface Database
public OQLQuery getOQLQuery(java.lang.String oql) throws PersistenceException
Database
getOQLQuery
in interface Database
oql
- An OQL query statement
PersistenceException
public Query getQuery()
Database
getQuery
in interface Database
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
Object.finalize()
protected TransactionContext getTransaction() throws TransactionNotInProgressException
TransactionNotInProgressException
public void begin() throws PersistenceException
Database
begin
in interface Database
PersistenceException
- A transaction is already open on
this database, or an error reported by the persistence enginepublic void commit() throws TransactionNotInProgressException, TransactionAbortedException
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.
commit
in interface Database
TransactionNotInProgressException
- Method called while
transaction is not in progress
TransactionAbortedException
- The transaction cannot
commit and has been rolled backpublic void rollback() throws TransactionNotInProgressException
Database
rollback
in interface Database
TransactionNotInProgressException
- Method called while
transaction is not in progresspublic void beforeCompletion()
beforeCompletion
in interface javax.transaction.Synchronization
public void afterCompletion(int status)
afterCompletion
in interface javax.transaction.Synchronization
void setTxMap(TxDatabaseMap txMap)
public boolean isActive()
Database
isActive
in interface Database
public java.lang.String toString()
toString
in class java.lang.Object
public java.sql.Connection getJdbcConnection() throws PersistenceException
getJdbcConnection
in interface Database
PersistenceException
- If the underlying JDBC connection cannot be obtained.public void expireCache(java.lang.Class[] type, java.lang.Object[] identity) throws PersistenceException
CacheManager
which can be
obtained by calling getCacheManager()
.
type
- An array of class types.identity
- An array of object identifiers.
PersistenceException
- Indicates that a problem has occured expiring objects from the cache.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |