Changeset 4877 for trunk/lib/Doctrine
- Timestamp:
- 09/07/08 14:48:40 (4 months ago)
- Location:
- trunk/lib/Doctrine
- Files:
-
- 2 added
- 41 removed
- 21 modified
-
ClassMetadata.php (modified) (7 diffs)
-
Collection.php (modified) (2 diffs)
-
Connection.php (modified) (3 diffs)
-
Connection/Firebird (deleted)
-
Connection/Informix (deleted)
-
Connection/Mock.php (deleted)
-
Connection/Mssql (deleted)
-
Connection/Mysql (deleted)
-
Connection/Oracle (deleted)
-
Connection/Pgsql (deleted)
-
Connection/Sqlite (deleted)
-
Connection/UnitOfWork.php (modified) (10 diffs)
-
ConnectionFactory (deleted)
-
ConnectionFactory.php (modified) (5 diffs)
-
DatabasePlatform/FirebirdPlatform.php (modified) (1 diff)
-
DatabasePlatform/OraclePlatform.php (modified) (1 diff)
-
DataDict (deleted)
-
Entity.php (modified) (1 diff)
-
EntityManager.php (modified) (10 diffs)
-
EntityManagerFactory.php (deleted)
-
EntityPersister/Abstract.php (modified) (2 diffs)
-
EventListener (deleted)
-
Export/Exception.php (deleted)
-
Export/Firebird.php (deleted)
-
Export/Mssql.php (deleted)
-
Export/Mysql.php (deleted)
-
Export/Oracle.php (deleted)
-
Export/Pgsql.php (deleted)
-
Export/Sqlite.php (deleted)
-
Expression (deleted)
-
Hook (deleted)
-
Id/AbstractIdGenerator.php (modified) (3 diffs)
-
Id/Assigned.php (added)
-
Id/IdentityGenerator.php (modified) (1 diff)
-
Id/SequenceGenerator.php (modified) (1 diff)
-
Id/SequenceIdentityGenerator.php (added)
-
Id/TableGenerator.php (modified) (1 diff)
-
Import/Firebird.php (deleted)
-
Import/Informix.php (deleted)
-
Import/Mssql.php (deleted)
-
Import/Mysql.php (deleted)
-
Import/Oracle.php (deleted)
-
Import/Pgsql.php (deleted)
-
Import/Sqlite.php (deleted)
-
Manager (deleted)
-
Query/Filter (deleted)
-
Query/Tokenizer (deleted)
-
RawSql (deleted)
-
Record/Exception.php (deleted)
-
Record/Filter (deleted)
-
Record/Filter.php (deleted)
-
Record/Iterator.php (deleted)
-
Record/Listener (deleted)
-
Record/Listener.php (deleted)
-
Record/State (deleted)
-
Relation (deleted)
-
Sequence/Db2.php (modified) (1 diff)
-
Sequence/Informix.php (modified) (1 diff)
-
Sequence/Mssql.php (modified) (1 diff)
-
Sequence/Mysql.php (modified) (1 diff)
-
Sequence/Oracle.php (modified) (1 diff)
-
Sequence/Pgsql.php (modified) (1 diff)
-
Sequence/Sqlite.php (modified) (1 diff)
-
View (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Doctrine/ClassMetadata.php
r4866 r4877 170 170 171 171 /** 172 * The Id generator. 173 * 174 * @var Doctrine::ORM::Id::IdGenerator 175 */ 176 protected $_idGenerator; 177 178 /** 172 179 * The field mappings of the class. 173 180 * Keys are field names and values are mapping definitions. … … 599 606 */ 600 607 public function getAssociationMappings() 608 { 609 return $this->_associationMappings; 610 } 611 612 /** 613 * Gets all association mappings of the class. 614 * Alias for getAssociationMappings(). 615 * 616 * @return array 617 */ 618 public function getAssociations() 601 619 { 602 620 return $this->_associationMappings; … … 687 705 } 688 706 $this->_fieldMappings[$mapping['fieldName']] = $mapping; 689 }690 691 /**692 * Overrides an existant field mapping.693 * Used i.e. by Entity classes deriving from another Entity class that acts694 * as a mapped superclass to refine the basic mapping.695 *696 * @param array $newMapping697 * @todo Implementation.698 */699 public function overrideFieldMapping(array $newMapping)700 {701 //...702 707 } 703 708 … … 756 761 757 762 return $mapping; 763 } 764 765 /** 766 * @todo Implementation of Optimistic Locking. 767 */ 768 public function mapVersionField(array $mapping) 769 { 770 //... 771 } 772 773 /** 774 * Overrides an existant field mapping. 775 * Used i.e. by Entity classes deriving from another Entity class that acts 776 * as a mapped superclass to refine the basic mapping. 777 * 778 * @param array $newMapping 779 * @todo Implementation. 780 */ 781 public function overrideFieldMapping(array $newMapping) 782 { 783 //... 784 } 785 786 /** 787 * Used to lazily create the id generator. 788 * 789 * @param string $generatorType 790 * @return void 791 */ 792 protected function _createIdGenerator() 793 { 794 if ($this->_generatorType == self::GENERATOR_TYPE_IDENTITY) { 795 $this->_idGenerator = new Doctrine_Id_IdentityGenerator($this->_em); 796 } else if ($this->_generatorType == self::GENERATOR_TYPE_SEQUENCE) { 797 $this->_idGenerator = new Doctrine_Id_SequenceGenerator($this->_em); 798 } else if ($this->_generatorType == self::GENERATOR_TYPE_TABLE) { 799 $this->_idGenerator = new Doctrine_Id_TableGenerator($this->_em); 800 } else { 801 $this->_idGenerator = new Doctrine_Id_Assigned($this->_em); 802 } 758 803 } 759 804 … … 1621 1666 return $this->_customRepositoryClassName; 1622 1667 } 1668 1669 /** 1670 * Gets the Id generator used by the class. 1671 * 1672 * @return Doctrine::ORM::Id::AbstractIdGenerator 1673 */ 1674 public function getIdGenerator() 1675 { 1676 if (is_null($this->_idGenerator)) { 1677 $this->_createIdGenerator(); 1678 } 1679 return $this->_idGenerator; 1680 } 1623 1681 1624 1682 /** … … 1725 1783 1726 1784 /** 1727 * Completes the identifier mapping of the class.1785 * INTERNAL: Completes the identifier mapping of the class. 1728 1786 * NOTE: Should only be called by the ClassMetadataFactory! 1729 1787 * … … 1732 1790 public function completeIdentifierMapping() 1733 1791 { 1734 if ($this-> getIdGeneratorType()== self::GENERATOR_TYPE_AUTO) {1792 if ($this->_generatorType == self::GENERATOR_TYPE_AUTO) { 1735 1793 $platform = $this->_em->getConnection()->getDatabasePlatform(); 1794 if ($platform === null) { 1795 try { 1796 throw new Exception(); 1797 } catch (Exception $e) { 1798 echo $e->getTraceAsString(); 1799 } 1800 } 1736 1801 if ($platform->prefersSequences()) { 1737 1802 $this->_generatorType = self::GENERATOR_TYPE_SEQUENCE; -
trunk/lib/Doctrine/Collection.php
r4866 r4877 131 131 { 132 132 $this->_entityBaseType = $entityBaseType; 133 $this->_em = Doctrine_EntityManager Factory::getManager($entityBaseType);133 $this->_em = Doctrine_EntityManager::getActiveEntityManager(); 134 134 135 135 if ($keyField !== null) { … … 1019 1019 public function unserialize($serialized) 1020 1020 { 1021 $manager = Doctrine_EntityManager Factory::getManager();1021 $manager = Doctrine_EntityManager::getActiveEntityManager(); 1022 1022 $connection = $manager->getConnection(); 1023 1023 -
trunk/lib/Doctrine/Connection.php
r4866 r4877 162 162 163 163 /** 164 * The sequence manager.165 *166 * @var Doctrine::DBAL::Sequencing::SequenceManager167 */168 protected $_sequenceManager;169 170 /**171 164 * The schema manager. 172 165 * … … 947 940 * @param string $field Name of the field into which a new row was inserted. 948 941 */ 949 public function lastInsertId($ table = null, $field= null)950 { 951 return $this-> getSequenceManager()->lastInsertId($table, $field);942 public function lastInsertId($seqName = null) 943 { 944 return $this->_pdo->lastInsertId($seqName); 952 945 } 953 946 … … 1179 1172 1180 1173 /** 1181 * Gets the SequenceManager that can be used to retrieve sequence values1182 * through this connection.1183 *1184 * @return Doctrine::DBAL::Sequencing::SequenceManager1185 */1186 public function getSequenceManager()1187 {1188 if ( ! $this->_sequenceManager) {1189 $class = "Doctrine_Sequence_" . $this->_driverName;1190 $this->_sequenceManager = new $class;1191 }1192 return $this->_sequenceManager;1193 }1194 1195 /**1196 1174 * Gets the SchemaManager that can be used to inspect or change the 1197 1175 * database schema through the connection. -
trunk/lib/Doctrine/Connection/UnitOfWork.php
r4789 r4877 183 183 } 184 184 185 /** 186 * Executes all entity insertions for entities of the specified type. 187 * 188 * @param Doctrine::ORM::Mapping::ClassMetadata $class 189 */ 185 190 private function _executeInserts($class) 186 191 { … … 194 199 if ($entity->getClass()->getClassName() == $className) { 195 200 $persister->insert($entity); 201 if ($class->isIdGeneratorIdentity()) { 202 $entity->_assignIdentifier($class->getIdGenerator()->getPostInsertId()); 203 } 196 204 } 197 205 } 198 206 } 199 207 208 /** 209 * Executes all entity updates for entities of the specified type. 210 * 211 * @param Doctrine::ORM::Mapping::ClassMetadata $class 212 */ 200 213 private function _executeUpdates($class) 201 214 { … … 209 222 } 210 223 224 /** 225 * Executes all entity deletions for entities of the specified type. 226 * 227 * @param Doctrine::ORM::Mapping::ClassMetadata $class 228 */ 211 229 private function _executeDeletions($class) 212 230 { … … 225 243 * @return array 226 244 */ 227 private function _getCommitOrder( )245 private function _getCommitOrder(array $entityChangeSet = null) 228 246 { 229 247 //TODO: Once these 3 arrays are indexed by classname we can do this: … … 234 252 array_keys($this->_deletedEntities) 235 253 );*/ 236 237 $entityChangeSet = array_merge($this->_newEntities, $this->_dirtyEntities, $this->_deletedEntities); 254 255 if (is_null($entityChangeSet)) { 256 $entityChangeSet = array_merge($this->_newEntities, $this->_dirtyEntities, $this->_deletedEntities); 257 } 238 258 239 259 /* if (count($entityChangeSet) == 1) { … … 384 404 return; // entity has not been persisted yet, so nothing more to do. 385 405 } 386 /* Seems unnecessary since _dirtyEntities is filled & cleared on commit, not earlier 387 if (isset($this->_dirtyEntities[$oid])) {388 unset($this->_dirtyEntities[$oid]);389 }*/406 407 if (isset($this->_dirtyEntities[$oid])) { 408 unset($this->_dirtyEntities[$oid]); 409 } 390 410 if ( ! isset($this->_deletedEntities[$oid])) { 391 411 $this->_deletedEntities[$oid] = $entity; … … 431 451 $oid = $entity->getOid(); 432 452 return isset($this->_newEntities[$oid]) || 433 //isset($this->_dirtyEntities[$oid]) ||453 isset($this->_dirtyEntities[$oid]) || 434 454 isset($this->_deletedEntities[$oid]) || 435 455 $this->isInIdentityMap($entity); … … 585 605 $this->_doSave($entity, $visited, $insertNow); 586 606 if ( ! empty($insertNow)) { 587 // We have no choice. This means that there are either new entities 588 // with an IDENTITY key generation or with a natural identifier. 589 // In both cases we must commit the inserts instantly. 590 //TODO: Isnt it enough to only execute the inserts instead of full flush? 591 $this->commit(); 592 /* The following may be better: 607 // We have no choice. This means that there are new entities 608 // with an IDENTITY column key generation. 593 609 $commitOrder = $this->_getCommitOrder($insertNow); 594 610 foreach ($commitOrder as $class) { 595 611 $this->_executeInserts($class); 596 612 } 597 // ... remove them from _newEntities, or dont store them there in the first place598 */613 // remove them from _newEntities 614 $this->_newEntities = array_diff_key($this->_newEntities, $insertNow); 599 615 } 600 616 } … … 622 638 break; 623 639 case Doctrine_Entity::STATE_NEW: 624 if ($class->isIdGeneratorIdentity()) { 640 $result = $class->getIdGenerator()->generate($entity); 641 if ($result == Doctrine_Id_AbstractIdGenerator::POST_INSERT_INDICATOR) { 625 642 $insertNow[$entity->getOid()] = $entity; 626 $this->_newEntities[$entity->getOid()] = $entity;627 } else if ( ! $class->usesIdGenerator()) {628 $insertNow[$entity->getOid()] = $entity;629 $this->_newEntities[$entity->getOid()] = $entity;630 //...631 } else if ($class->isIdGeneratorSequence()) {632 // Get the next sequence number633 //TODO: sequence name?634 $id = $this->_em->getConnection()->getSequenceManager()->nextId("foo");635 $entity->set($class->getSingleIdentifierFieldName(), $id);636 $this->registerNew($entity);637 643 } else { 638 throw new Doctrine_Exception("Unable to handle ID generation of new entity.");644 $entity->_assignIdentifier($result); 639 645 } 646 $this->registerNew($entity); 640 647 break; 641 648 case Doctrine_Entity::STATE_DETACHED: … … 671 678 } 672 679 680 /** 681 * Enter description here... 682 * 683 * @param Doctrine_Entity $entity 684 * @param array $visited 685 */ 673 686 private function _doDelete(Doctrine_Entity $entity, array &$visited) 674 687 { -
trunk/lib/Doctrine/ConnectionFactory.php
r4866 r4877 46 46 'firebird' => 'Doctrine_Connection_Firebird', 47 47 'informix' => 'Doctrine_Connection_Informix', 48 'mock' => 'Doctrine_Connection_Mock'); 49 50 /** 51 * The EventManager that is injected into all created Connections. 52 * 53 * @var EventManager 54 */ 55 private $_eventManager; 56 57 /** 58 * The Configuration that is injected into all created Connections. 59 * 60 * @var Configuration 61 */ 62 private $_config; 48 ); 63 49 64 50 public function __construct() 65 51 { 66 52 67 }68 69 /**70 * Sets the Configuration that is injected into all Connections.71 *72 * @param Doctrine_Configuration $config73 */74 public function setConfiguration(Doctrine_Configuration $config)75 {76 $this->_config = $config;77 }78 79 /**80 * Sets the EventManager that is injected into all Connections.81 *82 * @param Doctrine_EventManager $eventManager83 */84 public function setEventManager(Doctrine_EventManager $eventManager)85 {86 $this->_eventManager = $eventManager;87 53 } 88 54 … … 93 59 * @return Connection 94 60 */ 95 public function createConnection(array $params) 61 public function createConnection(array $params, Doctrine_Configuration $config = null, 62 Doctrine_EventManager $eventManager = null) 96 63 { 97 64 // create default config and event manager, if not set 98 if ( ! $ this->_config) {99 $ this->_config = new Doctrine_Configuration();65 if ( ! $config) { 66 $config = new Doctrine_Configuration(); 100 67 } 101 if ( ! $ this->_eventManager) {102 $ this->_eventManager = new Doctrine_EventManager();68 if ( ! $eventManager) { 69 $eventManager = new Doctrine_EventManager(); 103 70 } 104 71 … … 111 78 $this->_checkParams($params); 112 79 } 113 $className = $this->_drivers[$params['driver']]; 80 if (isset($params['driverClass'])) { 81 $className = $params['driverClass']; 82 } else { 83 $className = $this->_drivers[$params['driver']]; 84 } 114 85 115 return new $className($params, $ this->_config, $this->_eventManager);86 return new $className($params, $config, $eventManager); 116 87 } 117 88 … … 126 97 127 98 // driver 128 if ( ! isset($params['driver']) ) {99 if ( ! isset($params['driver']) && ! isset($params['driverClass'])) { 129 100 throw Doctrine_ConnectionFactory_Exception::driverRequired(); 130 101 } … … 133 104 134 105 // driver 135 if ( ! isset($this->_drivers[$params['driver']])) {106 if ( isset($params['driver']) && ! isset($this->_drivers[$params['driver']])) { 136 107 throw Doctrine_ConnectionFactory_Exception::unknownDriver($driverName); 137 108 } -
trunk/lib/Doctrine/DatabasePlatform/FirebirdPlatform.php
r4725 r4877 247 247 } 248 248 249 /** 250 * Enter description here... 251 * 252 * @param unknown_type $sequenceName 253 * @override 254 */ 255 public function getSequenceNextValSql($sequenceName) 256 { 257 return 'SELECT GEN_ID(' . $this->quoteIdentifier($sequenceName) . ', 1) FROM RDB$DATABASE'; 258 } 259 249 260 } 250 261 -
trunk/lib/Doctrine/DatabasePlatform/OraclePlatform.php
r4776 r4877 332 332 'fixed' => $fixed); 333 333 } 334 335 /** 336 * Enter description here... 337 * 338 * @param unknown_type $sequenceName 339 * @override 340 */ 341 public function getSequenceNextValSql($sequenceName) 342 { 343 return 'SELECT ' . $this->quoteIdentifier($sequenceName) . '.nextval FROM DUAL'; 344 } 334 345 } 335 346 -
trunk/lib/Doctrine/Entity.php
r4866 r4877 205 205 { 206 206 $this->_entityName = get_class($this); 207 $this->_em = Doctrine_EntityManager Factory::getManager($this->_entityName);207 $this->_em = Doctrine_EntityManager::getActiveEntityManager(); 208 208 $this->_class = $this->_em->getClassMetadata($this->_entityName); 209 209 $this->_oid = self::$_index++; -
trunk/lib/Doctrine/EntityManager.php
r4866 r4877 63 63 64 64 /** 65 * The currently active EntityManager. Only one EntityManager can be active 66 * at any time. 67 * 68 * @var Doctrine::ORM::EntityManager 69 */ 70 private static $_activeEm; 71 72 /** 65 73 * The unique name of the EntityManager. The name is used to bind entity classes 66 74 * to certain EntityManagers. … … 133 141 private $_tmpEntityData = array(); 134 142 143 private $_closed = false; 144 135 145 /** 136 146 * Creates a new EntityManager that operates on the given database connection. … … 139 149 * @param string $name 140 150 */ 141 public function __construct(Doctrine_Connection $conn, $name = null) 151 protected function __construct(Doctrine_Connection $conn, $name, Doctrine_Configuration $config, 152 Doctrine_EventManager $eventManager) 142 153 { 143 154 $this->_conn = $conn; 144 155 $this->_name = $name; 156 $this->_config = $config; 157 $this->_eventManager = $eventManager; 145 158 $this->_metadataFactory = new Doctrine_ClassMetadata_Factory( 146 159 $this, new Doctrine_ClassMetadata_CodeDriver()); … … 157 170 { 158 171 return $this->_conn; 172 } 173 174 /** 175 * Gets the name of the EntityManager. 176 * 177 * @return string The name of the EntityManager. 178 */ 179 public function getName() 180 { 181 return $this->_name; 159 182 } 160 183 … … 303 326 public function flush() 304 327 { 328 $this