Class SynchronizationManager
- java.lang.Object
-
- com.sun.jdo.api.persistence.support.SynchronizationManager
-
- All Implemented Interfaces:
jakarta.transaction.Synchronization
public class SynchronizationManager extends Object implements 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
Fields Modifier and Type Field Description protected static int
defaultCapacity
The default capacity of the List of Synchronizations.protected List
synchronizations
The list of instances to synchronize.
-
Constructor Summary
Constructors Modifier Constructor Description SynchronizationManager()
Creates 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.protected
SynchronizationManager(PersistenceManager pm)
Creates new SynchronizationManager instance and registers it with the persistence manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterCompletion(int status)
This method will be called during transaction completion.void
beforeCompletion()
This method will be called during transaction completion.protected static SynchronizationManager
getSynchronizationManager(PersistenceManager pm)
Get the synchronization manager already registered with this persistence manager.protected void
registerSynchronization(jakarta.transaction.Synchronization instance)
Register an instance with this synchronization manager.static void
registerSynchronization(jakarta.transaction.Synchronization instance, PersistenceManager pm)
Register a new Synchronization with the current transaction.static void
setDefaultCapacity(int capacity)
Specify the default capacity of the list of Synchronizations.
-
-
-
Field Detail
-
defaultCapacity
protected static int defaultCapacity
The default capacity of the List of Synchronizations.
-
synchronizations
protected final List 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 Detail
-
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
protected SynchronizationManager(PersistenceManager pm)
Creates new SynchronizationManager instance and registers it with the persistence manager.- Parameters:
pm
- the persistence manager managing this transaction
-
-
Method Detail
-
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
protected static SynchronizationManager getSynchronizationManager(PersistenceManager pm)
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:
beforeCompletion
in 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:
afterCompletion
in 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
-
-