Skip to content

Commit

Permalink
Fixing types to match orm.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed May 20, 2010
1 parent 0632861 commit 5386404
Show file tree
Hide file tree
Showing 26 changed files with 304 additions and 118 deletions.
61 changes: 61 additions & 0 deletions example/performance.doctrine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

require '/Users/jwage/Sites/doctrine2git/lib/Doctrine/Common/ClassLoader.php';

use Doctrine\Common\ClassLoader,
Doctrine\Common\Annotations\AnnotationReader,
Doctrine\Common\Cache\ApcCache,
Doctrine\ODM\MongoDB\DocumentManager,
Doctrine\ODM\MongoDB\Mongo,
Doctrine\ODM\MongoDB\Configuration,
Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;

$classLoader = new ClassLoader('Doctrine\ODM', __DIR__ . '/../lib');
$classLoader->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";
5 changes: 5 additions & 0 deletions example/performance.mysql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$pdo = new PDO('mysql:host=localhost;dbname=performance', 'root', null);
$stmt = $pdo->prepare('INSERT INTO user (username, password) VALUES (?, ?)');
$stmt->execute(array('user', 'password'));
22 changes: 22 additions & 0 deletions example/performance.raw.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$mongo = new Mongo();

$start = microtime(true);

/*
$user = array(
'username' => '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";
41 changes: 38 additions & 3 deletions lib/Doctrine/ODM/MongoDB/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -299,6 +306,7 @@ public function persist($document)
if ( ! is_object($document)) {
throw new \InvalidArgumentException(gettype($document));
}
$this->_errorIfClosed();
$this->_unitOfWork->persist($document);
}

Expand All @@ -315,6 +323,7 @@ public function remove($document)
if ( ! is_object($document)) {
throw new \InvalidArgumentException(gettype($document));
}
$this->_errorIfClosed();
$this->_unitOfWork->remove($document);
}

Expand All @@ -329,6 +338,7 @@ public function refresh($document)
if ( ! is_object($document)) {
throw new \InvalidArgumentException(gettype($document));
}
$this->_errorIfClosed();
$this->_unitOfWork->refresh($document);
}

Expand Down Expand Up @@ -362,6 +372,7 @@ public function merge($document)
if ( ! is_object($document)) {
throw new \InvalidArgumentException(gettype($document));
}
$this->_errorIfClosed();
return $this->_unitOfWork->merge($document);
}

Expand Down Expand Up @@ -434,6 +445,7 @@ public function load($documentName, $id, $data)
*/
public function flush()
{
$this->_errorIfClosed();
$this->_unitOfWork->commit();
}

Expand Down Expand Up @@ -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();
}
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)) {
Expand Down
88 changes: 0 additions & 88 deletions lib/Doctrine/ODM/MongoDB/Mapping/Types.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class BinDataCustomType implements Type
class BinDataCustomType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataFuncType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class BinDataFuncType implements Type
class BinDataFuncType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataMD5Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class BinDataMD5Type implements Type
class BinDataMD5Type extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class BinDataType implements Type
class BinDataType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/BinDataUUIDType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class BinDataUUIDType implements Type
class BinDataUUIDType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class BooleanType implements Type
class BooleanType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class DateType implements Type
class DateType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class FileType implements Type
class FileType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/FloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Jonathan H. Wage <[email protected]>
*/
class FloatType implements Type
class FloatType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Types/HashType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @version $Revision$
* @author Bulat Shakirzyanov <[email protected]>
*/
class HashType implements Type
class HashType extends Type
{
public function convertToDatabaseValue($value)
{
Expand Down
Loading

0 comments on commit 5386404

Please sign in to comment.