de.mguennewig.pobjects
Class PObjNestedSet<T extends Record>

java.lang.Object
  extended by de.mguennewig.pobjects.AbstractPObjJoin<T>
      extended by de.mguennewig.pobjects.PObjNestedSet<T>

public class PObjNestedSet<T extends Record>
extends AbstractPObjJoin<T>

Wrapper object for nested set valued joins between two tables.

Even thought the methods of this set are synchronized is there still the chance for concurrent modifications made by other database users.

Note that a nested set requires a database that supports SQL commands and SELECT statements.

Author:
Michael Günnewig
See Also:
JdbcContainer

Constructor Summary
PObjNestedSet(PObject parent, java.lang.Class<? extends Record> elementClass, Column rightColumn)
           
PObjNestedSet(PObject parent, java.lang.Class<? extends Record> elementClass, NestedSetType nestedSetType)
          Creates a new nested set.
 
Method Summary
 T add(T parent, T node)
           
 T getAncestor(T node)
          Returns the direct ancestor of the given node.
 T[] getChildren(T node)
          Returns the direct descendants/children of the given node.
 T[] getDescendants(T node)
          Returns all descendants (the complete subtree) of the given node.
 T[] getPath(T node)
          Returns the path from the root to the given node.
 int getSubtreeSize(T node)
          Returns the number of descendants for the given node.
 boolean isLeaf(T node)
          Returns whether the given node is a leaf in the set.
 boolean remove(T obj)
          Remove the give record obj as an element from the nested set.
 
Methods inherited from class de.mguennewig.pobjects.AbstractPObjJoin
clear, findAll, getContainer, getElementClass, getElementDecl, getParent, isEmpty, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PObjNestedSet

public PObjNestedSet(PObject parent,
                     java.lang.Class<? extends Record> elementClass,
                     NestedSetType nestedSetType)
Creates a new nested set.


PObjNestedSet

public PObjNestedSet(PObject parent,
                     java.lang.Class<? extends Record> elementClass,
                     Column rightColumn)
Method Detail

add

public T add(T parent,
             T node)
                     throws PObjConstraintException,
                            PObjSQLException
Throws:
PObjConstraintException
PObjSQLException

getAncestor

public final T getAncestor(T node)
Returns the direct ancestor of the given node.

This is equivalent to use the last element of getPath(Record).

Throws:
java.lang.IllegalArgumentException - if no node has been given or does not belongs to this nested set.
PObjReadError - if any database read error occurs.

getDescendants

public T[] getDescendants(T node)
Returns all descendants (the complete subtree) of the given node.

Throws:
java.lang.IllegalArgumentException - if no node has been given or does not belongs to this nested set.
PObjReadError - if any database read error occurs.
See Also:
getSubtreeSize(Record)

getChildren

public T[] getChildren(T node)
Returns the direct descendants/children of the given node.

Throws:
java.lang.IllegalArgumentException - if no node has been given or does not belongs to this nested set.
PObjReadError - if any database read error occurs.

getPath

public T[] getPath(T node)
Returns the path from the root to the given node.

Returns:
The path from the root to the given node (inclusive).
Throws:
java.lang.IllegalArgumentException - if no node has been given or does not belongs to this nested set.
PObjReadError - if any database read error occurs.

getSubtreeSize

public int getSubtreeSize(T node)
Returns the number of descendants for the given node.

See Also:
getDescendants(Record)

isLeaf

public boolean isLeaf(T node)
Returns whether the given node is a leaf in the set.

Nodes that are not persistent are leaves.


remove

public boolean remove(T obj)
               throws PObjConstraintException,
                      PObjSQLException
Remove the give record obj as an element from the nested set. If the element exists prior to the call, then the result is true. The data is stored immediately in the RDBMS.

Throws:
PObjConstraintException
PObjSQLException