com.softwareag.mdm.schema.trigger
Class TableTrigger

java.lang.Object
  extended bycom.softwareag.mdm.schema.trigger.TableTrigger

public abstract class TableTrigger
extends Object

Specifies methods that are automatically executed when some operations are performed on a table. This is the equivalent of database triggers.

Schema definition

The trigger must be declared under the element xs:annotation/xs:appinfo:

 <mdm:trigger class="com.foo.MyTableTrigger" />
where com.foo.MyTableTrigger is the fully qualified name of the class implementing this interface. It is also possible to set additional JavaBean properties:
 <mdm:trigger class="com.foo.MyTableTrigger">
 	 <param1>...</param1>
 	 <param2>...</param2>
 </mdm:trigger>
where param1 and param2 are JavaBean properties of the class specified.

For more information, read JavaBeans specification.

Life-cycle

  1. When the schema is loaded:
    1. the class specified is instantiated through its default constructor and the JavaBean properties' setters are called (in the example above, setParam1(...) and setParam2(...));
    2. the method setup(TriggerSetupContext) is called on the new instance.
  2. In operational phase: the methods handle... are called each time the associated operation is executed.

If several operations are defined for the same table, no specific ordering in their execution must be assumed.

Transaction Management

The general execution of triggers during a transaction follows the triple : before update, update, after update. Where an update is either a creation, a modification or a deletion of an occurrence. During a given transaction, one can have a sequence of nested updates as shown in the following example:

Begin triple 1  
   before update 1 
   update 1  
   after update 1 
      Begin triple 2  
         before update 2  
         update 2  
         after update 2  
            Begin triple 3  
               before update 3  
               update 3  
               after update 3  
            End triple 3  
      End triple 2  
End triple 1  

Note that a sequence of nested updates is handled by the same ProcedureContext.

Exception handling

If any update method throws an exception, the container will properly handles it so as to preserve integrity: any modifications that would have been made on the current repository (see ProcedureContext.getAdaptationHome()), during a given sequence of nested updates execution, will be cancelled.

Furthermore, if a ProcedureContext raises an exception then any preceeding updates made on the repository, during a given sequence of nested updates execution, will be first cancelled before the corresponding update method gets the exception. This additional feature is for ensuring that repository and cache remain consistent, even if the corresponding update method catches the exception.

Known Limitation

A "before trigger" allows to update, in the current branch, only the current occurrence content (no access to ProcedureContext is provided). If at this stage more advanced updates were needed, one should use a specific service instead of triggers.


Constructor Summary
TableTrigger()
           
 
Method Summary
 void handleAfterCreate(AfterCreateOccurrenceContext aContext)
          This method is called after the creation of an occurrence.
 void handleAfterDelete(AfterDeleteOccurrenceContext aContext)
          This method is called after deleting an occurrence.
 void handleAfterModify(AfterModifyOccurrenceContext aContext)
          This method is called after the modification of an occurrence.
 void handleBeforeCreate(BeforeCreateOccurrenceContext aContext)
          This method is called before the creation of an occurrence.
 void handleBeforeDelete(BeforeDeleteOccurrenceContext aContext)
          This method is called before deleting an occurrence.
 void handleBeforeModify(BeforeModifyOccurrenceContext aContext)
          This method is called before the modification of an occurrence.
 void handleNewContext(NewTransientOccurrenceContext aContext)
          This method is called when a transient occurrence context is created.
abstract  void setup(TriggerSetupContext aContext)
          This method is called when the schema is loaded, for checking and preparing this instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableTrigger

public TableTrigger()
Method Detail

setup

public abstract void setup(TriggerSetupContext aContext)
This method is called when the schema is loaded, for checking and preparing this instance.


handleNewContext

public void handleNewContext(NewTransientOccurrenceContext aContext)
This method is called when a transient occurrence context is created. It gives the opportunity to feed the context with some specific values.

Default implementation does nothing.

See Also:
ProcedureContext.getContextForNewOccurrence(AdaptationTable)

handleBeforeCreate

public void handleBeforeCreate(BeforeCreateOccurrenceContext aContext)
                        throws OperationException
This method is called before the creation of an occurrence. It gives the opportunity to feed the new occurrence content with some specific values.

Default implementation does nothing.

See Transaction Management.

Throws:
OperationException - when an exception occurred or for preventing the execution of the subsequent creation (guard role). Warning: in case of a mass update the whole transaction is aborted.

handleAfterCreate

public void handleAfterCreate(AfterCreateOccurrenceContext aContext)
This method is called after the creation of an occurrence. It gives the opportunity to notify a third-party system.

Default implementation does nothing.

See Transaction Management.


handleBeforeModify

public void handleBeforeModify(BeforeModifyOccurrenceContext aContext)
                        throws OperationException
This method is called before the modification of an occurrence. It gives the opportunity to modify the occurrence contents with some additional values. If no modification is set to the initial occurrence contents, this trigger will not be executed.

Default implementation does nothing.

See Transaction Management.

Throws:
OperationException - when an exception occurred or for preventing the execution of the subsequent modification (guard role). Warning: in case of a mass update the whole transaction is aborted.

handleAfterModify

public void handleAfterModify(AfterModifyOccurrenceContext aContext)
This method is called after the modification of an occurrence. It gives the opportunity to notify a third-party system. If no modification is set to the initial occurrence contents, this trigger will not be executed.

Default implementation does nothing.

See Transaction Management.


handleBeforeDelete

public void handleBeforeDelete(BeforeDeleteOccurrenceContext aContext)
                        throws OperationException
This method is called before deleting an occurrence.

Default implementation does nothing.

See Transaction Management.

Throws:
OperationException - when an exception occurred or for preventing the execution of the subsequent deletion (guard role). Warning: in case of a mass update the whole transaction is aborted.

handleAfterDelete

public void handleAfterDelete(AfterDeleteOccurrenceContext aContext)
This method is called after deleting an occurrence.

Default implementation does nothing.

See Transaction Management.



(report a bug)
webMethods MDM 4.2.8 [0558]
Copyright Software AG 2000-2007. All rights reserved.