atg.droplet
Class TransactionalFormHandler

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.droplet.EmptyFormHandler
              extended by atg.droplet.GenericFormHandler
                  extended by atg.droplet.TransactionalFormHandler
All Implemented Interfaces:
DropletFormHandler, NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener
Direct Known Subclasses:
CreateOrganizationFormHandler, GiftlistFormHandler, PortalGenericFormHandler, WorkflowTaskFormHandler

public class TransactionalFormHandler
extends GenericFormHandler

This form handler adds transaction management capabilities while processing form input. Typically when one is modifying RepositoryItems one should have a transaction in place to enclose all the modifications. The SQL Repository will automatically start and end a transaction for each setPropertyValue call unless a transaction is already in place. This can lead to significant performance problems and inconsistent data, from the application's perspective, because one set could succeed and another might fail. If the ensureTransaction property is true, then transactions are created, if necessary, in the beforeSet operation and committed or rolledback in the afterSet method. Instances of this form handler should be request scoped, or if session scoped, the component should be synchronized.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.droplet.GenericFormHandler
PARAM_DEFER_FORWARD_OR_REDIRECT, PARAM_USE_FORWARDS
 
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
TransactionalFormHandler()
          Constructs an instanceof TransactionalFormHandler
 
Method Summary
 boolean afterSet(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          If the TransactionDemarcation is not null, then the transaction is ended.
 boolean beforeSet(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Creates a new TransactionDemarcation and then begins the transaction.
 boolean checkFormRedirect(java.lang.String pSuccessURL, java.lang.String pFailureURL, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          If the transaction is marked as rollback, then redirect to the FailureURL, otherwise allow the super-class behavior to perform.
 void commitTransaction()
          This method commits the current transaction (or rolls it back if you have called setRollbackTransaction(true) since the transaction started).
protected  TransactionDemarcation getTransactionDemarcation()
          Returns property TransactionDemarcation.
protected  int getTransactionStatus()
          Obtain the status of the transaction associated with the current thread.
 boolean isEnsureTransaction()
          Returns property EnsureTransaction, if false then no transaction management is performed
protected  boolean isRollbackTransaction()
          Returns property RollbackTransaction.
 boolean isRollbackTransactionOnUnhandledException()
          Gets the value of the isRollbackTransactionOnUnhandledException property.
protected  boolean isTransactionMarkedAsRollback()
          Returns true if the transaction associated with the current thread is marked for rollback.
 void setEnsureTransaction(boolean pEnsureTransaction)
          Sets property EnsureTransaction
protected  void setRollbackTransaction(boolean pRollbackTransaction)
          Sets property RollbackTransaction
 void setRollbackTransactionOnUnhandledException(boolean pRollbackTransactionOnUnhandledException)
          Sets the value of the isRollbackTransactionOnUnhandledException property.
protected  void setTransactionDemarcation(TransactionDemarcation pTransactionDemarcation)
          Sets property TransactionDemarcation Previously, this method stored the TransactionDemarcation object as a member variable.
 
Methods inherited from class atg.droplet.GenericFormHandler
addFormException, addUncheckedFormException, createFormSubmissionMessage, getCancelURL, getCheckForValidSession, getFormError, getFormExceptions, getFormName, getMessagePort, getMessageSource, getMessageType, getPropertyExceptions, getSendMessages, getUncheckedFormExceptions, handleCancel, handleFormException, handleUncheckedFormException, hasUncheckedFormExceptions, isDeferForwardsAndRedirects, isRestorableForm, isUseForwards, isValidSession, redirectOrForward, resetFormExceptions, setCancelURL, setCheckForValidSession, setDeferForwardsAndRedirects, setFormName, setMessagePort, setMessageSource, setMessageType, setRestorableForm, setSendMessages, setUseForwards
 
Methods inherited from class atg.droplet.EmptyFormHandler
afterGet, beforeGet
 
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, reResolveThis, 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

TransactionalFormHandler

public TransactionalFormHandler()
Constructs an instanceof TransactionalFormHandler

Method Detail

setEnsureTransaction

public void setEnsureTransaction(boolean pEnsureTransaction)
Sets property EnsureTransaction


isEnsureTransaction

public boolean isEnsureTransaction()
Returns property EnsureTransaction, if false then no transaction management is performed


setTransactionDemarcation

protected void setTransactionDemarcation(TransactionDemarcation pTransactionDemarcation)
Sets property TransactionDemarcation Previously, this method stored the TransactionDemarcation object as a member variable. Since this component can be session scoped, multiple requests using the same session scoped form handler can collide with their use of the form handler. Now, this method stores the attribute in the current request.


getTransactionDemarcation

protected TransactionDemarcation getTransactionDemarcation()
Returns property TransactionDemarcation. This object that is used to manage transactions in the beforeSet and afterSet methods. This is created in the beforeSet method and set to null in afterSet.


setRollbackTransaction

protected void setRollbackTransaction(boolean pRollbackTransaction)
Sets property RollbackTransaction


isRollbackTransaction

protected boolean isRollbackTransaction()
Returns property RollbackTransaction. If this is true, then the transaction will be marked for rollback in the afterSet method. This defaults to false and is reset to false in afterSet.


beforeSet

public boolean beforeSet(DynamoHttpServletRequest pRequest,
                         DynamoHttpServletResponse pResponse)
                  throws DropletFormException
Creates a new TransactionDemarcation and then begins the transaction. If the ensureTransaction property is false then no transacation management is performed.

Specified by:
beforeSet in interface DropletFormHandler
Overrides:
beforeSet in class GenericFormHandler
Returns:
true if form processing should continue, false if it should be aborted
Throws:
DropletFormException

afterSet

public boolean afterSet(DynamoHttpServletRequest pRequest,
                        DynamoHttpServletResponse pResponse)
                 throws DropletFormException
If the TransactionDemarcation is not null, then the transaction is ended. The transaction can be marked for rollback if the property rollbackTransaction is set to true, otherwise the transaction is committed. If the ensureTransaction property is false then no transacation management is performed. The transactionDemarcation property is set to null and rollbackTransaction property is set to false in the finally clause of this method after the super.afterSet method is called.

Specified by:
afterSet in interface DropletFormHandler
Overrides:
afterSet in class GenericFormHandler
Returns:
true if request processing should continue and the requested URL should be served, false if it should be aborted. If false is returned, you typically have already completed the request with a redirect or by sending output to the output stream.
Throws:
DropletFormException

isTransactionMarkedAsRollback

protected boolean isTransactionMarkedAsRollback()
Returns true if the transaction associated with the current thread is marked for rollback.


getTransactionStatus

protected int getTransactionStatus()
Obtain the status of the transaction associated with the current thread.

Returns:
The transaction status. If no transaction is associated with the current thread, this method returns the Status.NoTransaction value Logs an error and returns unknown status if TransactionManager.getStatus() throws a SystemException.

checkFormRedirect

public boolean checkFormRedirect(java.lang.String pSuccessURL,
                                 java.lang.String pFailureURL,
                                 DynamoHttpServletRequest pRequest,
                                 DynamoHttpServletResponse pResponse)
                          throws javax.servlet.ServletException,
                                 java.io.IOException
If the transaction is marked as rollback, then redirect to the FailureURL, otherwise allow the super-class behavior to perform.

Overrides:
checkFormRedirect in class GenericFormHandler
Parameters:
pSuccessURL - The URL to redirect to if there were no form errors. If a null value is passed in, no redirect occurs.
pFailureURL - The URL to redirect to if form errors were found. If a null value is passed in, no redirect occurs.
pRequest - the servlet's request
pResponse - the servlet's response
Returns:
If redirect (for whatever reason) to a new page occurred, return false. If NO redirect occurred, return true.
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

commitTransaction

public void commitTransaction()
This method commits the current transaction (or rolls it back if you have called setRollbackTransaction(true) since the transaction started).


isRollbackTransactionOnUnhandledException

public boolean isRollbackTransactionOnUnhandledException()
Gets the value of the isRollbackTransactionOnUnhandledException property.

Returns:
true if the transaction should rollback if there was an unhandled exception thrown from a handle method.

setRollbackTransactionOnUnhandledException

public void setRollbackTransactionOnUnhandledException(boolean pRollbackTransactionOnUnhandledException)
Sets the value of the isRollbackTransactionOnUnhandledException property.

Parameters:
pRollbackTransactionOnUnhandledException - true if the transaction should rollback if there was an unhandled exception thrown from a handle method.