|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.castor.persist.LockEngine
public final class LockEngine
LockEngine is a gateway for all the ClassMolders of a persistence storage. It mantains dirty checking cache state and lock, and provides a thread safe enviroment for ClassMolder. LockEngine garantees that no two conflicting operations will be let running concurrently for the same object.
For example, it ensures that exactly one transaction may read (load) exclusively on one object; transaction can not deleted an object while the other is reading it, etc...
It also provides caching for a persistence storage. Different LRU
mechanisms
can be specified.
User should not create more than one instance of LockEngine for each persistent storage. So that object can be properly locked and ObjectModifiedException can be avoided.
However, if more than one instance of LockEngine or some other external
application run concurrently, if the Persistence
supports dirty checking,
like a fully complaint JDBC Relational Database, proper
ObjectModifiedException will be thrown to ensure data consistency.
Constructor Summary | |
---|---|
LockEngine(MappingResolver mapResolver,
PersistenceFactory factory,
LogInterceptor logInterceptor)
Construct a new cache engine with the specified mapping table, persistence engine and the log interceptor. |
Method Summary | |
---|---|
OID |
create(TransactionContext tx,
OID oid,
java.lang.Object object)
Creates a new object in the persistence storage. |
void |
delete(TransactionContext tx,
OID oid,
java.lang.Object object)
Called at transaction commit time to delete the object. |
void |
forgetObject(TransactionContext tx,
OID oid)
Called at transaction commit or rollback to forget an object and release its locks. |
ClassMolder |
getClassMolder(java.lang.Class cls)
Get classMolder which represents the given java data object class Dependent class will not be returned to avoid persistenting a dependent class without |
Persistence |
getPersistence(java.lang.Class cls)
|
java.util.HashMap |
getXATransactions()
Returns an association between Xid and transactions contexts. |
OID |
load(TransactionContext tx,
OID oid,
java.lang.Object object,
AccessMode suggestedAccessMode,
int timeout)
Loads an object of the specified type and identity from persistent storage. |
OID |
load(TransactionContext tx,
OID oid,
java.lang.Object object,
AccessMode suggestedAccessMode,
int timeout,
QueryResults results)
|
void |
markCreate(TransactionContext tx,
OID oid,
java.lang.Object object)
Mark an object and its related or dependent object to be created |
void |
markDelete(TransactionContext tx,
OID oid,
java.lang.Object object,
int timeout)
|
OID |
preStore(TransactionContext tx,
OID oid,
java.lang.Object object,
int timeout)
Called at transaction commit to store an object that has been loaded during the transaction. |
void |
releaseLock(TransactionContext tx,
OID oid)
Called at transaction commit or rollback to release all locks held on the object. |
void |
revertObject(TransactionContext tx,
OID oid,
java.lang.Object object)
Reverts an object to the cached copy given the object's OID. |
void |
softLock(TransactionContext tx,
OID oid,
int timeout)
Acquire a write lock on the object in memory. |
void |
store(TransactionContext tx,
OID oid,
java.lang.Object object)
|
boolean |
update(TransactionContext tx,
OID oid,
java.lang.Object object,
AccessMode suggestedAccessMode,
int timeout)
Updates an existing object to this engine. |
void |
updateCache(TransactionContext tx,
OID oid,
java.lang.Object object)
Update the cached object with changes done to its copy. |
void |
writeLock(TransactionContext tx,
OID oid,
int timeout)
Acquire a write lock on the object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
LockEngine(MappingResolver mapResolver, PersistenceFactory factory, LogInterceptor logInterceptor) throws MappingException
mapResolver
- Provides mapping information for objects
supported by this cachefactory
- Factory for creating persistence engines for each
object described in the maplogInterceptor
- Log interceptor to use for cache and all its
persistence engines
MappingException
- Indicate that one of the mappings is
invalidMethod Detail |
---|
public ClassMolder getClassMolder(java.lang.Class cls)
public Persistence getPersistence(java.lang.Class cls)
public OID load(TransactionContext tx, OID oid, java.lang.Object object, AccessMode suggestedAccessMode, int timeout) throws ObjectNotFoundException, LockNotGrantedException, PersistenceException, ClassNotPersistenceCapableException, ObjectDeletedWaitingForLockException
tx
- The transaction contextoid
- The identity of the object to loadobject
- The type of the object to loadaccessMode
- The desired access modetimeout
- The timeout waiting to acquire a lock on the
object (specified in seconds)
ObjectNotFoundException
- The object was not found in
persistent storage
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
PersistenceException
- An error reported by the
persistence engine
ClassNotPersistenceCapableException
- The class is not
persistent capable
ObjectDeletedWaitingForLockException
public OID load(TransactionContext tx, OID oid, java.lang.Object object, AccessMode suggestedAccessMode, int timeout, QueryResults results) throws ObjectNotFoundException, LockNotGrantedException, PersistenceException, ClassNotPersistenceCapableException, ObjectDeletedWaitingForLockException
ObjectNotFoundException
LockNotGrantedException
PersistenceException
ClassNotPersistenceCapableException
ObjectDeletedWaitingForLockException
public void markCreate(TransactionContext tx, OID oid, java.lang.Object object) throws PersistenceException, LockNotGrantedException
tx
- The transaction contextoid
- The identity of the object, or nullobject
- The newly created object
PersistenceException
LockNotGrantedException
public OID create(TransactionContext tx, OID oid, java.lang.Object object) throws DuplicateIdentityException, PersistenceException, ClassNotPersistenceCapableException
tx
- The transaction contextoid
- The identity of the object, or nullobject
- The newly created object
DuplicateIdentityException
- An object with this identity
already exists in persistent storage
PersistenceException
- An error reported by the
persistence engine
ClassNotPersistenceCapableException
- The class is not
persistent capablepublic void delete(TransactionContext tx, OID oid, java.lang.Object object) throws PersistenceException
forgetObject(org.exolab.castor.persist.TransactionContext, org.exolab.castor.persist.OID)
tx
- The transaction contextoid
- The object's identityobject
- The object type
PersistenceException
- An error reported by the
persistence enginepublic void markDelete(TransactionContext tx, OID oid, java.lang.Object object, int timeout) throws PersistenceException, LockNotGrantedException
PersistenceException
LockNotGrantedException
public boolean update(TransactionContext tx, OID oid, java.lang.Object object, AccessMode suggestedAccessMode, int timeout) throws ObjectNotFoundException, LockNotGrantedException, ObjectModifiedException, PersistenceException, ClassNotPersistenceCapableException, ObjectDeletedWaitingForLockException
tx
- The transaction contextoid
- The object's identityobject
- The objectaccessMode
- The desired access modetimeout
- The timeout waiting to acquire a lock on the
object (specified in seconds)
ObjectNotFoundException
- The object was not found in
persistent storage
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
PersistenceException
- An error reported by the
persistence engine
ClassNotPersistenceCapableException
- The class is not
persistent capable
ObjectModifiedException
- Dirty checking mechanism may immediately
report that the object was modified in the database during the long
transaction.
ObjectDeletedWaitingForLockException
public OID preStore(TransactionContext tx, OID oid, java.lang.Object object, int timeout) throws LockNotGrantedException, PersistenceException
tx
- The transaction contextoid
- The object's identityobject
- The object to storetimeout
- The timeout waiting to acquire a lock on the
object (specified in seconds)
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
ObjectDeletedException
- The object has been deleted from
persistent storage
ObjectModifiedException
- The object has been modified in
persistent storage since it was loaded, the memory image is
no longer valid
DuplicateIdentityException
- An object with this identity
already exists in persistent storage
PersistenceException
- An error reported by the
persistence enginepublic void store(TransactionContext tx, OID oid, java.lang.Object object) throws LockNotGrantedException, ObjectDeletedException, ObjectModifiedException, DuplicateIdentityException, PersistenceException
LockNotGrantedException
ObjectDeletedException
ObjectModifiedException
DuplicateIdentityException
PersistenceException
public void writeLock(TransactionContext tx, OID oid, int timeout) throws ObjectDeletedException, LockNotGrantedException, PersistenceException
tx
- The transaction contextoid
- The object's OIDtimeout
- The timeout waiting to acquire a lock on the
object (specified in seconds)
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
ObjectDeletedException
- The object has been deleted from
persistent storage
PersistenceException
- An error reported by the
persistence enginepublic void softLock(TransactionContext tx, OID oid, int timeout) throws LockNotGrantedException
tx
- The transaction contextoid
- The object's OIDtimeout
- The timeout waiting to acquire a lock on the
object (specified in seconds)
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
persistent storagepublic void revertObject(TransactionContext tx, OID oid, java.lang.Object object) throws PersistenceException
tx
- The transaction contextoid
- The object's oidobject
- The object into which to copy
PersistenceException
- An error reported by the
persistence engine obtaining a dependent objectpublic void updateCache(TransactionContext tx, OID oid, java.lang.Object object)
store(org.exolab.castor.persist.TransactionContext, org.exolab.castor.persist.OID, java.lang.Object)
and is assumed to have obtained a write
lock.
tx
- The transaction contextoid
- The object's oidobject
- The object to copy frompublic void releaseLock(TransactionContext tx, OID oid)
tx
- The transaction contextoid
- The object OIDpublic void forgetObject(TransactionContext tx, OID oid)
tx
- The transaction contextoid
- The object OIDpublic java.util.HashMap getXATransactions()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |