From 5386404668ec271d77f2e7c89c3306a57e5d5b2c Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Thu, 20 May 2010 16:17:34 -0400 Subject: [PATCH] Fixing types to match orm. --- example/performance.doctrine.php | 61 +++++++++ example/performance.mysql.php | 5 + example/performance.raw.php | 22 ++++ lib/Doctrine/ODM/MongoDB/DocumentManager.php | 41 +++++- lib/Doctrine/ODM/MongoDB/Hydrator.php | 4 +- lib/Doctrine/ODM/MongoDB/Mapping/Types.php | 88 ------------- .../Mapping/Types/BinDataCustomType.php | 2 +- .../MongoDB/Mapping/Types/BinDataFuncType.php | 2 +- .../MongoDB/Mapping/Types/BinDataMD5Type.php | 2 +- .../ODM/MongoDB/Mapping/Types/BinDataType.php | 2 +- .../MongoDB/Mapping/Types/BinDataUUIDType.php | 2 +- .../ODM/MongoDB/Mapping/Types/BooleanType.php | 2 +- .../ODM/MongoDB/Mapping/Types/DateType.php | 2 +- .../ODM/MongoDB/Mapping/Types/FileType.php | 2 +- .../ODM/MongoDB/Mapping/Types/FloatType.php | 2 +- .../ODM/MongoDB/Mapping/Types/HashType.php | 2 +- .../ODM/MongoDB/Mapping/Types/IdType.php | 2 +- .../ODM/MongoDB/Mapping/Types/IntType.php | 2 +- .../ODM/MongoDB/Mapping/Types/KeyType.php | 2 +- .../ODM/MongoDB/Mapping/Types/StringType.php | 2 +- .../MongoDB/Mapping/Types/TimestampType.php | 2 +- .../ODM/MongoDB/Mapping/Types/Type.php | 121 +++++++++++++++++- lib/Doctrine/ODM/MongoDB/MongoDB.php | 5 + lib/Doctrine/ODM/MongoDB/MongoDBException.php | 20 +++ lib/Doctrine/ODM/MongoDB/Query.php | 11 ++ lib/Doctrine/ODM/MongoDB/UnitOfWork.php | 14 +- 26 files changed, 304 insertions(+), 118 deletions(-) create mode 100644 example/performance.doctrine.php create mode 100644 example/performance.mysql.php create mode 100644 example/performance.raw.php delete mode 100644 lib/Doctrine/ODM/MongoDB/Mapping/Types.php diff --git a/example/performance.doctrine.php b/example/performance.doctrine.php new file mode 100644 index 0000000000..841682fa99 --- /dev/null +++ b/example/performance.doctrine.php @@ -0,0 +1,61 @@ +register(); + +$classLoader = new ClassLoader('Doctrine', '/Users/jwage/Sites/doctrine2git/lib'); +$classLoader->register(); + +$config = new Configuration(); +$config->setMetadataCacheImpl(new ApcCache()); +$config->setProxyDir(__DIR__ . '/Proxies'); +$config->setProxyNamespace('Proxies'); + +$reader = new AnnotationReader(); +$reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\'); +$config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents')); + +$mongo = new Mongo(); +$dm = DocumentManager::create($mongo, $config); + +/** @Document(db="performance", collection="users") */ +class User +{ + /** @Id */ + public $id; + + /** @String */ + public $username; + + /** @String */ + public $password; +} + +$start = microtime(true); + +/* +$user = new User(); +$user->username = 'user'; +$user->password = 'password'; +$dm->persist($user); +$dm->flush(); +*/ + +$user = $dm->findOne('User', array('username' => 'user')); + +$end = microtime(true); +$total = $end - $start; + +print_r($user); + +echo "Doctrine MongoDB ODM: " . $total."\n"; \ No newline at end of file diff --git a/example/performance.mysql.php b/example/performance.mysql.php new file mode 100644 index 0000000000..ffa6fe7aac --- /dev/null +++ b/example/performance.mysql.php @@ -0,0 +1,5 @@ +prepare('INSERT INTO user (username, password) VALUES (?, ?)'); +$stmt->execute(array('user', 'password')); \ No newline at end of file diff --git a/example/performance.raw.php b/example/performance.raw.php new file mode 100644 index 0000000000..e9cbede6cd --- /dev/null +++ b/example/performance.raw.php @@ -0,0 +1,22 @@ + 'user', + 'password' => 'password' +); +$mongo->performance->users->insert($user); +*/ + +$user = $mongo->performance->users->findOne(array('username' => 'user')); + +$end = microtime(true); +$total = $end - $start; + +print_r($user); + +echo "Raw MongoDB Extension: " . $total."\n"; \ No newline at end of file diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index c4cb391ccc..63d288933e 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -109,6 +109,11 @@ class DocumentManager */ private $_documentCollections = array(); + /** + * Whether the DocumentManager is closed or not. + */ + private $_closed = false; + /** * Creates a new Document that operates on the given Mongo connection * and uses the given Configuration. @@ -143,10 +148,11 @@ protected function __construct(Mongo $mongo = null, Configuration $config = null * * @param Doctrine\ODM\MongoDB\Mongo $mongo * @param Doctrine\ODM\MongoDB\Configuration $config + * @param Doctrine\Common\EventManager $eventManager */ - public static function create(Mongo $mongo, Configuration $config = null) + public static function create(Mongo $mongo, Configuration $config = null, EventManager $eventManager = null) { - return new self($mongo, $config); + return new self($mongo, $config, $eventManager); } /** @@ -235,6 +241,7 @@ public function getDocumentDB($className) { $db = $this->_metadataFactory->getMetadataFor($className)->getDB(); $db = $db ? $db : $this->_config->getDefaultDB(); + $db = $db ? $db : 'doctrine'; if ($db && ! isset($this->_documentDBs[$db])) { $database = $this->_mongo->selectDB($db); $this->_documentDBs[$db] = new MongoDB($database); @@ -299,6 +306,7 @@ public function persist($document) if ( ! is_object($document)) { throw new \InvalidArgumentException(gettype($document)); } + $this->_errorIfClosed(); $this->_unitOfWork->persist($document); } @@ -315,6 +323,7 @@ public function remove($document) if ( ! is_object($document)) { throw new \InvalidArgumentException(gettype($document)); } + $this->_errorIfClosed(); $this->_unitOfWork->remove($document); } @@ -329,6 +338,7 @@ public function refresh($document) if ( ! is_object($document)) { throw new \InvalidArgumentException(gettype($document)); } + $this->_errorIfClosed(); $this->_unitOfWork->refresh($document); } @@ -362,6 +372,7 @@ public function merge($document) if ( ! is_object($document)) { throw new \InvalidArgumentException(gettype($document)); } + $this->_errorIfClosed(); return $this->_unitOfWork->merge($document); } @@ -434,6 +445,7 @@ public function load($documentName, $id, $data) */ public function flush() { + $this->_errorIfClosed(); $this->_unitOfWork->commit(); } @@ -540,4 +552,27 @@ public function clear() { $this->_unitOfWork->clear(); } -} + + /** + * Closes the DocumentManager. All documents that are currently managed + * by this DocumentManager become detached. The DocumentManager may no longer + * be used after it is closed. + */ + public function close() + { + $this->clear(); + $this->_closed = true; + } + + /** + * Throws an exception if the EntityManager is closed or currently not active. + * + * @throws ORMException If the EntityManager is closed. + */ + private function _errorIfClosed() + { + if ($this->_closed) { + throw MongoDBException::documentManagerClosed(); + } + } +} \ No newline at end of file diff --git a/lib/Doctrine/ODM/MongoDB/Hydrator.php b/lib/Doctrine/ODM/MongoDB/Hydrator.php index 3aae8e4782..68ab37bd47 100644 --- a/lib/Doctrine/ODM/MongoDB/Hydrator.php +++ b/lib/Doctrine/ODM/MongoDB/Hydrator.php @@ -22,7 +22,7 @@ use Doctrine\ODM\MongoDB\Query, Doctrine\ODM\MongoDB\Mapping\ClassMetadata, Doctrine\ODM\MongoDB\PersistentCollection, - Doctrine\ODM\MongoDB\Mapping\Types, + Doctrine\ODM\MongoDB\Mapping\Types\Type, Doctrine\Common\Collections\ArrayCollection, Doctrine\Common\Collections\Collection; @@ -108,7 +108,7 @@ public function hydrate(ClassMetadata $metadata, $document, $data) } } else { $value = $data[$mapping['fieldName']]; - $value = Types::getType($mapping['type'])->convertToPHPValue($value); + $value = Type::getType($mapping['type'])->convertToPHPValue($value); $metadata->setFieldValue($document, $mapping['fieldName'], $value); } if (isset($value)) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types.php deleted file mode 100644 index dfd2feca86..0000000000 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types.php +++ /dev/null @@ -1,88 +0,0 @@ -. - */ - -namespace Doctrine\ODM\MongoDB\Mapping; - -/** - * Types class used for retrieving Mongo type instances and processing values. - * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.org - * @since 1.0 - * @version $Revision$ - * @author Jonathan H. Wage - */ -class Types -{ - /** - * Array of string types mapped to their type class. - */ - private static $_typeMap = array( - 'id' => 'Doctrine\ODM\MongoDB\Mapping\Types\IdType', - 'boolean' => 'Doctrine\ODM\MongoDB\Mapping\Types\BooleanType', - 'int' => 'Doctrine\ODM\MongoDB\Mapping\Types\IntType', - 'float' => 'Doctrine\ODM\MongoDB\Mapping\Types\FloatType', - 'string' => 'Doctrine\ODM\MongoDB\Mapping\Types\StringType', - 'date' => 'Doctrine\ODM\MongoDB\Mapping\Types\DateType', - 'key' => 'Doctrine\ODM\MongoDB\Mapping\Types\KeyType', - 'timestamp' => 'Doctrine\ODM\MongoDB\Mapping\Types\TimestampType', - 'bin' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataType', - 'bin_func' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataFuncType', - 'bin_uuid' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataUUIDType', - 'bin_md5' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataMD5Type', - 'custom' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataCustomType', - 'file' => 'Doctrine\ODM\MongoDB\Mapping\Types\FileType', - 'hash' => 'Doctrine\ODM\MongoDB\Mapping\Types\HashType', - ); - - /** - * Array of instantiated type classes. - */ - private static $_types = array(); - - /** - * Register a new type in the type map. - * - * @param string $name The name of the type. - * @param string $class The class name. - */ - public static function registerType($name, $class) - { - self::$_typeMap[$name] = $class; - } - - /** - * Get a Type instance. - * - * @param string $type The type name. - * @return Doctrine\ODM\MongoDB\Mapping\Types\Type $type - * @throws InvalidArgumentException - */ - public static function getType($type) - { - if ( ! isset(self::$_typeMap[$type])) { - throw new \InvalidArgumentException(sprintf('Invalid type specified "%s".', $type)); - } - if ( ! isset(self::$_types[$type])) { - $className = self::$_typeMap[$type]; - self::$_types[$type] = new $className; - } - return self::$_types[$type]; - } -} \ No newline at end of file diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataCustomType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataCustomType.php index 1c41a20956..22602feffa 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataCustomType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataCustomType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class BinDataCustomType implements Type +class BinDataCustomType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataFuncType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataFuncType.php index f99c1c6489..ca6ff16219 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataFuncType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataFuncType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class BinDataFuncType implements Type +class BinDataFuncType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataMD5Type.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataMD5Type.php index cab0b2abdc..80211de987 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataMD5Type.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataMD5Type.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class BinDataMD5Type implements Type +class BinDataMD5Type extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataType.php index 408d70577e..4d36dbbaf9 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class BinDataType implements Type +class BinDataType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataUUIDType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataUUIDType.php index f91b2097a8..f559f6016f 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataUUIDType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataUUIDType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class BinDataUUIDType implements Type +class BinDataUUIDType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BooleanType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BooleanType.php index 54c0d054f7..8313eb72fa 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/BooleanType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/BooleanType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class BooleanType implements Type +class BooleanType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/DateType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/DateType.php index 52c4efc3ad..287fcc97ad 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/DateType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/DateType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class DateType implements Type +class DateType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/FileType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/FileType.php index 7f3e820fd2..8b327140a9 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/FileType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/FileType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class FileType implements Type +class FileType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/FloatType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/FloatType.php index 92a7d3033f..6ceb91adfa 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/FloatType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/FloatType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class FloatType implements Type +class FloatType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/HashType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/HashType.php index c826cd0363..4b0ee72553 100755 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/HashType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/HashType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Bulat Shakirzyanov */ -class HashType implements Type +class HashType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/IdType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/IdType.php index 55a2027283..ebc86cf099 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/IdType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/IdType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class IdType implements Type +class IdType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/IntType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/IntType.php index bf24f838f5..948fe3f80b 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/IntType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/IntType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class IntType implements Type +class IntType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/KeyType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/KeyType.php index 3d1fa7ff86..238413c221 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/KeyType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/KeyType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class KeyType implements Type +class KeyType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/StringType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/StringType.php index 2c80aa1b1a..3a29641269 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/StringType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/StringType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class StringType implements Type +class StringType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/TimestampType.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/TimestampType.php index 5923349851..00c75a3767 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/TimestampType.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/TimestampType.php @@ -28,7 +28,7 @@ * @version $Revision$ * @author Jonathan H. Wage */ -class TimestampType implements Type +class TimestampType extends Type { public function convertToDatabaseValue($value) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Types/Type.php b/lib/Doctrine/ODM/MongoDB/Mapping/Types/Type.php index 50a6df9edf..e0e9f1162b 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Types/Type.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Types/Type.php @@ -19,6 +19,8 @@ namespace Doctrine\ODM\MongoDB\Mapping\Types; +use Doctrine\ODM\MongoDB\MongoDBException; + /** * The Type interface. * @@ -28,8 +30,121 @@ * @version $Revision$ * @author Jonathan H. Wage */ -interface Type +abstract class Type { - function convertToDatabaseValue($value); - function convertToPHPValue($value); + /** + * Array of string types mapped to their type class. + */ + private static $_typesMap = array( + 'id' => 'Doctrine\ODM\MongoDB\Mapping\Types\IdType', + 'boolean' => 'Doctrine\ODM\MongoDB\Mapping\Types\BooleanType', + 'int' => 'Doctrine\ODM\MongoDB\Mapping\Types\IntType', + 'float' => 'Doctrine\ODM\MongoDB\Mapping\Types\FloatType', + 'string' => 'Doctrine\ODM\MongoDB\Mapping\Types\StringType', + 'date' => 'Doctrine\ODM\MongoDB\Mapping\Types\DateType', + 'key' => 'Doctrine\ODM\MongoDB\Mapping\Types\KeyType', + 'timestamp' => 'Doctrine\ODM\MongoDB\Mapping\Types\TimestampType', + 'bin' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataType', + 'bin_func' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataFuncType', + 'bin_uuid' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataUUIDType', + 'bin_md5' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataMD5Type', + 'custom' => 'Doctrine\ODM\MongoDB\Mapping\Types\BinDataCustomType', + 'file' => 'Doctrine\ODM\MongoDB\Mapping\Types\FileType', + 'hash' => 'Doctrine\ODM\MongoDB\Mapping\Types\HashType', + ); + + abstract public function convertToDatabaseValue($value); + abstract public function convertToPHPValue($value); + + /** + * Array of instantiated type classes. + */ + private static $_types = array(); + + /** + * Register a new type in the type map. + * + * @param string $name The name of the type. + * @param string $class The class name. + */ + public static function registerType($name, $class) + { + self::$_typesMap[$name] = $class; + } + + /** + * Get a Type instance. + * + * @param string $type The type name. + * @return Doctrine\ODM\MongoDB\Mapping\Types\Type $type + * @throws InvalidArgumentException + */ + public static function getType($type) + { + if ( ! isset(self::$_typesMap[$type])) { + throw new \InvalidArgumentException(sprintf('Invalid type specified "%s".', $type)); + } + if ( ! isset(self::$_types[$type])) { + $className = self::$_typesMap[$type]; + self::$_types[$type] = new $className; + } + return self::$_types[$type]; + } + + /** + * Adds a custom type to the type map. + * + * @static + * @param string $name Name of the type. This should correspond to what getName() returns. + * @param string $className The class name of the custom type. + * @throws MongoDBException + */ + public static function addType($name, $className) + { + if (isset(self::$_typesMap[$name])) { + throw MongoDBException::typeExists($name); + } + + self::$_typesMap[$name] = $className; + } + + /** + * Checks if exists support for a type. + * + * @static + * @param string $name Name of the type + * @return boolean TRUE if type is supported; FALSE otherwise + */ + public static function hasType($name) + { + return isset(self::$_typesMap[$name]); + } + + /** + * Overrides an already defined type to use a different implementation. + * + * @static + * @param string $name + * @param string $className + * @throws MongoDBException + */ + public static function overrideType($name, $className) + { + if ( ! isset(self::$_typesMap[$name])) { + throw MongoDBException::typeNotFound($name); + } + + self::$_typesMap[$name] = $className; + } + + /** + * Get the types array map which holds all registered types and the corresponding + * type class + * + * @return array $typesMap + */ + public static function getTypesMap() + { + return self::$_typesMap; + } } \ No newline at end of file diff --git a/lib/Doctrine/ODM/MongoDB/MongoDB.php b/lib/Doctrine/ODM/MongoDB/MongoDB.php index 7fb8339919..cca8e0e458 100644 --- a/lib/Doctrine/ODM/MongoDB/MongoDB.php +++ b/lib/Doctrine/ODM/MongoDB/MongoDB.php @@ -58,6 +58,11 @@ public function getMongoDB() return $this->_mongoDB; } + public function selectCollection($collection) + { + return $this->_mongoDB->selectCollection($collection); + } + /** @proxy */ public function __call($method, $arguments) { diff --git a/lib/Doctrine/ODM/MongoDB/MongoDBException.php b/lib/Doctrine/ODM/MongoDB/MongoDBException.php index e8d6c1c5ca..ea02660340 100644 --- a/lib/Doctrine/ODM/MongoDB/MongoDBException.php +++ b/lib/Doctrine/ODM/MongoDB/MongoDBException.php @@ -64,4 +64,24 @@ public static function documentNotMappedToCollection($className) { return new self(sprintf('The "%s" document is not mapped to a MongoDB database collection.', $className)); } + + public static function documentManagerClosed() + { + return new self('The DocumentManager is closed.'); + } + + public static function typeExists($name) + { + return new self('Type '.$name.' already exists.'); + } + + public static function unknownFieldType($name) + { + return new self('Unknown field type '.$name.' requested.'); + } + + public static function typeNotFound($name) + { + return new self('Type to be overwritten '.$name.' does not exist.'); + } } \ No newline at end of file diff --git a/lib/Doctrine/ODM/MongoDB/Query.php b/lib/Doctrine/ODM/MongoDB/Query.php index 5d4faf0a84..0a1dc8e9ba 100644 --- a/lib/Doctrine/ODM/MongoDB/Query.php +++ b/lib/Doctrine/ODM/MongoDB/Query.php @@ -756,6 +756,17 @@ public function pullAll($field, array $valueArray) return $this; } + /** + * Proxy to execute() method + * + * @param array $options + * @return Query + */ + public function getResult(array $options = array()) + { + return $this->execute($options); + } + /** * Execute the query and return an array of results * diff --git a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php index b99f1b352e..c92b0b97e1 100644 --- a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php +++ b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php @@ -23,7 +23,7 @@ Doctrine\ODM\MongoDB\Internal\CommitOrderCalculator, Doctrine\ODM\MongoDB\Mapping\ClassMetadata, Doctrine\ODM\MongoDB\Proxy\Proxy, - Doctrine\ODM\MongoDB\Mapping\Types, + Doctrine\ODM\MongoDB\Mapping\Types\Type, Doctrine\Common\Collections\Collection, Doctrine\Common\Collections\ArrayCollection; @@ -691,7 +691,7 @@ private function _prepareUpdate($class, $document) $changeset[$mapping['fieldName']] = $this->_prepareDocEmbeded($targetClass, $doc); } } elseif (isset($changeset[$mapping['fieldName']])) { - $changeset[$mapping['fieldName']] = Types::getType($mapping['type'])->convertToDatabaseValue($changeset[$mapping['fieldName']]); + $changeset[$mapping['fieldName']] = Type::getType($mapping['type'])->convertToDatabaseValue($changeset[$mapping['fieldName']]); } } return $changeset; @@ -761,7 +761,7 @@ private function _prepareDocEmbeded($class, $doc) } } } else { - $value = Types::getType($mapping['type'])->convertToDatabaseValue($rawValue); + $value = Type::getType($mapping['type'])->convertToDatabaseValue($rawValue); } $changeset[$mapping['fieldName']] = $value; } @@ -812,10 +812,10 @@ private function _getCommitOrder(array $documentChangeSet = null) { if ($documentChangeSet === null) { $documentChangeSet = array_merge( - $this->_documentInsertions, - $this->_documentUpdates, - $this->_documentDeletions - ); + $this->_documentInsertions, + $this->_documentUpdates, + $this->_documentDeletions + ); } $calc = $this->getCommitOrderCalculator();