|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfri.util.database.jpa.tree.uniqueconstraints.AbstractUniqueTreeConstraintImpl<N>
public abstract class AbstractUniqueTreeConstraintImpl<N extends TreeNode>
Basic unique constraint check implementation. Provides utility methods to check uniqueness (1) in children and (2) in whole tree.
This also provides a check for unique roots. Which of these two checks is performed (roots or tree) is managed internally (depends on the arguments of checkUniqueConstraint(), see isRootsCheck()).
Field Summary | |
---|---|
protected boolean |
shouldCheckRootsForUniqueness
True when constraint should also check that no root has the same unique property set as another root. |
protected java.lang.String[][] |
uniquePropertyNames
One or several property name sets that represent this unique constraint. |
Constructor Summary | |
---|---|
protected |
AbstractUniqueTreeConstraintImpl(java.lang.String[][] uniquePropertyNames,
boolean shouldCheckRootsForUniqueness)
|
Method Summary | |
---|---|
protected abstract void |
appendNodeCheckingCondition(N root,
java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters)
|
protected abstract void |
appendRootCheckingCondition(java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters)
|
protected void |
appendUniquenessConditions(N node,
java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters,
java.lang.String tableAlias)
Appends unique property conditions to queryText and parameters, not starting with "AND". |
protected void |
appendUpdateCondition(N node,
java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters,
java.lang.String tableAlias,
TreeActionLocation<N> location)
When node is persistent and action is neither MOVE nor INSERT, appends a condition saying "node != originalNode", thus avoiding the node to detect itself. |
protected void |
beforeCheckUniqueness(java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters)
Does nothing. |
protected boolean |
checkUniqueChildrenConstraint(N node,
TreeActionLocation<N> location)
Checks if passed node would be unique in the children of given location, but can not check roots. |
protected boolean |
checkUniqueWholeTreeConstraint(java.util.List<N> nodes,
TreeActionLocation<N> location)
Checks if passed node would be unique within its tree. |
protected boolean |
equal(N n1,
N n2)
Delegates to dao.equal(). |
protected abstract java.lang.String |
fromClause()
|
protected TreeDao<N> |
getDao()
|
protected abstract java.lang.String |
getNodeTableAlias()
|
protected java.lang.Object |
getNodeValueForProperty(java.lang.String uniqueName,
java.lang.Object node)
Retrieves a named value from given Object by reflection. |
protected DbSession |
getSession()
|
protected boolean |
isDifferent(java.lang.Object newValue,
java.lang.Object existingValue)
Equality of node property values. |
protected boolean |
isRootsCheck(N root,
N node)
|
protected java.lang.String |
nodeEntityName()
|
protected java.lang.String |
pathEntityName()
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface fri.util.database.jpa.tree.uniqueconstraints.UniqueTreeConstraint |
---|
checkUniqueConstraint |
Field Detail |
---|
protected final java.lang.String[][] uniquePropertyNames
protected final boolean shouldCheckRootsForUniqueness
Constructor Detail |
---|
protected AbstractUniqueTreeConstraintImpl(java.lang.String[][] uniquePropertyNames, boolean shouldCheckRootsForUniqueness)
uniquePropertyNames
- JPQL property names that should be checked for uniqueness.
For example, to check (1) "name" combined with "code", and (2) "acronym", for uniqueness,
pass in new String [][] { { "name", "code" }, { "acronym" } }
.shouldCheckRootsForUniqueness
- true when constraint should also check that
no root has the same unique property set as another root.Method Detail |
---|
public void setContext(DbSession session, TreeDao<N> dao, java.lang.String nodeEntityName, java.lang.String pathEntityName)
UniqueTreeConstraint
setContext
in interface UniqueTreeConstraint<N extends TreeNode>
session
- the database session to use for uniqueness checks.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.protected final java.lang.String nodeEntityName()
protected final java.lang.String pathEntityName()
protected final TreeDao<N> getDao()
protected final DbSession getSession()
protected final java.lang.Object getNodeValueForProperty(java.lang.String uniqueName, java.lang.Object node)
protected boolean checkUniqueChildrenConstraint(N node, TreeActionLocation<N> location)
protected final boolean equal(N n1, N n2)
protected boolean isDifferent(java.lang.Object newValue, java.lang.Object existingValue)
protected final boolean checkUniqueWholeTreeConstraint(java.util.List<N> nodes, TreeActionLocation<N> location)
protected abstract java.lang.String getNodeTableAlias()
protected abstract java.lang.String fromClause()
protected abstract void appendRootCheckingCondition(java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters)
protected abstract void appendNodeCheckingCondition(N root, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters)
protected boolean isRootsCheck(N root, N node)
root
- the root of the node about to be inserted or updated, must be null for root checks.node
- the node about to be updated, null when this is an insert.
protected void appendUpdateCondition(N node, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters, java.lang.String tableAlias, TreeActionLocation<N> location)
protected final void appendUniquenessConditions(N node, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters, java.lang.String tableAlias)
protected void beforeCheckUniqueness(java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |