Class HierarchyCache

Description

This class provides a mechanism for caching different parts of a hierarchy and

acts as an interface between the datastructures and the database. A single instance of this class will be included with a single

  1. Hierarchy
object and all its
  1. Node
objects.

The class maintains a single

  1. Tree
object called
  1. tree
that will store the parts of the hierarchy already cached. In addition, there is a special array called
  1. cache
. Given an id of a cached node, this array enables us to determine whether any of the node's inheritors or ancestors have been cached as well. In specific, each element of the array corresponds to a unique node (each index of the array is a node id) and is another array storing one
  1. Node
object and two integer values. If any of the integer values is positive, then that means that we have information about the cache status of the node's immediate ancestors or inheritors. Specifically, the two integer values determine the amount of caching, i.e. the first integer specifies the number of tree levels cached down the node, and the second integer specifies the number of tree levels cached up the node. If any of these values is negative then that means that the caching extends all the way up or down. If any of the two values is zero, then nothing has been cached in the corresponding direction.

Caching occurs when the user calls the accessor methods of the

  1. Hierarchy
class, i.e.
  1. traverse()
,
  1. getChildren()
or
  1. getParents()
.

  • version: $Id: HierarchyCache.class.php,v 1.39 2007/09/17 16:44:35 adamfranco Exp $
  • license: GNU General Public License (GPL)
  • copyright: Copyright © 2005, Middlebury College

Located in /harmoni/core/oki2/hierarchy/HierarchyCache.class.php (line 39)


	
			
Variable Summary
array $_cache
integer $_dbIndex
string $_hierarchyId
array $_infoCache
object _nodeQuery $_nodeQuery
object _tree $_tree
Method Summary
HierarchyCache HierarchyCache (mixed $hierarchyId, integer $allowsMultipleParents, mixed $dbIndex, object DateAndTime $lastStructureUpdate)
void addParent (mixed $parentIdValue, mixed $childIdValue)
void clearCache ()
void clearNodeAncestory (string $idString)
void createNode (object nodeId $nodeId, object parentId $parentId, object type $type, string $displayName, string $description)
void createRootNode (object nodeId $nodeId, object type $type, string $displayName, string $description)
void deleteNode (mixed $idValue)
ref getAllNodes ()
ref getChildren (object node $node)
object Id getHierarchyId ()
mixed getNode (mixed $idValue)
ref getNodesFromDB (string $where)
ref getParents (object node $node)
ref getRootNodes ()
boolean isLeaf (object node $node)
boolean nodeExists (mixed $idValue)
void rebuildNodeAncestory (object Id $id)
void rebuildSubtreeAncestory (object Id $id)
void removeParent (mixed $parentIdValue, mixed $childIdValue)
ref traverse (object id $id, boolean $down, integer $levels)
boolean _isCached (mixed $idValue)
boolean _isCachedDown (mixed $idValue, integer $levels)
boolean _isCachedUp (mixed $idValue, integer $levels)
void _traverseDown (string $idValue, integer $levels)
void _traverseUp (string $idValue, integer $levels)
void _traverseUpAncestory (string $idValue, integer $levels)
Variables
boolean $_allowsMultipleParents (line 102)

This is true if the hierarchy will allow multiple parents.

  • var: _allowsMultipleParents
  • access: private
array $_cache (line 67)

Given an id of a cached node,

this array enables us to determine whether any of the node's inheritors or ancestors have been cached as well. In specific, each element of the array corresponds to a unique node (each index of the array is a node id) and is another array storing one

  1. Node
object and two integer values. If any of the integer values is positive, then that means that we have information about the cache status of the node's immediate ancestors or inheritors. Specifically, the two integer values determine the amount of caching, i.e. the first integer specifies the number of tree levels cached down the node, and the second integer specifies the number of tree levels cached up the node. If any of these values is negative then that means that the caching extends all the way down or up. If any of the two values is zero, then nothing has been cached in the corresponding direction.

  • var: _cache
  • access: protected
integer $_dbIndex (line 75)

The database connection as returned by the DBHandler.

  • var: _dbIndex
  • access: protected
string $_hierarchyId (line 84)

