|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfri.util.database.jpa.tree.AbstractTreeDao<N>
N
- the tree node type handled by this DAO.public abstract class AbstractTreeDao<N extends TreeNode>
Common functionalities for a TreeDao implementation.
Mind that concurrency is not handled in any way. The caller is expected to provide a transaction around every DAO write-method. DAO write-methods execute more than one JPQL statement when called!
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface fri.util.database.jpa.tree.TreeDao |
---|
TreeDao.CopiedNodeRenamer<N extends TreeNode> |
Field Summary | |
---|---|
protected DbSession |
session
|
Fields inherited from interface fri.util.database.jpa.tree.TreeDao |
---|
UNDEFINED_POSITION |
Constructor Summary | |
---|---|
protected |
AbstractTreeDao(DbSession session,
java.lang.String nodeEntityName)
|
Method Summary | |
---|---|
protected void |
appendInvalidityCondition(java.lang.String tableAlias,
java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters)
Temporal extension. |
void |
appendValidityCondition(java.lang.String tableAlias,
java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters)
Temporal extension. |
protected void |
applyCopiedNodeRenamer(N node)
Applies the currently set CopiedNodeRenamer if one was set. |
protected void |
assertUpdate(N node)
Throws IllegalArgumentException when node is not persistent, because then it is not an UPDATE. |
protected void |
beforeFindQuery(java.lang.String tableAlias,
java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters,
boolean whereWasAppended,
boolean doNotApplyTemporalConditions,
boolean invertTemporalConditions)
Temporal extension. |
protected java.lang.String |
buildAliasedPropertyName(java.lang.String tableAlias,
java.lang.String propertyName)
|
protected java.lang.String |
buildIndexedPlaceHolder(java.util.List<java.lang.Object> parameters)
|
void |
checkUniqueConstraint(N cloneOfExistingNodeWithNewValues,
N root,
N existingNode)
Checks unique constraint(s) for passed entity before an update of unique properties. |
protected void |
checkUniqueness(java.util.List<N> nodes,
TreeActionLocation<N> location)
Utility method that calls the implementation when one was defined. |
protected void |
copyOrMovePreconditions(N relativeNode,
N nodeToMove)
Throws IllegalArgumentException when copy or move could not performed, checks if tree would be copied/moved into itself. |
boolean |
equal(N n1,
N n2)
Decides if two nodes are equal. |
protected UniqueTreeConstraint<N> |
getUniqueTreeConstraint()
|
protected java.lang.String |
getValidFromPropertyName()
Temporal extension. |
protected java.lang.String |
getValidToPropertyName()
Temporal extension. |
boolean |
isPersistent(N entity)
|
boolean |
isValid(Temporal node,
java.util.Date validityDate)
Temporal extension. |
protected java.lang.String |
nodeEntityName()
|
protected java.lang.String |
pathEntityName()
|
protected void |
refresh(java.util.List<?> nodesToRefresh)
Updates nodes from database, overwriting pending local changes. |
protected java.lang.Object |
save(N node)
Saves the given node to session. |
void |
setCheckUniqueConstraintOnUpdate(boolean checkUniqueConstraintOnUpdate)
Setting this to true will call unique constraint(s) even on update() . |
void |
setCopiedNodeRenamer(TreeDao.CopiedNodeRenamer<N> copiedNodeRenamer)
Sets a CopiedNodeRenamer for copy actions in trees guarded by unique constraint(s). |
void |
setUniqueTreeConstraint(UniqueTreeConstraint<N> uniqueTreeConstraint)
Optionally lets set unique constraint(s). |
protected boolean |
shouldCheckUniqueConstraintOnUpdate()
|
protected java.util.Date |
validFrom()
Temporal extension. |
protected java.util.Date |
validTo()
Temporal extension. |
protected java.util.Date |
validToOnRemove()
Temporal extension. |
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.TreeDao |
---|
addChild, addChildAt, addChildBefore, copy, copyBefore, copyTo, copyToBeRoot, createRoot, find, find, findDirectChildren, findSubTree, getChildCount, getChildren, getLevel, getParent, getPath, getRoot, getRoots, getTree, getTreeCacheable, isChildOf, isEqualToOrChildOf, isLeaf, isRoot, move, moveBefore, moveTo, moveToBeRoot, remove, removeAll, size, update |
Field Detail |
---|
protected final DbSession session
Constructor Detail |
---|
protected AbstractTreeDao(DbSession session, java.lang.String nodeEntityName)
Method Detail |
---|
public boolean isPersistent(N entity)
isPersistent
in interface TreeDao<N extends TreeNode>
protected java.lang.Object save(N node)
public boolean equal(N n1, N n2)
UniqueTreeConstraint
implementations.
public void setUniqueTreeConstraint(UniqueTreeConstraint<N> uniqueTreeConstraint)
setUniqueTreeConstraint
in interface TreeDao<N extends TreeNode>
uniqueTreeConstraint
- the constraint checker implementation, or null to switch off checking.public void setCheckUniqueConstraintOnUpdate(boolean checkUniqueConstraintOnUpdate)
update()
.
Default is false, because it is assumed that caller itself does a check
by calling dao.checkUniqueConstraint()
before updating.
setCheckUniqueConstraintOnUpdate
in interface TreeDao<N extends TreeNode>
checkUniqueConstraintOnUpdate
- the behavior to be set.protected final boolean shouldCheckUniqueConstraintOnUpdate()
protected final UniqueTreeConstraint<N> getUniqueTreeConstraint()
public void checkUniqueConstraint(N cloneOfExistingNodeWithNewValues, N root, N existingNode) throws UniqueConstraintViolationException
name
in entity, this method MUST be
called BEFORE entity.setName(name)
is called, else entity will get dirty and
will be flushed by the JPA layer before the constraint checking query can be launched.
For that purpose you must create a clone (template) of the node pending to be updated,
and set the new value of the property into the clone.
checkUniqueConstraint
in interface TreeDao<N extends TreeNode>
cloneOfExistingNodeWithNewValues
- non-persistent clone of the entity to be checked,
containing at least the properties the constraint will check.root
- the root where insert or update will happen, null when node is (or will be) be a root.existingNode
- the original node to be inserted or updated, null when node is not yet persistent.
UniqueConstraintViolationException
- when uniqueness would be violated.protected void checkUniqueness(java.util.List<N> nodes, TreeActionLocation<N> location) throws UniqueConstraintViolationException
nodes
- one or several nodes to insert or update. Updates should be tested with a clone, else JPA object would get dirty.root
- the root of the tree where to check, can be null for a uniqueness check among roots.originalNode
- the node to be updated, must be null for a new node to be inserted.modificationLocation
- insert/update location information, implementation-specific.
UniqueConstraintViolationException
- when constraint would be violated.public void setCopiedNodeRenamer(TreeDao.CopiedNodeRenamer<N> copiedNodeRenamer)
setCopiedNodeRenamer
in interface TreeDao<N extends TreeNode>
copiedNodeRenamer
- the editor to be applied for following copy action, can be null.protected final void applyCopiedNodeRenamer(N node)
protected final java.lang.String nodeEntityName()
protected java.lang.String pathEntityName()
protected void assertUpdate(N node)
protected void copyOrMovePreconditions(N relativeNode, N nodeToMove)
protected void refresh(java.util.List<?> nodesToRefresh)
protected final void beforeFindQuery(java.lang.String tableAlias, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters, boolean whereWasAppended, boolean doNotApplyTemporalConditions, boolean invertTemporalConditions)
public void appendValidityCondition(java.lang.String tableAlias, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters)
UniqueTemporalTreeConstraint
implementations.
tableAlias
- the alias of the table containing the validTo property, without trailing dot, could be null.queryText
- the pending JPQL query text looking for valid nodes.parameters
- the positional arguments for the pending query.protected void appendInvalidityCondition(java.lang.String tableAlias, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters)
tableAlias
- the alias of the table containing the validTo property, without trailing dot, could be null.queryText
- the pending JPQL query text looking for invalid nodes.parameters
- the positional arguments for the pending query.protected final java.lang.String buildAliasedPropertyName(java.lang.String tableAlias, java.lang.String propertyName)
protected final java.lang.String buildIndexedPlaceHolder(java.util.List<java.lang.Object> parameters)
protected java.util.Date validFrom()
new Date()
which represents "now".protected java.util.Date validTo()
new Date()
which represents "now".protected java.util.Date validToOnRemove()
new Date()
which represents "now".public boolean isValid(Temporal node, java.util.Date validityDate)
node.validFrom
is null or before or equal to given date,
and node.validTo
is null or after given date.protected java.lang.String getValidFromPropertyName()
protected java.lang.String getValidToPropertyName()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |