fri.util.database.jpa.tree.uniqueconstraints
Interface UniqueTreeConstraint<N extends TreeNode>

All Known Implementing Classes:
AbstractUniqueTreeConstraintImpl, AbstractWholeTreeUniqueConstraintImpl, UniqueChildrenConstraintImpl, UniqueChildrenConstraintImpl, UniqueChildrenTemporalConstraintImpl, UniqueChildrenTemporalConstraintImpl, UniqueWholeTreeConstraintImpl, UniqueWholeTreeConstraintImpl, UniqueWholeTreeTemporalConstraintImpl, UniqueWholeTreeTemporalConstraintImpl

public interface UniqueTreeConstraint<N extends TreeNode>

Implementers check unique constraints in a tree-table. This interface expects the constructor of the implementation to receive names of properties that have to be unique.

Mind that this constraint implementation must be applied BEFORE setXxx() is called on a domain object (POJO), as the JPA container might flush the setXxx() call to database before the checker query is launched (then, of course, the wrong value will be found by the query). Thus the application MUST call treeDao.checkUniqueConstraint() BEFORE updating an unique property, and it must do this using a clone of the persistent entity. See AbstractTreeTest.setName() unit test method for an example how to do this.

Author:
Fritz Ritzberger, 20.10.2011

Method Summary
 boolean checkUniqueConstraint(java.util.List<N> candidates, TreeActionLocation<N> location)
          The implementation of this is expected to check the uniqueness of passed node(s).
 void setContext(DbSession session, TreeDao<N> dao, java.lang.String nodeEntityName, java.lang.String pathEntityName)
          Called by the DAO to publish context information to this constraint-checker.
 

Method Detail

checkUniqueConstraint

boolean checkUniqueConstraint(java.util.List<N> candidates,
                              TreeActionLocation<N> location)
The implementation of this is expected to check the uniqueness of passed node(s). Called by the DAO when addChild(), move() or copy() is performed. Mind that you must call treeDao.checkUniqueConstraint() explicitly when updating a node property, see explanation in header comment!

Parameters:
candidates - one (default) or more (copy/move only) entities that hold values to check for uniqueness at location, when list, the copied node will be first, then its sub-nodes.
location - the information where the pending modification is going to happen.
Returns:
false when unique constraint would be violated, else true.

setContext

void setContext(DbSession session,
                TreeDao<N> dao,
                java.lang.String nodeEntityName,
                java.lang.String pathEntityName)
Called by the DAO to publish context information to this constraint-checker.

Parameters:
dao - the calling DAO, provides tree access for reading children, parents, etc.
nodeEntityName - name of the JPQL node database table.
pathEntityName - optionally the name of the JPQL tree-path database table, can be null, this is for ClosureTable only.
session - the database session to use for uniqueness checks.