atg.commerce.util
Class TransactionLockFactory

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.util.TransactionLockFactory
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class TransactionLockFactory
extends GenericService

The transaction lock factory is used to grab locks before beginning and ending a transaction. To use:

   TransactionLockFactory tlf = getTransactionLockFactory();
   TransactionLockService lockService = tlf.getServiceInstance(this);
     
   try {
     lockService.acquireTransactionLock();
   }
   catch (DeadlockException de) {
     // log something
   }

   try {
     // perform your work in a transaction
   }
   finally
   {
     try {
       lockService.releaseTransactionLock();
     }
     catch (LockManagerException lme) {
       // log something
     }
   }
 
By default, the key used to retrieve the lock is the current profile id. To change this, pass in your own key to getServiceInstance


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
TransactionLockFactory()
           
 
Method Summary
 ClientLockManager getLocalLockManager()
          Return the lock manager to use if useLocksAroundTransactions is true.
 RepositoryItem getProfile()
          Return the current user profile.
 TransactionLockService getServiceInstance()
          Get a new TransactionLockService with all the default settings..
 TransactionLockService getServiceInstance(ApplicationLogging pLogger)
          Get a new TransactionLockService with all the default settings.
 TransactionLockService getServiceInstance(java.lang.String pLockName)
          Get a new TransactionLockService but instead of using the default transactionLockName, use the given lock name.
 TransactionLockService getServiceInstance(java.lang.String pLockName, ApplicationLogging pLogger)
          Get a new TransactionLockService but instead of using the default transactionLockName, use the given lock name.
protected  java.lang.String getTransactionLockName()
          Generate the lock name to use when acquiring and releasing locks in acquireTransactionLock and releaseTransactionLock.
 boolean isUseLocksAroundTransactions()
          Inquire whether to use a local lock manager to obtain a lock before starting transactions, and to release the lock after committing transactions.
 void setLocalLockManager(ClientLockManager pLocalLockManager)
          Specify the lock manager to use if useLocksAroundTransactions is true.
 void setUseLocksAroundTransactions(boolean pUseLocksAroundTransactions)
          Specify whether to use a local lock manager to obtain a lock before starting transactions and to release the lock after committing transacations.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

TransactionLockFactory

public TransactionLockFactory()
Method Detail

setUseLocksAroundTransactions

public void setUseLocksAroundTransactions(boolean pUseLocksAroundTransactions)
Specify whether to use a local lock manager to obtain a lock before starting transactions and to release the lock after committing transacations.

If this property is set to true, locking will be used to prevent one user from trying to modify orders in multiple concurrent threads. This has a small performance impact as we obtain and release the lock, but minimizes the possibility of concurrent update exceptions if two threads try to modify the same order for the same user. The default value for useLocksAroundTransactions is true.


isUseLocksAroundTransactions

public boolean isUseLocksAroundTransactions()
Inquire whether to use a local lock manager to obtain a lock before starting transactions, and to release the lock after committing transactions.


setLocalLockManager

public void setLocalLockManager(ClientLockManager pLocalLockManager)
Specify the lock manager to use if useLocksAroundTransactions is true.

See Also:
setUseLocksAroundTransactions(boolean)

getLocalLockManager

public ClientLockManager getLocalLockManager()
Return the lock manager to use if useLocksAroundTransactions is true.

See Also:
setUseLocksAroundTransactions(boolean)

getProfile

public RepositoryItem getProfile()
Return the current user profile.

Returns:
a RepositoryItem value

getServiceInstance

public TransactionLockService getServiceInstance()
Get a new TransactionLockService with all the default settings.. This method will never return null

Returns:
A new TransactionLockService

getServiceInstance

public TransactionLockService getServiceInstance(java.lang.String pLockName)
Get a new TransactionLockService but instead of using the default transactionLockName, use the given lock name. This method will never return null

Parameters:
pLockName - The name to use when acquiring and releasing locks.
Returns:
A new TransactionLockService

getServiceInstance

public TransactionLockService getServiceInstance(ApplicationLogging pLogger)
Get a new TransactionLockService with all the default settings. This method will never return null

Parameters:
pLogger - The logger used by the returned TransactionLockService
Returns:
A new TransactionLockService

getServiceInstance

public TransactionLockService getServiceInstance(java.lang.String pLockName,
                                                 ApplicationLogging pLogger)
Get a new TransactionLockService but instead of using the default transactionLockName, use the given lock name. This method will never return null

Parameters:
pLockName - The name to use when acquiring and releasing locks.
pLogger - The logger used by the returned TransactionLockService
Returns:
A new TransactionLockService

getTransactionLockName

protected java.lang.String getTransactionLockName()
Generate the lock name to use when acquiring and releasing locks in acquireTransactionLock and releaseTransactionLock. By default this returns the repository id of the current user profile, generating an error message and returning null if no profile is available. Subclasses may override this behavior to choose a different locking strategy.

Returns:
The lock name to use when acquiring and releasing locks, or null if no lock name is available. In this case locking will be disabled for the current form submission.