Author: dr
Date: Fri Aug 10 11:59:07 2007
New Revision: 5869
Log:
- Move prefetching to be an attribute of the node list iterator only.
- Having prefetching on the tree makes things way to undeterministic and thus
confusing. It also only really makes sense for node lists anyway.
I will add a method to ezcTreeNodeList to fetch all the data for those
nodes without having to use the ezcTreeNodeListIterator soon.
Modified:
trunk/Tree/src/tree.php
trunk/Tree/src/tree_node.php
trunk/Tree/src/tree_node_list_iterator.php
trunk/Tree/src/visitors/visualization.php
trunk/Tree/tests/tree.php
trunk/Tree/tests/tree_node.php
trunk/TreeDatabaseTiein/tests/db_tree.php
trunk/TreePersistentObjectTiein/tests/po_store.php
Modified: trunk/Tree/src/tree.php
==============================================================================
--- trunk/Tree/src/tree.php [iso-8859-1] (original)
+++ trunk/Tree/src/tree.php [iso-8859-1] Fri Aug 10 11:59:07 2007
@@ -13,8 +13,6 @@
*
* @property-read ezcTreeXmlDataStore $store
* The data store that is used for retrieving/storing data.
- * @property bool $prefetch
- * Whether data pre-fetching is enabled.
* @property string $nodeClassName
* Which class is used as tree node - this class *must* inherit
* the ezcTreeNode class.
@@ -29,7 +27,7 @@
*
* @var array(string=>mixed)
*/
- protected $properties = array( 'prefetch' => false, 'nodeClassName' =>
'ezcTreeNode' );
+ protected $properties = array( 'nodeClassName' => 'ezcTreeNode' );
/**
* Contains whether a transaction has been started.
@@ -65,7 +63,6 @@
{
case 'store':
case 'nodeClassName':
- case 'prefetch':
return $this->properties[$name];
}
throw new ezcBasePropertyNotFoundException( $name );
@@ -111,14 +108,6 @@
$this->properties[$name] = $value;
break;
- case 'prefetch':
- if ( !is_bool( $value ) )
- {
- throw new ezcBaseValueException( $name, $value, 'boolean'
);
- }
- $this->properties[$name] = $value;
- break;
-
default:
throw new ezcBasePropertyNotFoundException( $name );
}
@@ -177,11 +166,6 @@
$className = $this->properties['nodeClassName'];
$node = new $className( $this, $nodeId );
- // Obtain data from the store if prefetch is enabled
- if ( $this->prefetch )
- {
- $this->properties['store']->fetchDataForNode( $node );
- }
return $node;
}
Modified: trunk/Tree/src/tree_node.php
==============================================================================
--- trunk/Tree/src/tree_node.php [iso-8859-1] (original)
+++ trunk/Tree/src/tree_node.php [iso-8859-1] Fri Aug 10 11:59:07 2007
@@ -54,11 +54,6 @@
$this->properties['data'] = null;
$this->properties['dataFetched'] = false;
$this->properties['dataStored'] = true;
-
- if ( $tree->prefetch )
- {
- $tree->store->fetchDataForNode( $this );
- }
}
else
{
Modified: trunk/Tree/src/tree_node_list_iterator.php
==============================================================================
--- trunk/Tree/src/tree_node_list_iterator.php [iso-8859-1] (original)
+++ trunk/Tree/src/tree_node_list_iterator.php [iso-8859-1] Fri Aug 10 11:59:07
2007
@@ -9,6 +9,43 @@
/**
* ezcTreeNodeListIterator implements an iterator over a ezcTreeNodeList
+ *
+ * The iterator is instantiated with both an implementation ezcTree and
+ * a ezcTreeNodeList object. It can be used to iterate over all the nodes
+ * in a list.
+ *
+ * Example:
+ * <code>
+ * <?php
+ * // fetch all the nodes in a subtree as an ezcNodeList
+ * $nodeList = $tree->fetchSubtree( 'pan' );
+ * foreach ( new ezcTreeNodeListIterator( $tree, $nodeList ) as $nodeId =>
$data )
+ * {
+ * // do something with the node ID and data - data is fetched on
+ * // demand
+ * }
+ * ?>
+ * </code>
+ *
+ * Data for the nodes in the node lists is fetched on demand, unless
+ * the "prefetch" argument is set to true. In that case the iterator will
+ * fetch the data when the iterator is instantiated. This reduces the number
+ * of queries made for database and persistent object based data stores, but
+ * increases memory usage.
+ *
+ * Example:
+ * <code>
+ * <?php
+ * // fetch all the nodes in a subtree as an ezcNodeList
+ * $nodeList = $tree->fetchSubtree( 'Uranus' );
+ * // instantiate an iterator with pre-fetching enabled
+ * foreach ( new ezcTreeNodeListIterator( $tree, $nodeList, true ) as
$nodeId => $data )
+ * {
+ * // do something with the node ID and data - data is fetched when
+ * // the iterator is instatiated.
+ * }
+ * ?>
+ * </code>
*
* @package Tree
* @version //autogentag//
@@ -40,11 +77,12 @@
*
* @param ezcTree $tree
* @param ezcTreeNodeList $nodeList
+ * @param bool $prefetch
*/
- public function __construct( ezcTree $tree, ezcTreeNodeList $nodeList )
+ public function __construct( ezcTree $tree, ezcTreeNodeList $nodeList,
$prefetch = false )
{
$this->tree = $tree;
- if ( $tree->prefetch )
+ if ( $prefetch )
{
$this->tree->store->fetchDataForNodes( $nodeList );
}
Modified: trunk/Tree/src/visitors/visualization.php
==============================================================================
--- trunk/Tree/src/visitors/visualization.php [iso-8859-1] (original)
+++ trunk/Tree/src/visitors/visualization.php [iso-8859-1] Fri Aug 10 11:59:07
2007
@@ -9,13 +9,15 @@
*/
/**
- * An implementation of the ezcTreeVisitor interface that
- * generates GraphViz/dot markup for a tree structure.
+ * An implementation of the ezcTreeVisitor interface that generates
+ * GraphViz/dot markup for a tree structure.
*
* <code>
- * $visitor = new ezcTreeVisitorVisualization;
- * $tree->accept( $visitor );
- * echo (string)$visitor; // print the plot
+ * <?php
+ * $visitor = new ezcTreeVisitorVisualization;
+ * $tree->accept( $visitor );
+ * echo (string) $visitor; // print the plot
+ * ?>
* </code>
*
* @package Tree
Modified: trunk/Tree/tests/tree.php
==============================================================================
--- trunk/Tree/tests/tree.php [iso-8859-1] (original)
+++ trunk/Tree/tests/tree.php [iso-8859-1] Fri Aug 10 11:59:07 2007
@@ -80,32 +80,6 @@
catch ( ezcBasePropertyPermissionException $e )
{
self::assertSame( "The property 'store' is read-only.",
$e->getMessage() );
- }
- }
-
- public function testSetPrefetch()
- {
- $tree = $this->setUpTestTree();
-
- $tree->prefetch = true;
- self::assertSame( true, $tree->prefetch );
-
- $tree->prefetch = false;
- self::assertSame( false, $tree->prefetch );
- }
-
- public function testSetPrefetchWrongValue()
- {
- $tree = $this->setUpTestTree();
-
- try
- {
- $tree->prefetch = 42;
- self::fail( "Expected exception not thrown" );
- }
- catch ( ezcBaseValueException $e )
- {
- self::assertSame( "The value '42' that you were trying to assign
to setting 'prefetch' is invalid. Allowed values are: boolean.",
$e->getMessage() );
}
}
@@ -758,35 +732,9 @@
self::assertSame( 4, $nodeList->size );
self::assertSame( 'Node 4', $nodeList['4']->data );
- $tree->prefetch = true;
- foreach ( new ezcTreeNodeListIterator( $tree, $nodeList ) as $nodeId
=> $data )
+ foreach ( new ezcTreeNodeListIterator( $tree, $nodeList, true ) as
$nodeId => $data )
{
self::assertSame( "Node $nodeId", $data );
- }
- }
-
- public function testPrefetchData()
- {
- $tree = $this->setUpTestTree();
-
- // the memory backend has prefetching always enabled
- if ( get_class( $this ) !== 'ezcTreeMemoryTest' )
- {
- $nodeList = $tree->fetchNodeById( 4 )->fetchSubtree();
- self::assertSame( 4, $nodeList->size );
- foreach ( $nodeList->getNodes() as $node )
- {
- self::assertSame( false, $node->dataFetched );
- }
-
- $tree->prefetch = true;
- }
-
- $nodeList = $tree->fetchNodeById( 4 )->fetchSubtree();
- self::assertSame( 4, $nodeList->size );
- foreach ( $nodeList->getNodes() as $node )
- {
- self::assertSame( true, $node->dataFetched );
}
}
Modified: trunk/Tree/tests/tree_node.php
==============================================================================
--- trunk/Tree/tests/tree_node.php [iso-8859-1] (original)
+++ trunk/Tree/tests/tree_node.php [iso-8859-1] Fri Aug 10 11:59:07 2007
@@ -129,17 +129,6 @@
self::assertSame( true, $node->dataFetched );
}
- public function testPrefetch()
- {
- $tree = ezcTreeMemory::create( new TestTranslateDataStore() );
- $tree->prefetch = true;
- $node = new ezcTreeNode( $tree, 'Al' );
- self::assertSame( 'Al', $node->id );
- self::assertSame( true, $node->dataFetched );
- self::assertSame( 'Aluminium', $node->data );
- self::assertSame( true, $node->dataFetched );
- }
-
public function testSetDataFetchedNotBool()
{
$node = new ezcTreeNode( $this->tree, 'Si', 'Silicon' );
Modified: trunk/TreeDatabaseTiein/tests/db_tree.php
==============================================================================
--- trunk/TreeDatabaseTiein/tests/db_tree.php [iso-8859-1] (original)
+++ trunk/TreeDatabaseTiein/tests/db_tree.php [iso-8859-1] Fri Aug 10 11:59:07
2007
@@ -155,9 +155,8 @@
$nodeList = $tree->fetchSubtree( '3' );
- $tree->prefetch = true;
$expected = "something's wrong";
- foreach ( new ezcTreeNodeListIterator( $tree, $nodeList ) as $id =>
$data )
+ foreach ( new ezcTreeNodeListIterator( $tree, $nodeList, true ) as $id
=> $data )
{
switch ( $id )
{
Modified: trunk/TreePersistentObjectTiein/tests/po_store.php
==============================================================================
--- trunk/TreePersistentObjectTiein/tests/po_store.php [iso-8859-1] (original)
+++ trunk/TreePersistentObjectTiein/tests/po_store.php [iso-8859-1] Fri Aug 10
11:59:07 2007
@@ -208,8 +208,7 @@
$tree = $this->setUpTestTree();
$list = $tree->fetchSubtree( '1' );
- $tree->prefetch = true;
- foreach ( new ezcTreeNodeListIterator( $tree, $list ) as $elem )
+ foreach ( new ezcTreeNodeListIterator( $tree, $list, $tree ) as $elem )
{
}
self::assertSame( '/boot/httpd/pw-admin', $elem->name );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components