abstract class AssociationSyncher
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected static interface |
AssociationSyncher.Helper
An interface which abstracts a helper API for managing a foreign DMO.
|
protected class |
AssociationSyncher.OneToManyHelper
An implementation of the
Helper interface which assumes
a one-to-many association from a foreign DMO to zero or more local
DMOs. |
protected class |
AssociationSyncher.OneToOneHelper
An implementation of the
Helper interface which assumes
that there is no more than one record on either end of the association. |
Modifier and Type | Field and Description |
---|---|
protected RecordBuffer |
buffer
Record buffer being monitored for property changes
|
protected java.lang.reflect.Method |
foreignSetter
Method used to set foreign DMO into local DMO
|
protected AssociationSyncher.Helper |
helper
Object which abstracts methods to assist in managing the foreign DMO
|
protected java.lang.String |
lockTable
Name of table for which temporary record locks must be acquired
|
private static java.util.logging.Logger |
LOG
Logger
|
private java.util.Set<TempLock> |
tempLocks
Set of temporary locks which are acquired to make updates
|
Constructor and Description |
---|
AssociationSyncher(RecordBuffer buffer,
RelationInfo info,
java.lang.Class<?> lockClass)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
acquireLock(java.io.Serializable id,
LockType lockType)
Acquire a temporary lock of the specified type for the given primary key
ID.
|
void |
attemptSynch(java.util.Set dirtyProperties)
Perform record synchronization.
|
private void |
doSynch()
Perform foreign association synchronization.
|
protected abstract java.util.Set |
getLegacyKeys()
Retrieve the set of property names which represent the columns which
comprise the legacy key joining two records.
|
protected abstract void |
preSynch(java.util.Set newLocalDMOs,
Persistable newForeignDMO)
Subclasses which need to remove any existing association linkages
before the new association is applied must implement this method.
|
protected abstract Persistable |
retrieveForeignDMO()
Retrieve the DMO, if any, at the foreign end of the association.
|
protected abstract java.util.Set |
retrieveLocalDMOs()
Retrieve the set of DMOs which comprise the local end of the foreign
association.
|
private static final java.util.logging.Logger LOG
protected final AssociationSyncher.Helper helper
protected final java.lang.reflect.Method foreignSetter
protected final java.lang.String lockTable
protected final RecordBuffer buffer
private final java.util.Set<TempLock> tempLocks
AssociationSyncher(RecordBuffer buffer, RelationInfo info, java.lang.Class<?> lockClass)
buffer
- Record buffer containing the DMO whose property change(s)
will trigger synchronization attempts.info
- Foreign relation descriptor object.lockClass
- DMO class for which temporary record locks must be acquired.public final void attemptSynch(java.util.Set dirtyProperties) throws PersistenceException
dirtyProperties
- The set of properties which have been modified, thereby
triggering the synchronization request.PersistenceException
- if any error occurs resolving the foreign record.protected abstract java.util.Set getLegacyKeys()
protected abstract void preSynch(java.util.Set newLocalDMOs, Persistable newForeignDMO) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
newLocalDMOs
- Set of zero or more local DMOs which are about to be updated
with the new association.newForeignDMO
- Foreign DMO which is about to be updated with the new
association.java.lang.IllegalAccessException
- if an access error occurs while invoking a method using
reflection.java.lang.reflect.InvocationTargetException
- if a method invoked using reflection throws an exception.protected abstract java.util.Set retrieveLocalDMOs() throws PersistenceException
The implementing class should obtain an exclusive lock on each record
returned, using the acquireLock(java.io.Serializable, com.goldencode.p2j.persist.lock.LockType)
method to ensure it is
properly released or downgraded upon completion of synchronization.
This is not necessary for records already exclusively locked.
If the association is one-to-one, the set will contain zero or one records.
If the association is one-to-many, the set may contain zero or more records.
null
.PersistenceException
- if there are any errors retrieving DMOs from the database.protected abstract Persistable retrieveForeignDMO() throws PersistenceException
The implementing class should obtain an exclusive lock on the record
returned, using the acquireLock(java.io.Serializable, com.goldencode.p2j.persist.lock.LockType)
method to ensure it is
properly released or downgraded upon completion of synchronization.
This is not necessary if the record is already exclusively locked.
null
if none was available.PersistenceException
- if there are any errors retrieving the DMO from the database.protected final void acquireLock(java.io.Serializable id, LockType lockType) throws LockUnavailableException
id
- ID of the record to lock.lockType
- Lock type to acquire for the record.LockUnavailableException
- if a NO-WAIT lock type variant is requested, but the lock
cannot be acquired immediately.private void doSynch() throws PersistenceException
PersistenceException
- if any error occurs resolving records.