Package de.hybris.platform.jalo
Interface Item.ItemConstraint
-
- Enclosing class:
- Item
public static interface Item.ItemConstraint
Interface for implementing transaction aware consistency checks using the item methodItem.checkConstraint(ItemConstraint)
. Using this interface consistency check code is wrapped in an object and executed depending upon the enclosing transaction state. If there is no active transaction running the code is executed immediately by callingassertConstraint(Item)
. If it throws an exception the methodundoChanges(Item)
is called to let the enclosing code restore the previous state. In case there is a running transaction the code is not executed by registered at the transaction. It is being executed by callingassertConstraint(Item)
upon transaction commit just before the actual changes are committed permanently. If one of the registered constrains throws an exception the transaction is rolled back - soundoChanges(Item)
is not called in this case! An example:public void do( String arg ) { final String prev = getProperty("blah"); setProperty( "blah", arg ); checkConstraint( new ItemConstraint() { public void assertConstraint(Item item) throws ConsistencyCheckException { if( ((MyItem)item).getProperty("blubb") == null && ((MyItem)item).getProperty("blah") == null ) throw new ConsistencyCheckException("should never happen", 0 ); } public void undoChanges( Item item ) { ((MyItem)item).setProperty("blah", prev ); } } ); }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
assertConstraint(Item item)
Called to perform the actual constraint checking.void
undoChanges(Item item)
Called only if there is no enclosing transaction to rollback changes automatically: this method should restore the item state prior the change which triggered this constraint.
-
-
-
Method Detail
-
assertConstraint
void assertConstraint(Item item) throws ConsistencyCheckException
Called to perform the actual constraint checking.- Parameters:
item
- the item from whichItem.checkConstraint(de.hybris.platform.jalo.Item.ItemConstraint)
has been called.- Throws:
ConsistencyCheckException
- to signal that the constraint is violated
-
undoChanges
void undoChanges(Item item)
Called only if there is no enclosing transaction to rollback changes automatically: this method should restore the item state prior the change which triggered this constraint.- Parameters:
item
- the item from whichItem.checkConstraint(de.hybris.platform.jalo.Item.ItemConstraint)
has been called.
-
-