public static interface Item.ItemConstraint
Item.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 calling assertConstraint(Item). If it throws an exception the method
undoChanges(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 calling
assertConstraint(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 - so
undoChanges(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 );
}
}
);
}
| Modifier and Type | Method and 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.
|
void assertConstraint(Item item) throws ConsistencyCheckException
item - the item from which Item.checkConstraint(de.hybris.platform.jalo.Item.ItemConstraint) has
been called.ConsistencyCheckException - to signal that the constraint is violatedvoid undoChanges(Item item)
item - the item from which Item.checkConstraint(de.hybris.platform.jalo.Item.ItemConstraint) has
been called.Copyright © 2017 SAP SE. All Rights Reserved.