org.apache.cayenne.query
Class PrefetchTreeNode

java.lang.Object
  extended by org.apache.cayenne.query.PrefetchTreeNode
All Implemented Interfaces:
java.io.Serializable, XMLSerializable

public class PrefetchTreeNode
extends java.lang.Object
implements java.io.Serializable, XMLSerializable

Defines a node in a prefetch tree.

Since:
1.2
Author:
Andrus Adamchik
See Also:
Serialized Form

Field Summary
protected  java.util.Collection children
           
static int DISJOINT_PREFETCH_SEMANTICS
           
static int JOINT_PREFETCH_SEMANTICS
           
protected  java.lang.String name
           
protected  PrefetchTreeNode parent
           
protected  boolean phantom
           
protected  int semantics
           
static int UNDEFINED_SEMANTICS
           
 
Constructor Summary
  PrefetchTreeNode()
          Creates a root node of the prefetch tree.
protected PrefetchTreeNode(PrefetchTreeNode parent, java.lang.String segmentPath)
          Creates a phantom PrefetchTreeNode, initializing it with parent node and a name of a relationship segment connecting this node with the parent.
 
Method Summary
 void addChild(PrefetchTreeNode child)
           
 PrefetchTreeNode addPath(java.lang.String path)
          Adds a "path" with specified semantics to this prefetch node.
 java.util.Collection adjacentJointNodes()
          Returns a subset of nodes with "joint" semantics that are to be prefetched in the same query as the current node.
 java.util.Collection disjointNodes()
          Returns a collection of PrefetchTreeNodes with disjoint semantics.
 void encodeAsXML(XMLEncoder encoder)
          Prints itself as XML to the provided XMLEncoder.
protected  PrefetchTreeNode getChild(java.lang.String segment)
           
 java.util.Collection getChildren()
          Returns an unmodifiable collection of children.
 java.lang.String getName()
           
 PrefetchTreeNode getNode(java.lang.String path)
          Looks up an existing node in the tree desribed by the dot-separated path.
 PrefetchTreeNode getParent()
           
 java.lang.String getPath()
          Returns full prefetch path, that is a dot separated String of node names starting from root and up to and including this node.
 java.lang.String getPath(PrefetchTreeNode upTillParent)
           
 PrefetchTreeNode getRoot()
          Returns the root of the node tree.
 int getSemantics()
           
 boolean hasChildren()
           
 boolean isDisjointPrefetch()
           
 boolean isJointPrefetch()
           
 boolean isPhantom()
           
 java.util.Collection jointNodes()
          Returns a collection of PrefetchTreeNodes in this tree with joint semantics.
 java.util.Collection nonPhantomNodes()
          Returns a collection of PrefetchTreeNodes that are not phantoms.
 void removeChild(PrefetchTreeNode child)
           
protected  void removeChild(java.lang.String segment)
           
 void removePath(java.lang.String path)
          Removes or makes phantom a node defined by this path.
 void setPhantom(boolean phantom)
           
 void setSemantics(int semantics)
           
 void traverse(PrefetchProcessor processor)
          Traverses the tree depth-first, invoking callback methods of the processor when passing through the nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDEFINED_SEMANTICS

public static final int UNDEFINED_SEMANTICS
See Also:
Constant Field Values

JOINT_PREFETCH_SEMANTICS

public static final int JOINT_PREFETCH_SEMANTICS
See Also:
Constant Field Values

DISJOINT_PREFETCH_SEMANTICS

public static final int DISJOINT_PREFETCH_SEMANTICS
See Also:
Constant Field Values

name

protected java.lang.String name

phantom

protected boolean phantom

semantics

protected int semantics

parent

protected transient PrefetchTreeNode parent

children

protected java.util.Collection children
Constructor Detail

PrefetchTreeNode

public PrefetchTreeNode()
Creates a root node of the prefetch tree. Children can be added to the parent by calling "addPath".


PrefetchTreeNode

protected PrefetchTreeNode(PrefetchTreeNode parent,
                           java.lang.String segmentPath)
Creates a phantom PrefetchTreeNode, initializing it with parent node and a name of a relationship segment connecting this node with the parent.

Method Detail

encodeAsXML

public void encodeAsXML(XMLEncoder encoder)
Description copied from interface: XMLSerializable
Prints itself as XML to the provided XMLEncoder.

Specified by:
encodeAsXML in interface XMLSerializable

getRoot

public PrefetchTreeNode getRoot()
Returns the root of the node tree. Root is the topmost parent node that itself has no parent set.


getPath

public java.lang.String getPath()
Returns full prefetch path, that is a dot separated String of node names starting from root and up to and including this node. Note that root "name" is considered to be an empty string.


getPath

public java.lang.String getPath(PrefetchTreeNode upTillParent)

adjacentJointNodes

public java.util.Collection adjacentJointNodes()
Returns a subset of nodes with "joint" semantics that are to be prefetched in the same query as the current node. Result excludes this node, regardless of its semantics.


jointNodes

public java.util.Collection jointNodes()
Returns a collection of PrefetchTreeNodes in this tree with joint semantics.


disjointNodes

public java.util.Collection disjointNodes()
Returns a collection of PrefetchTreeNodes with disjoint semantics.


nonPhantomNodes

public java.util.Collection nonPhantomNodes()
Returns a collection of PrefetchTreeNodes that are not phantoms.


traverse

public void traverse(PrefetchProcessor processor)
Traverses the tree depth-first, invoking callback methods of the processor when passing through the nodes.


getNode

public PrefetchTreeNode getNode(java.lang.String path)
Looks up an existing node in the tree desribed by the dot-separated path. Will return null if no matching child exists.


addPath

public PrefetchTreeNode addPath(java.lang.String path)
Adds a "path" with specified semantics to this prefetch node. All yet non-existent nodes in the created path will be marked as phantom.

Returns:
the last segment in the created path.

removePath

public void removePath(java.lang.String path)
Removes or makes phantom a node defined by this path. If the node for this path doesn't have any children, it is removed, otherwise it is made phantom.


addChild

public void addChild(PrefetchTreeNode child)

removeChild

public void removeChild(PrefetchTreeNode child)

removeChild

protected void removeChild(java.lang.String segment)

getChild

protected PrefetchTreeNode getChild(java.lang.String segment)

getParent

public PrefetchTreeNode getParent()

getChildren

public java.util.Collection getChildren()
Returns an unmodifiable collection of children.


hasChildren

public boolean hasChildren()

getName

public java.lang.String getName()

isPhantom

public boolean isPhantom()

setPhantom

public void setPhantom(boolean phantom)

getSemantics

public int getSemantics()

setSemantics

public void setSemantics(int semantics)

isJointPrefetch

public boolean isJointPrefetch()

isDisjointPrefetch

public boolean isDisjointPrefetch()


Copyright © 2001-2006 Apache.org All Rights Reserved.