Interface Item.ItemConstraint

  • Enclosing class:
    Item

    public static interface Item.ItemConstraint
    Interface for implementing transaction aware consistency checks using the item method 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 );
                    }
                }
                    );
        }
     
    See Also:
    Item.checkConstraint(de.hybris.platform.jalo.Item.ItemConstraint)
    • 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.