cvs: pecl(BRANCH_1_0_5) /sdo/DAS Relational.php /sdo/DAS/Relational ContainmentReferencesModel.php ObjectModel.php
| From: | Simon Laws | Date: | Thu, 09 Nov 2006 13:40:19 +0000 |
| Subject: | cvs: pecl(BRANCH_1_0_5) /sdo/DAS Relational.php /sdo/DAS/Relational ContainmentReferencesModel.php ObjectModel.php | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-6619@lists.php.net to get a copy of this message | ||
slaws Thu Nov 9 13:40:19 2006 UTC
Modified files: (Branch: BRANCH_1_0_5)
/pecl/sdo/DAS Relational.php
/pecl/sdo/DAS/Relational ObjectModel.php
ContainmentReferencesModel.php
Log:
Allow for more than one data object at the top level. PECL #9289
http://cvs.php.net/viewvc.cgi/pecl/sdo/DAS/Relational.php?r1=1.12&r2=1.12.4.1&diff_format=u Index: pecl/sdo/DAS/Relational.php diff -u pecl/sdo/DAS/Relational.php:1.12 pecl/sdo/DAS/Relational.php:1.12.4.1 --- pecl/sdo/DAS/Relational.php:1.12 Thu Sep 28 19:23:49 2006 +++ pecl/sdo/DAS/Relational.php Thu Nov 9 13:40:19 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: Relational.php,v 1.12 2006/09/28 19:23:49 cem Exp $ +$Id: Relational.php,v 1.12.4.1 2006/11/09 13:40:19 slaws Exp $ */ require_once 'SDO/DAS/Relational/Exception.php'; @@ -75,6 +75,7 @@ $containment_references_metadata = array(); } $this->database_model = new SDO_DAS_Relational_DatabaseModel($database_metadata); +/* if ($application_root_type == null) { $all_tables_names = $this->database_model->getAllTableNames(); if (count($all_tables_names) == 1) { @@ -83,11 +84,12 @@ throw new SDO_DAS_Relational_Exception('Application root type (second argument to constructor) can only be null when there is exactly one table in the database metadata'); } } - $this->application_root_type = $application_root_type; - $this->containment_references_model = new SDO_DAS_Relational_ContainmentReferencesModel($application_root_type, $containment_references_metadata); - $this->object_model = new SDO_DAS_Relational_ObjectModel($this->database_model, $this->containment_references_model); - $this->data_factory = SDO_DAS_DataFactory::getDataFactory(); - $this->object_model -> defineToSDO($this->data_factory); +*/ + $this->application_root_type = $application_root_type; + $this->containment_references_model = new SDO_DAS_Relational_ContainmentReferencesModel($application_root_type, $containment_references_metadata, $this->database_model); + $this->object_model = new SDO_DAS_Relational_ObjectModel($this->database_model, $this->containment_references_model); + $this->data_factory = SDO_DAS_DataFactory::getDataFactory(); + $this->object_model->defineToSDO($this->data_factory); } /** @@ -174,7 +176,9 @@ $root = self::createRoot($this->data_factory); $table_names = $this->database_model->getAllTableNames(); //TODO make sure they come back in graph order - assert($table_names[0] == $this->application_root_type); + if ( $this->application_root_type ) { + assert($table_names[0] == $this->application_root_type); + } $key_object_map = new SDO_DAS_Relational_KeyObjectMap(); if ($all_rows) { $all_later_updates = array(); http://cvs.php.net/viewvc.cgi/pecl/sdo/DAS/Relational/ObjectModel.php?r1=1.6&r2=1.6.4.1&diff_format=u Index: pecl/sdo/DAS/Relational/ObjectModel.php diff -u pecl/sdo/DAS/Relational/ObjectModel.php:1.6 pecl/sdo/DAS/Relational/ObjectModel.php:1.6.4.1 --- pecl/sdo/DAS/Relational/ObjectModel.php:1.6 Thu Sep 28 19:23:52 2006 +++ pecl/sdo/DAS/Relational/ObjectModel.php Thu Nov 9 13:40:19 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: ObjectModel.php,v 1.6 2006/09/28 19:23:52 cem Exp $ +$Id: ObjectModel.php,v 1.6.4.1 2006/11/09 13:40:19 slaws Exp $ */ /** @@ -143,7 +143,8 @@ private function ensureTheApplicationRootTypeIsAValidTable() { $app_root_type = $this->containment_references_model->getApplicationRootType(); - if (!$this->database_model->isValidTableName($app_root_type)) { + if ( $app_root_type && + !$this->database_model->isValidTableName($app_root_type)) { throw new SDO_DAS_Relational_Exception('Application root type ' . $app_root_type . ' does not appear as a table name in the database metadata'); } } @@ -180,8 +181,10 @@ echo "Building SDO model as follows:\n"; } $this->defineTheRootTypeToSDO($data_factory); - $this->addAllTheActiveTypesToSDO($data_factory); - $this->addTopLevelContainmentPropertyToSDO($data_factory); + //$this->addAllTheActiveTypesToSDO($data_factory); + $this->addAllTypesToSDO($data_factory); + //$this->addTopLevelContainmentPropertyToSDO($data_factory); + $this->addTopLevelContainmentPropertiesToSDO($data_factory); $this->addAllTheColumnsAsPropertiesToSDO($data_factory); } @@ -206,6 +209,17 @@ } } + private function addAllTypesToSDO($data_factory) + { + $all_types = $this->database_model->getAllTableNames(); + foreach ($all_types as $type) { + if (SDO_DAS_Relational::DEBUG_BUILD_SDO_MODEL) { + echo "adding type $type\n"; + } + $data_factory->addType(SDO_DAS_Relational::APP_NAMESPACE, $type); + } + } + private function addTopLevelContainmentPropertyToSDO($data_factory) { $app_root_type = $this->containment_references_model->getApplicationRootType(); @@ -219,6 +233,23 @@ array('many' => true, 'containment' => true)); } + private function addTopLevelContainmentPropertiesToSDO($data_factory) + { + $non_contained_types = $this->containment_references_model->getAllNonContainedTypes(); + + foreach ( $non_contained_types as $type ) { + if (SDO_DAS_Relational::DEBUG_BUILD_SDO_MODEL) { + echo "adding containment property $type to hidden root type\n"; + } + + $data_factory->addPropertyToType( + SDO_DAS_Relational::DAS_NAMESPACE, SDO_DAS_Relational::DAS_ROOT_TYPE, + $type, + SDO_DAS_Relational::APP_NAMESPACE, $type, + array('many' => true, 'containment' => true)); + } + } + private function addAllTheColumnsAsPropertiesToSDO($data_factory) { ////////////////////////////////////////////////////////////////////////// @@ -258,7 +289,7 @@ // end for each this column // end for each active type ////////////////////////////////////////////////////////////////////////// - $active_types = $this->containment_references_model->getActiveTypes(); + $active_types = $this->containment_references_model->getActiveTypes(); foreach ($active_types as $type) { $table = $this->database_model->getTableByName($type); $columns = $table->getColumns(); http://cvs.php.net/viewvc.cgi/pecl/sdo/DAS/Relational/ContainmentReferencesModel.php?r1=1.4&r2=1.4.4.1&diff_format=u Index: pecl/sdo/DAS/Relational/ContainmentReferencesModel.php diff -u pecl/sdo/DAS/Relational/ContainmentReferencesModel.php:1.4 pecl/sdo/DAS/Relational/ContainmentReferencesModel.php:1.4.4.1 --- pecl/sdo/DAS/Relational/ContainmentReferencesModel.php:1.4 Thu Sep 28 19:23:52 2006 +++ pecl/sdo/DAS/Relational/ContainmentReferencesModel.php Thu Nov 9 13:40:19 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: ContainmentReferencesModel.php,v 1.4 2006/09/28 19:23:52 cem Exp $ +$Id: ContainmentReferencesModel.php,v 1.4.4.1 2006/11/09 13:40:19 slaws Exp $ */ require_once 'SDO/DAS/Relational/ContainmentReference.php'; @@ -48,20 +48,34 @@ private $active_containment_references = array(); // Only those reachable from app_root_type private $active_types; // potentially a subset of the full set of types - just those reachable from root private $app_root_type; + private $database_model; - public function __construct($app_root_type, $containment_references_metadata) + public function __construct($app_root_type, $containment_references_metadata, $database_model) { - assert(gettype($app_root_type) == 'string'); + if ( $app_root_type != null ) { + assert(gettype($app_root_type) == 'string'); + } + assert(gettype($containment_references_metadata) == 'array'); - $this->app_root_type = $app_root_type; + $this->app_root_type = $app_root_type; + $this->database_model = $database_model; foreach ($containment_references_metadata as $cref) { $this->full_set_containment_references[] = new SDO_DAS_Relational_ContainmentReference($cref); } $reachable_types_already_visited = array(); - $reachable_types_still_to_check = array($app_root_type); + + // maintain app_root_type here for backward compatibility + if ( $app_root_type != null ) { + $reachable_types_still_to_check = array($app_root_type); + } else { + // we need to check all the types and find all of the ones for which no + // containment references are specified + $reachable_types_still_to_check = $this->getAllNonContainedTypes(); + } + $references_traversed = array(); while (count($reachable_types_still_to_check) > 0) { $type = array_shift($reachable_types_still_to_check); @@ -79,6 +93,7 @@ $this->active_types = $reachable_types_already_visited; $this->active_containment_references = $references_traversed; } + public function getActiveContainmentReferences() { @@ -130,6 +145,30 @@ } return null; } + + public function getAllNonContainedTypes() + { + $non_contained_types = array(); + $all_types = $this->database_model->getAllTableNames(); + + // loop through all the types. If a type name doesn't appear + // as a child in the containment meta-data then the type + // is non contained + foreach ( $all_types as $type ) { + $contained = false; + foreach ( $this->full_set_containment_references as $ref ) { + if ( $ref->getChildName() == $type ) { + $contained = true; + break; + } + } + if ( $contained == false ) { + $non_contained_types[] = $type; + } + } + + return $non_contained_types; + } } ?> \ No newline at end of file
http://cvs.php.net/viewvc.cgi/pecl/sdo/DAS/Relational.php?r1=1.12&r2=1.12.4.1&diff_format=u Index: pecl/sdo/DAS/Relational.php diff -u pecl/sdo/DAS/Relational.php:1.12 pecl/sdo/DAS/Relational.php:1.12.4.1 --- pecl/sdo/DAS/Relational.php:1.12 Thu Sep 28 19:23:49 2006 +++ pecl/sdo/DAS/Relational.php Thu Nov 9 13:40:19 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: Relational.php,v 1.12 2006/09/28 19:23:49 cem Exp $ +$Id: Relational.php,v 1.12.4.1 2006/11/09 13:40:19 slaws Exp $ */ require_once 'SDO/DAS/Relational/Exception.php'; @@ -75,6 +75,7 @@ $containment_references_metadata = array(); } $this->database_model = new SDO_DAS_Relational_DatabaseModel($database_metadata); +/* if ($application_root_type == null) { $all_tables_names = $this->database_model->getAllTableNames(); if (count($all_tables_names) == 1) { @@ -83,11 +84,12 @@ throw new SDO_DAS_Relational_Exception('Application root type (second argument to constructor) can only be null when there is exactly one table in the database metadata'); } } - $this->application_root_type = $application_root_type; - $this->containment_references_model = new SDO_DAS_Relational_ContainmentReferencesModel($application_root_type, $containment_references_metadata); - $this->object_model = new SDO_DAS_Relational_ObjectModel($this->database_model, $this->containment_references_model); - $this->data_factory = SDO_DAS_DataFactory::getDataFactory(); - $this->object_model -> defineToSDO($this->data_factory); +*/ + $this->application_root_type = $application_root_type; + $this->containment_references_model = new SDO_DAS_Relational_ContainmentReferencesModel($application_root_type, $containment_references_metadata, $this->database_model); + $this->object_model = new SDO_DAS_Relational_ObjectModel($this->database_model, $this->containment_references_model); + $this->data_factory = SDO_DAS_DataFactory::getDataFactory(); + $this->object_model->defineToSDO($this->data_factory); } /** @@ -174,7 +176,9 @@ $root = self::createRoot($this->data_factory); $table_names = $this->database_model->getAllTableNames(); //TODO make sure they come back in graph order - assert($table_names[0] == $this->application_root_type); + if ( $this->application_root_type ) { + assert($table_names[0] == $this->application_root_type); + } $key_object_map = new SDO_DAS_Relational_KeyObjectMap(); if ($all_rows) { $all_later_updates = array(); http://cvs.php.net/viewvc.cgi/pecl/sdo/DAS/Relational/ObjectModel.php?r1=1.6&r2=1.6.4.1&diff_format=u Index: pecl/sdo/DAS/Relational/ObjectModel.php diff -u pecl/sdo/DAS/Relational/ObjectModel.php:1.6 pecl/sdo/DAS/Relational/ObjectModel.php:1.6.4.1 --- pecl/sdo/DAS/Relational/ObjectModel.php:1.6 Thu Sep 28 19:23:52 2006 +++ pecl/sdo/DAS/Relational/ObjectModel.php Thu Nov 9 13:40:19 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: ObjectModel.php,v 1.6 2006/09/28 19:23:52 cem Exp $ +$Id: ObjectModel.php,v 1.6.4.1 2006/11/09 13:40:19 slaws Exp $ */ /** @@ -143,7 +143,8 @@ private function ensureTheApplicationRootTypeIsAValidTable() { $app_root_type = $this->containment_references_model->getApplicationRootType(); - if (!$this->database_model->isValidTableName($app_root_type)) { + if ( $app_root_type && + !$this->database_model->isValidTableName($app_root_type)) { throw new SDO_DAS_Relational_Exception('Application root type ' . $app_root_type . ' does not appear as a table name in the database metadata'); } } @@ -180,8 +181,10 @@ echo "Building SDO model as follows:\n"; } $this->defineTheRootTypeToSDO($data_factory); - $this->addAllTheActiveTypesToSDO($data_factory); - $this->addTopLevelContainmentPropertyToSDO($data_factory); + //$this->addAllTheActiveTypesToSDO($data_factory); + $this->addAllTypesToSDO($data_factory); + //$this->addTopLevelContainmentPropertyToSDO($data_factory); + $this->addTopLevelContainmentPropertiesToSDO($data_factory); $this->addAllTheColumnsAsPropertiesToSDO($data_factory); } @@ -206,6 +209,17 @@ } } + private function addAllTypesToSDO($data_factory) + { + $all_types = $this->database_model->getAllTableNames(); + foreach ($all_types as $type) { + if (SDO_DAS_Relational::DEBUG_BUILD_SDO_MODEL) { + echo "adding type $type\n"; + } + $data_factory->addType(SDO_DAS_Relational::APP_NAMESPACE, $type); + } + } + private function addTopLevelContainmentPropertyToSDO($data_factory) { $app_root_type = $this->containment_references_model->getApplicationRootType(); @@ -219,6 +233,23 @@ array('many' => true, 'containment' => true)); } + private function addTopLevelContainmentPropertiesToSDO($data_factory) + { + $non_contained_types = $this->containment_references_model->getAllNonContainedTypes(); + + foreach ( $non_contained_types as $type ) { + if (SDO_DAS_Relational::DEBUG_BUILD_SDO_MODEL) { + echo "adding containment property $type to hidden root type\n"; + } + + $data_factory->addPropertyToType( + SDO_DAS_Relational::DAS_NAMESPACE, SDO_DAS_Relational::DAS_ROOT_TYPE, + $type, + SDO_DAS_Relational::APP_NAMESPACE, $type, + array('many' => true, 'containment' => true)); + } + } + private function addAllTheColumnsAsPropertiesToSDO($data_factory) { ////////////////////////////////////////////////////////////////////////// @@ -258,7 +289,7 @@ // end for each this column // end for each active type ////////////////////////////////////////////////////////////////////////// - $active_types = $this->containment_references_model->getActiveTypes(); + $active_types = $this->containment_references_model->getActiveTypes(); foreach ($active_types as $type) { $table = $this->database_model->getTableByName($type); $columns = $table->getColumns(); http://cvs.php.net/viewvc.cgi/pecl/sdo/DAS/Relational/ContainmentReferencesModel.php?r1=1.4&r2=1.4.4.1&diff_format=u Index: pecl/sdo/DAS/Relational/ContainmentReferencesModel.php diff -u pecl/sdo/DAS/Relational/ContainmentReferencesModel.php:1.4 pecl/sdo/DAS/Relational/ContainmentReferencesModel.php:1.4.4.1 --- pecl/sdo/DAS/Relational/ContainmentReferencesModel.php:1.4 Thu Sep 28 19:23:52 2006 +++ pecl/sdo/DAS/Relational/ContainmentReferencesModel.php Thu Nov 9 13:40:19 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ | Author: Matthew Peters | +----------------------------------------------------------------------+ -$Id: ContainmentReferencesModel.php,v 1.4 2006/09/28 19:23:52 cem Exp $ +$Id: ContainmentReferencesModel.php,v 1.4.4.1 2006/11/09 13:40:19 slaws Exp $ */ require_once 'SDO/DAS/Relational/ContainmentReference.php'; @@ -48,20 +48,34 @@ private $active_containment_references = array(); // Only those reachable from app_root_type private $active_types; // potentially a subset of the full set of types - just those reachable from root private $app_root_type; + private $database_model; - public function __construct($app_root_type, $containment_references_metadata) + public function __construct($app_root_type, $containment_references_metadata, $database_model) { - assert(gettype($app_root_type) == 'string'); + if ( $app_root_type != null ) { + assert(gettype($app_root_type) == 'string'); + } + assert(gettype($containment_references_metadata) == 'array'); - $this->app_root_type = $app_root_type; + $this->app_root_type = $app_root_type; + $this->database_model = $database_model; foreach ($containment_references_metadata as $cref) { $this->full_set_containment_references[] = new SDO_DAS_Relational_ContainmentReference($cref); } $reachable_types_already_visited = array(); - $reachable_types_still_to_check = array($app_root_type); + + // maintain app_root_type here for backward compatibility + if ( $app_root_type != null ) { + $reachable_types_still_to_check = array($app_root_type); + } else { + // we need to check all the types and find all of the ones for which no + // containment references are specified + $reachable_types_still_to_check = $this->getAllNonContainedTypes(); + } + $references_traversed = array(); while (count($reachable_types_still_to_check) > 0) { $type = array_shift($reachable_types_still_to_check); @@ -79,6 +93,7 @@ $this->active_types = $reachable_types_already_visited; $this->active_containment_references = $references_traversed; } + public function getActiveContainmentReferences() { @@ -130,6 +145,30 @@ } return null; } + + public function getAllNonContainedTypes() + { + $non_contained_types = array(); + $all_types = $this->database_model->getAllTableNames(); + + // loop through all the types. If a type name doesn't appear + // as a child in the containment meta-data then the type + // is non contained + foreach ( $all_types as $type ) { + $contained = false; + foreach ( $this->full_set_containment_references as $ref ) { + if ( $ref->getChildName() == $type ) { + $contained = true; + break; + } + } + if ( $contained == false ) { + $non_contained_types[] = $type; + } + } + + return $non_contained_types; + } } ?> \ No newline at end of file