The id of the hierarchy.

  • var: _$hierarchyId
  • access: protected
array $_infoCache (line 112)

A cache of the created traversalInfoObjects. Intended to help solve some of the memory blowup in Concerto. Checking 20 AZs on about 25 Assets in Concerto was traversing such that ~100,000 HarmoniTraversalInfo objects were being created.

  • var: _infoCache
  • since: 3/28/05
  • access: private
object _nodeQuery $_nodeQuery (line 93)

This is a SELECT query that we will often use to get one single node from the database.

  • access: protected
object _tree $_tree (line 48)

This is the

  1. Tree
object that will store the cached portions of the hierarchy.

  • access: protected
Methods
Constructor HierarchyCache (line 121)

Constructor

  • access: protected
HierarchyCache HierarchyCache (mixed $hierarchyId, integer $allowsMultipleParents, mixed $dbIndex, object DateAndTime $lastStructureUpdate)
  • object DateAndTime $lastStructureUpdate
  • mixed $hierarchyId: hierarchyId The id of the corresponding hierarchy.
  • integer $allowsMultipleParents: dbIndex The database connection as returned by the DBHandler.
addParent (line 244)

Makes the first node the parent of the second node.

  • access: public
void addParent (mixed $parentIdValue, mixed $childIdValue)
  • mixed $parentIdValue: parentIdValue The string id of the node to add as a parent.
  • mixed $childIdValue: childIdValue The string id of the child node.
clearCache (line 1745)

Clears the cache.

  • access: public
void clearCache ()
clearNodeAncestory (line 1861)

Clear the ancestory rows for a given node

  • since: 11/4/05
  • access: public
void clearNodeAncestory (string $idString)
  • string $idString
createNode (line 1638)

Attempts to create the specified node in the database and adds the specified parent.

  • access: public
void createNode (object nodeId $nodeId, object parentId $parentId, object type $type, string $displayName, string $description)
  • object nodeId $nodeId: The id of the node.
  • object parentId $parentId: The id of the parent.
  • object type $type: The type of the node.
  • string $displayName: displayName The display name of the node.
  • string $description: description The description of the node.
createRootNode (line 1523)

Attempts to create the specified node as root node in the database.

  • access: public
void createRootNode (object nodeId $nodeId, object type $type, string $displayName, string $description)
  • object nodeId $nodeId: The id of the node.
  • object type $type: The type of the node.
  • string $displayName: displayName The display name of the node.
  • string $description: description The description of the node.
deleteNode (line 1654)

Attempts to delete the specified node in the database. Only leaf nodes can be deleted.

  • access: public
void deleteNode (mixed $idValue)
  • mixed $idValue: idValue The string id of the node to delete.
getAllNodes (line 451)

Returns an array of all nodes in this hierarchy.

  • return: array An array of all nodes in this hierarchy.
  • access: public
ref getAllNodes ()
getChildren (line 807)

Caches the children (if not cached already) of the given node by fecthing them from the database if neccessary, and then inserting them in

  1. _tree
and updating
  1. _cache
.

  • return: array An array of the children nodes of the given node.
  • access: public
ref getChildren (object node $node)
  • object node $node: The node object whose children we must cache.
getHierarchyId (line 163)

Answer the Id of the hierarchy

  • since: 12/20/05
  • access: public
object Id getHierarchyId ()
getNode (line 596)

Returns (and caches if necessary) the node with the specified string id.

  • return: The corresponding
    1. Node
    object.
  • access: public
mixed getNode (mixed $idValue)
  • mixed $idValue: idValue The string id of the node.
getNodesFromDB (line 407)

Gets node(s) from the database that match the criteria specified by the given where condition.

  • return: object An array of HarmoniNode objects.
  • access: public
ref getNodesFromDB (string $where)
  • string $where: where The where condition that will be used to determine which nodes to return.
getParents (line 690)

Caches the parents (if not cached already) of the given node by fecthing them from the database if neccessary, and then inserting them in

  1. _tree
and updating
  1. _cache
.

  • return: array An array of the parent nodes of the given node.
  • access: public
ref getParents (object node $node)
  • object node $node: The node object whose parents we must cache.
