Class SynchronizationManager
java.lang.Object
com.sun.jdo.api.persistence.support.SynchronizationManager
- All Implemented Interfaces:
jakarta.transaction.Synchronization
This class allows for multiple instances to be called at transaction
completion, which JDO does not currently provide. JDO only provides
for a single instance to be registered. This service exploits
the JDO capability by registering an instance of SynchronizationManager
with JDO and then calling each instance registered with itself.
- Version:
- 1.0
- Author:
- Craig Russell
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static intThe default capacity of the List of Synchronizations.protected final ListThe list of instances to synchronize. -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates new SynchronizationManager instance with a default capacity of the List of Synchronization instances.SynchronizationManager(int initialCapacity) Creates new SynchronizationManager instance specifying the initial capacity of the list of Synchronization instances.protectedCreates new SynchronizationManager instance and registers it with the persistence manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterCompletion(int status) This method will be called during transaction completion.voidThis method will be called during transaction completion.protected static SynchronizationManagerGet the synchronization manager already registered with this persistence manager.protected voidregisterSynchronization(jakarta.transaction.Synchronization instance) Register an instance with this synchronization manager.static voidregisterSynchronization(jakarta.transaction.Synchronization instance, PersistenceManager pm) Register a new Synchronization with the current transaction.static voidsetDefaultCapacity(int capacity) Specify the default capacity of the list of Synchronizations.
-
Field Details
-
defaultCapacity
protected static int defaultCapacityThe default capacity of the List of Synchronizations. -
synchronizations
The list of instances to synchronize. Duplicate registrations will result in the instance being called multiple times. Since we cannot depend on the caller implementing hashCode and equals, we cannot use a Set implementaion.
-
-
Constructor Details
-
SynchronizationManager
public SynchronizationManager(int initialCapacity) Creates new SynchronizationManager instance specifying the initial capacity of the list of Synchronization instances.- Parameters:
initialCapacity- the initial capacity of the List of Synchronization instances
-
SynchronizationManager
public SynchronizationManager()Creates new SynchronizationManager instance with a default capacity of the List of Synchronization instances. -
SynchronizationManager
Creates new SynchronizationManager instance and registers it with the persistence manager.- Parameters:
pm- the persistence manager managing this transaction
-
-
Method Details
-
registerSynchronization
public static void registerSynchronization(jakarta.transaction.Synchronization instance, PersistenceManager pm) Register a new Synchronization with the current transaction.- Parameters:
instance- the instance to be registeredpm- the persistence manager which manages this transaction
-
setDefaultCapacity
public static void setDefaultCapacity(int capacity) Specify the default capacity of the list of Synchronizations.- Parameters:
capacity- the default capacity of the List of Synchronizations
-
getSynchronizationManager
Get the synchronization manager already registered with this persistence manager. If the synchronization instance is not of the proper class, then replace it with a new instance of the synchronization manager, and register the previous synchronization with the newly created synchronization manager.- Parameters:
pm- the persistence manager- Returns:
- the synchronization manager
-
beforeCompletion
public void beforeCompletion()This method will be called during transaction completion. Resource access is allowed. This method in turn calls each registered instance beforeCompletion method.- Specified by:
beforeCompletionin interfacejakarta.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int status) This method will be called during transaction completion. No resource access is allowed. This method in turn calls each registered instance afterCompletion method. After this method completes, instances must register again in the new transaction, but the synchronization manager remains bound to the persistence manager transaction instance.- Specified by:
afterCompletionin interfacejakarta.transaction.Synchronization- Parameters:
status- the completion status of the transaction
-
registerSynchronization
protected void registerSynchronization(jakarta.transaction.Synchronization instance) Register an instance with this synchronization manager. Note that this is not thread-safe. If multiple threads call this method at the same time, the synchronizations List might become corrupt. The correct way to fix this is to ask the PersistenceManager for the Multithreaded flag and perform a synchronized add if the flag is true. We currently do not have the Multithreaded flag implemented.- Parameters:
instance- the instance to be registered
-