getRootNodes (line 537)

Returns an array of all root nodes in this hierarchy.

  • return: array An array of all root nodes in this hierarchy.
  • access: public
ref getRootNodes ()
isLeaf (line 917)

Return true if the node is a leaf

  • access: public
boolean isLeaf (object node $node)
  • object node $node: The node object to check.
nodeExists (line 643)

Returns true if the node specified by the idString exists. The node is cached for future access if it is found

  • access: public
boolean nodeExists (mixed $idValue)
  • mixed $idValue: idValue The string id of the node.
rebuildNodeAncestory (line 1762)

Build the ancestory rows for a given node

  • since: 11/4/05
  • access: public
void rebuildNodeAncestory (object Id $id)
  • object Id $id
rebuildSubtreeAncestory (line 1832)

Build the ancestory rows for a node and its decendents

  • since: 11/4/05
  • access: public
void rebuildSubtreeAncestory (object Id $id)
  • object Id $id
removeParent (line 345)

Removes the first node from the list of parents of the second node.

  • access: public
void removeParent (mixed $parentIdValue, mixed $childIdValue)
  • mixed $parentIdValue: parentIdValue The string id of the node to to remove as a parent.
  • mixed $childIdValue: childIdValue The string id of the child node.
traverse (line 974)

Performs a depth-first pre-order traversal. It either returns the previously cached nodes or fetches them from the database and then caches them (depending on whtether they had been already cached).

  • return: array An array of all nodes in the tree visited in a pre-order manner.
  • access: public
ref traverse (object id $id, boolean $down, integer $levels)
  • object id $id: The id of the node where to start traversal from.
  • boolean $down: down If
    1. true
    , this argument specifies that the traversal will go down the children; if
    1. false
    then it will go up the parents.
  • integer $levels: levels Specifies how many levels of nodes to traverse. If this is negative then the traversal will go on until the last level is processed.
_isCached (line 232)

Returns

  1. true
if the node with the specified string id has been cached.

  • return:
    1. true
    if the with the specified string id has been cached.
  • access: private
boolean _isCached (mixed $idValue)
  • mixed $idValue: idValue The string id of the node.
_isCachedDown (line 178)

Determines whether a node has been cached down

  • return: If
    1. true
    then
    1. levels
    number of levels have been cached down.
  • access: private
  • see: HierarchyCache::_cache
boolean _isCachedDown (mixed $idValue, integer $levels)
  • mixed $idValue: idValue The string id of the node.
  • integer $levels: levels The number of tree levels down to check for caching. If negative, then cached all the way down.
_isCachedUp (line 206)

Determines whether a node has been cached up

  • return: If
    1. true
    then
    1. levels
    number of levels have been cached up.
  • access: private
  • see: HierarchyCache::_cache
boolean _isCachedUp (mixed $idValue, integer $levels)
  • mixed $idValue: idValue The string id of the node.
  • integer $levels: levels The number of tree levels up to check for caching. If negative, then cached all the way up.
_traverseDown (line 1049)

Traverses down and caches whatever needs to be cached.

  • access: public
void _traverseDown (string $idValue, integer $levels)
  • string $idValue: idValue The string id of the node to start traversal from.
  • integer $levels: levels Specifies how many levels of nodes to traverse. If this is negative then the traversal will go on until the last level is processed.
_traverseUp (line 1361)

Traverses up and caches whatever needs to be cached.

  • access: public
void _traverseUp (string $idValue, integer $levels)
  • string $idValue: idValue The string id of the node to start traversal from.
  • integer $levels: levels Specifies how many levels of nodes to traverse. If this is negative then the traversal will go on until the last level is processed.
_traverseUpAncestory (line 1216)

Traverses up the ancestory table and caches whatever needs to be cached.

  • access: public
void _traverseUpAncestory (string $idValue, integer $levels)
  • string $idValue: idValue The string id of the node to start traversal from.
  • integer $levels: levels Specifies how many levels of nodes to traverse. If this is negative then the traversal will go on until the last level is processed.

Documentation generated on Wed, 19 Sep 2007 10:24:31 -0400 by phpDocumentor 1.3.0RC3