Commit 613d08f9 authored by romanb's avatar romanb

Merged dbal bugfixes from 0.11.

parent 7ffd4140
......@@ -272,14 +272,12 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*
* @param string $entityName Name of the entity class the metadata info is used for.
*/
public function __construct($entityName, Doctrine_Connection $conn)
public function __construct($entityName, Doctrine_EntityManager $em)
{
$this->_entityName = $entityName;
$this->_rootEntityName = $entityName;
$this->_conn = $conn;
$this->_conn = $em;
$this->_parser = new Doctrine_Relation_Parser($this);
$this->_filters[] = new Doctrine_Record_Filter_Standard();
$this->setConfigurableParent($this->_conn);
}
/**
......@@ -289,6 +287,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
{
return $this->_conn;
}
public function getEntityManager()
{
return $this->_conn;
}
/**
* getComponentName
......@@ -598,7 +601,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$this->_columnCount++;
}
/**
* Gets the default length for a field type.
*
* @param unknown_type $type
* @return unknown
*/
private function _getDefaultLength($type)
{
switch ($type) {
......@@ -625,6 +634,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return 25;
}
}
/**
* Maps an embedded value object.
*
* @todo Implementation.
*/
public function mapEmbeddedValue()
{
//...
}
/**
* setColumn
......@@ -956,11 +975,16 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this->getColumnDefinition($columnName);
}
/**
* Gets the mapping information for a field.
*
* @param string $fieldName
* @return array
*/
public function getMappingForField($fieldName)
{
$columnName = $this->getColumnName($fieldName);
return $this->getColumnDefinition($columnName);
}
......@@ -974,7 +998,13 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
{
return $this->getTypeOfColumn($this->getColumnName($fieldName));
}
/**
* Gets the type of a field.
*
* @param string $fieldName
* @return string
*/
public function getTypeOfField($fieldName)
{
return $this->getTypeOfColumn($this->getColumnName($fieldName));
......@@ -1022,7 +1052,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
public function addNamedQuery($name, $query)
{
//...
}
public function bindRelation($args, $type)
......@@ -1622,7 +1652,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
public function setTableName($tableName)
{
$this->setTableOption('tableName', $this->_conn->formatter->getTableName($tableName));
$this->setTableOption('tableName', $this->_conn->getConnection()
->formatter->getTableName($tableName));
}
/**
......
......@@ -44,9 +44,9 @@ class Doctrine_ClassMetadata_Factory
* @param $conn The connection to use.
* @param $driver The metadata driver to use.
*/
public function __construct(Doctrine_Connection $conn, $driver)
public function __construct(Doctrine_EntityManager $em, $driver)
{
$this->_conn = $conn;
$this->_conn = $em;
$this->_driver = $driver;
}
......
......@@ -31,9 +31,12 @@
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Rename to EntityCollection
*/
class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable
{
protected $_entityBaseType;
/**
* An array containing the records of this collection.
*
......@@ -101,10 +104,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param string $keyColumn The field name that will be used as the key
* in the collection.
*/
public function __construct($mapper, $keyField = null)
public function __construct($entityBaseType, $keyField = null)
{
if (is_string($mapper)) {
$mapper = Doctrine_Manager::getInstance()->getMapper($mapper);
if (is_string($entityBaseType)) {
$this->_entityBaseType = $entityBaseType;
$mapper = Doctrine_EntityManager::getManager($entityBaseType)->getEntityPersister($entityBaseType);
}
$this->_mapper = $mapper;
......@@ -204,16 +208,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public function unserialize($serialized)
{
$manager = Doctrine_Manager::getInstance();
$connection = $manager->getCurrentConnection();
$manager = Doctrine_EntityManager::getManager();
$connection = $manager->getConnection();
$array = unserialize($serialized);
foreach ($array as $name => $values) {
$this->$name = $values;
}
$this->_mapper = $connection->getMapper($this->_mapper);
$this->_mapper = $manager->getEntityPersister($this->_entityBaseType);
$keyColumn = isset($array['keyField']) ? $array['keyField'] : null;
if ($keyColumn === null) {
......@@ -506,6 +510,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public function add($record, $key = null)
{
/** @TODO Use raw getters/setters */
if ( ! $record instanceof Doctrine_Entity) {
throw new Doctrine_Record_Exception('Value variable in set is not an instance of Doctrine_Entity.');
}
......
This diff is collapsed.
......@@ -55,8 +55,8 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection
$col = explode('select', $select);
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
'OVER(ORDER BY ' . $col[1] . ') AS dctrn_rownum FROM ' . $table . ')' .
$select . 'FROM OFFSET WHERE dctrn_rownum BETWEEN ' . $offset .
'OVER(ORDER BY ' . $col[1] . ') AS doctrine_rownum FROM ' . $table . ')' .
$select . 'FROM OFFSET WHERE doctrine_rownum BETWEEN ' . $offset .
'AND ' . ($offset + $limit - 1);
return $sql;
}
......
......@@ -44,7 +44,7 @@ class Doctrine_Connection_Mock extends Doctrine_Connection_Common
* @param Doctrine_Manager $manager
* @param PDO|Doctrine_Adapter $adapter database handler
*/
public function __construct(Doctrine_Manager $manager, $adapter)
public function __construct()
{
}
......
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Connection');
/**
* Doctrine_Connection_Oracle
*
......@@ -80,39 +80,59 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection
$this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' . $format . '"');
}
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string the modified query
*/
public function modifyLimitQuery($query, $limit, $offset)
{
/**
$e = explode("select ",strtolower($query));
$e2 = explode(" from ",$e[1]);
$fields = $e2[0];
*/
$limit = (int) $limit;
$offset = (int) $offset;
if (preg_match('/^\s*SELECT/i', $query)) {
if ( ! preg_match('/\sFROM\s/i', $query)) {
$query .= " FROM dual";
}
if ($limit > 0) {
// taken from http://svn.ez.no/svn/ezcomponents/packages/Database
$max = $offset + $limit;
if ($offset > 0) {
$min = $offset + 1;
$query = 'SELECT * FROM (SELECT a.*, ROWNUM dctrn_rownum FROM (' . $query
. ') a WHERE ROWNUM <= ' . $max . ') WHERE dctrn_rownum >= ' . $min;
} else {
$query = 'SELECT a.* FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
}
}
}
return $query;
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string the modified query
*/
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
{
return $this->_createLimitSubquery($query, $limit, $offset);
}
private function _createLimitSubquery($query, $limit, $offset, $column = null)
{
$limit = (int) $limit;
$offset = (int) $offset;
if (preg_match('/^\s*SELECT/i', $query)) {
if ( ! preg_match('/\sFROM\s/i', $query)) {
$query .= " FROM dual";
}
if ($limit > 0) {
$max = $offset + $limit;
$column = $column === null ? '*' : $column;
if ($offset > 0) {
$min = $offset + 1;
$query = 'SELECT b.'.$column.' FROM ('.
'SELECT a.*, ROWNUM AS doctrine_rownum FROM ('
. $query . ') a '.
') b '.
'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max;
} else {
$query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
}
}
}
return $query;
}
/**
* Creates the SQL for Oracle that can be used in the subquery for the limit-subquery
* algorithm.
*/
public function modifyLimitSubquery(Doctrine_ClassMetadata $rootClass, $query, $limit = false,
$offset = false, $isManip = false)
{
// NOTE: no composite key support
$columnNames = $rootClass->getIdentifierColumnNames();
if (count($columnNames) > 1) {
throw new Doctrine_Connection_Exception("Composite keys in LIMIT queries are "
. "currently not supported.");
}
$column = $columnNames[0];
return $this->_createLimitSubquery($query, $limit, $offset, $column);
}
}
\ No newline at end of file
......@@ -25,18 +25,21 @@
*
* Some terminology:
*
* <b>New entity</b>: From the point of view of the unitOfWork is an entity that
* already has an identity but is not yet persisted into the database. This
* is usually the case for all newly saved entities that use a SEQUENCE id
* generator. Entities with an IDENTITY id generator get persisted as soon
* as they're saved in order to obtain the identifier. Therefore entities that
* use an IDENTITY id generator never appear in the list of new entities of the UoW.
* <b>New entity</b>: A new entity is an entity that already has an identity but
* is not yet persisted into the database. This is usually the case for all
* newly saved entities that use a SEQUENCE id generator. Entities with an
* IDENTITY id generator get persisted as soon as they're saved in order to
* obtain the identifier. Therefore entities that use an IDENTITY id generator
* never appear in the list of new entities of the UoW.
*
* <b>Dirty entity</b>: ...
* <b>Dirty entity</b>: A dirty entity is a managed entity whose values have
* been altered.
*
* <b>Removed entity</b>: ...
* <b>Removed entity</b>: A removed entity is a managed entity that is scheduled
* for deletion from the database.
*
* <b>Clean entity</b>: ...
* <b>Clean entity</b>: A clean entity is a managed entity that has been fetched
* from the database and whose values have not yet been altered.
*
* @package Doctrine
* @subpackage Connection
......@@ -226,7 +229,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$index = max(array_keys($tree));
}
$rels = $mapper->getTable()->getRelations();
$rels = $mapper->getClassMetadata()->getRelations();
// group relations
......@@ -355,7 +358,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
/**
* @param integer $oid object identifier
* @return boolean whether ot not the operation was successful
* @deprecated
* @deprecated The new implementation of detach() should remove the entity
* from the identity map.
*/
public function detach(Doctrine_Entity $entity)
{
......@@ -371,6 +375,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* Detaches all currently managed entities.
*
* @return integer The number of detached entities.
* @todo Deprecated. The new implementation should remove all entities from
* the identity map.
*/
public function detachAll()
{
......@@ -401,11 +407,24 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return true;
}
/**
* Enter description here...
*
* @param unknown_type $entityName
* @todo unify with detachAll()
*/
public function clearIdentitiesForEntity($entityName)
{
$this->_identityMap[$entityName] = array();
}
/**
* Removes an entity from the identity map.
*
* @param Doctrine_Entity $entity
* @return unknown
* @todo This will be the new detach().
*/
public function unregisterIdentity(Doctrine_Entity $entity)
{
$idHash = $this->getIdentifierHash($entity->identifier());
......@@ -422,6 +441,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return false;
}
/**
* Finds an entity in the identity map by its identifier hash.
*
* @param unknown_type $idHash
* @param unknown_type $rootClassName
* @return unknown
*/
public function getByIdHash($idHash, $rootClassName)
{
return $this->_identityMap[$rootClassName][$idHash];
......@@ -435,6 +461,12 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return false;
}
/**
* Gets the identifier hash for a set of identifier values.
*
* @param array $id
* @return string
*/
public function getIdentifierHash(array $id)
{
return implode(' ', $id);
......@@ -448,15 +480,22 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
*/
public function contains(Doctrine_Entity $entity)
{
$id = implode(' ', $entity->identifier());
if ( ! $id) {
$idHash = $this->getIdentifierHash($entity->identifier());
if ( ! $idHash) {
return false;
}
return isset($this->_identityMap[
$entity->getClassMetadata()->getRootClassName()
][$id]);
return isset($this->_identityMap
[$entity->getClassMetadata()->getRootClassName()]
[$idHash]);
}
/**
* Checks whether an identifier hash exists in the identity map.
*
* @param string $idHash
* @param string $rootClassName
* @return boolean
*/
public function containsIdHash($idHash, $rootClassName)
{
return isset($this->_identityMap[$rootClassName][$idHash]);
......
This diff is collapsed.
......@@ -23,6 +23,11 @@ class Doctrine_Entity_Exception extends Doctrine_Exception
return new self("Invalid value. The value of a reference in a ManyToMany "
. "association must be a Collection.");
}
public static function invalidField($field)
{
return new self("Invalid field: '$field'.");
}
}
?>
\ No newline at end of file
......@@ -35,13 +35,13 @@
class Doctrine_EntityRepository
{
protected $_entityName;
protected $_conn;
protected $_em;
protected $_classMetadata;
public function __construct($entityName, Doctrine_ClassMetadata $classMetadata)
{
$this->_entityName = $entityName;
$this->_conn = $classMetadata->getConnection();
$this->_em = $classMetadata->getConnection();
$this->_classMetadata = $classMetadata;
}
......@@ -59,7 +59,7 @@ class Doctrine_EntityRepository
if ( ! empty($alias)) {
$alias = ' ' . trim($alias);
}
return Doctrine_Query::create($this->_conn)->from($this->_entityName . $alias);
return Doctrine_Query::create($this->_em)->from($this->_entityName . $alias);
}
/**
......@@ -69,7 +69,7 @@ class Doctrine_EntityRepository
*/
public function clear()
{
$this->_conn->unitOfWork->clearIdentitiesForEntity($this->_classMetadata->getRootClassName());
$this->_em->unitOfWork->clearIdentitiesForEntity($this->_classMetadata->getRootClassName());
}
/**
......@@ -170,7 +170,7 @@ class Doctrine_EntityRepository
*/
public function findByDql($dql, array $params = array(), $hydrationMode = null)
{
$query = new Doctrine_Query($this->_conn);
$query = new Doctrine_Query($this->_em);
$component = $this->getComponentName();
$dql = 'FROM ' . $component . ' WHERE ' . $dql;
......
......@@ -63,7 +63,7 @@ abstract class Doctrine_Hydrator_Abstract
*
* @param Doctrine_Connection|null $connection
*/
public function __construct(Doctrine_Connection $em)
public function __construct(Doctrine_EntityManager $em)
{
$this->_em = $em;
$this->_nullObject = Doctrine_Null::$INSTANCE;
......
......@@ -43,7 +43,7 @@ class Doctrine_Hydrator_RecordDriver
/** The EntityManager */
private $_em;
public function __construct(Doctrine_Connection $em)
public function __construct(Doctrine_EntityManager $em)
{
$this->_nullObject = Doctrine_Null::$INSTANCE;
$this->_em = $em;
......@@ -93,7 +93,7 @@ class Doctrine_Hydrator_RecordDriver
public function getElement(array $data, $className)
{
return $this->_em->createEntity2($className, $data);
return $this->_em->createEntity($className, $data);
}
public function addRelatedIndexedElement(Doctrine_Entity $entity1, $property,
......
......@@ -375,6 +375,10 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
foreach ($data as $key => $value) {
// Parse each column name only once. Cache the results.
if ( ! isset($cache[$key])) {
// check ignored names. fastest solution for now. if we get more we'll start
// to introduce a list.
if ($key == 'doctrine_rownum') continue;
// cache general information like the column name <-> field name mapping
$e = explode('__', $key);
$columnName = strtolower(array_pop($e));
......
......@@ -680,7 +680,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/
public function getMapper($componentName)
{
return $this->getConnectionForComponent($componentName)->getMapper($componentName);
return $this->getConnectionForComponent($componentName)->getEntityPersister($componentName);
}
/**
......
......@@ -30,7 +30,6 @@
* @version $Revision: 3406 $
* @link www.phpdoctrine.org
* @since 2.0
* @todo Move all finder stuff to EntityRepository.
* @todo Rename to "EntityPersister" or similar.
*/
class Doctrine_Mapper
......@@ -69,6 +68,12 @@ class Doctrine_Mapper
*/
private $_entityListeners = array();
/**
* Enter description here...
*
* @var unknown_type
* @todo To EntityManager.
*/
private $_dataTemplate = array();
......@@ -121,6 +126,7 @@ class Doctrine_Mapper
* @param $array an array where keys are field names and
* values representing field values
* @return Doctrine_Entity the created record object
* @todo To EntityManager.
*/
public function create(array $array = array())
{
......@@ -158,24 +164,16 @@ class Doctrine_Mapper
}
}
public function detach(Doctrine_Entity $entity)
{
return $this->_conn->unitOfWork->detach($entity);
}
/**
* Executes a named query.
* Enter description here...
*
* @param string $queryName The name that was used when storing the query.
* @param array $params The query parameters.
* @return mixed The result.
* @deprecated
* @param Doctrine_Entity $entity
* @return unknown
* @todo To EntityManager
*/
public function executeNamedQuery($queryName, $params = array(), $hydrationMode = Doctrine::HYDRATE_RECORD)
public function detach(Doctrine_Entity $entity)
{
return Doctrine_Manager::getInstance()
->createNamedQuery($queryName)
->execute($params, $hydrationMode);
return $this->_conn->unitOfWork->detach($entity);
}
/**
......@@ -184,6 +182,7 @@ class Doctrine_Mapper
*
* @return void
* @todo what about a more descriptive name? clearIdentityMap?
* @todo To EntityManager
*/
public function clear()
{
......@@ -197,6 +196,7 @@ class Doctrine_Mapper
* @param Doctrine_Entity $record record to be added
* @return boolean
* @todo Better name? registerRecord? Move elsewhere to the new location of the identity maps.
* @todo Remove.
*/
public function addRecord(Doctrine_Entity $record)
{
......@@ -213,6 +213,7 @@ class Doctrine_Mapper
*
* @return boolean TRUE if the entity was previously not managed and is now managed,
* FALSE otherwise (the entity is already managed).
* @todo Remove.
*/
public function manage(Doctrine_Entity $record)
{
......@@ -244,6 +245,7 @@ class Doctrine_Mapper
* returns a new record.
*
* @return Doctrine_Entity
* @todo To EntityManager.
*/
public function getRecord(array $data)
{
......@@ -310,6 +312,7 @@ class Doctrine_Mapper
* applyInheritance
* @param $where query where part to be modified
* @return string query where part with column aggregation inheritance added
* @todo What to do with this? Remove if possible.
*/
final public function applyInheritance($where)
{
......@@ -357,6 +360,8 @@ class Doctrine_Mapper
* for the field can be skipped. Used i.e. during hydration to
* improve performance on large and/or complex results.
* @return mixed prepared value
* @todo To EntityManager. Make private and use in createEntity().
* .. Or, maybe better: Move to hydrator for performance reasons.
*/
public function prepareValue($fieldName, $value, $typeHint = null)
{
......@@ -398,43 +403,6 @@ class Doctrine_Mapper
}
return $value;
}
/**
* Hydrates the given data into the entity.
*
*/
/*public function hydrate(Doctrine_Entity $entity, array $data)
{
$this->_values = array_merge($this->_values, $this->cleanData($data));
$this->_data = array_merge($this->_data, $data);
$this->_extractIdentifier(true);
}*/
/**
* getTree
*
* getter for associated tree
*
* @return mixed if tree return instance of Doctrine_Tree, otherwise returns false
* @todo Part of the NestedSet Behavior plugin. Move outta here some day...
*/
public function getTree()
{
return $this->_classMetadata->getTree();
}
/**
* isTree
*
* determine if table acts as tree
*
* @return mixed if tree return true, otherwise returns false
* @todo Part of the NestedSet Behavior plugin. Move outta here some day...
*/
public function isTree()
{
return $this->_classMetadata->isTree();
}
/**
* getComponentName
......@@ -729,26 +697,11 @@ class Doctrine_Mapper
return true;
}
public function executeQuery(Doctrine_Query $query)
{
}
public function getTable()
{
return $this->_classMetadata;
}
public function getClassMetadata()
{
return $this->_classMetadata;
}
public function dump()
{
var_dump($this->_invokedMethods);
}
public function free()
{
$this->_mappingStrategy = null;
......@@ -759,8 +712,6 @@ class Doctrine_Mapper
return $this->_mappingStrategy;
}
public function getFieldName($columnName)
{
return $this->_mappingStrategy->getFieldName($columnName);
......
......@@ -1129,7 +1129,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$modifyLimit = true;
if ( ! empty($this->_sqlParts['limit']) || ! empty($this->_sqlParts['offset'])) {
if ($needsSubQuery) {
$subquery = $this->getLimitSubquery();
// what about composite keys?
......@@ -1138,7 +1137,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
switch (strtolower($this->_conn->getDriverName())) {
case 'mysql':
// mysql doesn't support LIMIT in subqueries
$list = $this->_conn->execute($subquery, $params)->fetchAll(Doctrine::FETCH_COLUMN);
$list = $this->_conn->execute($subquery, $params)->fetchAll(Doctrine::FETCH_COLUMN);
$subquery = implode(', ', array_map(array($this->_conn, 'quote'), $list));
break;
case 'pgsql':
......@@ -1192,18 +1191,18 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
*/
public function getLimitSubquery()
{
$map = reset($this->_queryComponents);
$table = $map['table'];
$map = reset($this->_queryComponents);
$table = $map['table'];
$componentAlias = key($this->_queryComponents);
// get short alias
$alias = $this->getTableAlias($componentAlias);
$alias = $this->getTableAlias($componentAlias);
// what about composite keys?
$idFieldNames = (array)$table->getIdentifier();
$primaryKey = $alias . '.' . $table->getColumnName($idFieldNames[0]);
// initialize the base of the subquery
$subquery = 'SELECT DISTINCT ' . $this->_conn->quoteIdentifier($primaryKey);
$subquery = 'SELECT DISTINCT ' . $this->_conn->quoteIdentifier($primaryKey);
$driverName = $this->_conn->getAttribute(Doctrine::ATTR_DRIVER_NAME);
......@@ -1261,7 +1260,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$subquery .= ( ! empty($this->_sqlParts['orderby']))? ' ORDER BY ' . implode(', ', $this->_sqlParts['orderby']) : '';
// add driver specific limit clause
$subquery = $this->_conn->modifyLimitQuery($subquery, $this->_sqlParts['limit'], $this->_sqlParts['offset']);
$subquery = $this->_conn->modifyLimitSubquery($table, $subquery, $this->_sqlParts['limit'], $this->_sqlParts['offset']);
$parts = $this->_tokenizer->quoteExplode($subquery, ' ', "'", "'");
......@@ -1643,7 +1642,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$this->_sqlParts['from'][] = $queryPart;
//echo "<br /><br />" . $table->getComponentName() . "---3---" . $name . "<br /><br />";
$this->_queryComponents[$componentAlias] = array(
'table' => $table, 'mapper' => $this->_conn->getMapper($name), 'map' => null);
'table' => $table, 'mapper' => $this->_conn->getEntityPersister($name), 'map' => null);
return $table;
}
......
......@@ -530,7 +530,7 @@ abstract class Doctrine_Query_Abstract
{
$table = $this->_conn->getMetadata($componentName);
$tableAlias = $this->getSqlTableAlias($componentAlias, $table->getTableName());
$customJoins = $this->_conn->getMapper($componentName)->getCustomJoins();
$customJoins = $this->_conn->getEntityPersister($componentName)->getCustomJoins();
$sql = '';
foreach ($customJoins as $componentName => $joinType) {
$joinedTable = $this->_conn->getMetadata($componentName);
......@@ -1051,12 +1051,12 @@ abstract class Doctrine_Query_Abstract
$e = explode('.', $components[0]);
if (count($e) === 1) {
$queryComponents[$alias]['mapper'] = $this->_conn->getMapper($e[0]);
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable();
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getClassMetadata();
} else {
$queryComponents[$alias]['parent'] = $e[0];
$queryComponents[$alias]['relation'] = $queryComponents[$e[0]]['table']->getRelation($e[1]);
$queryComponents[$alias]['mapper'] = $this->_conn->getMapper($queryComponents[$alias]['relation']->getForeignComponentName());
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable();
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getClassMetadata();
}
if (isset($components[1])) {
$queryComponents[$alias]['agg'] = $components[1];
......
......@@ -154,7 +154,7 @@ abstract class Doctrine_Relation implements ArrayAccess
}
}
$this->definition = $def;
$this->_foreignMapper = $this->getTable()->getConnection()->getMapper($def['class']);
$this->_foreignMapper = $this->getTable()->getConnection()->getEntityPersister($def['class']);
}
/**
......@@ -257,9 +257,8 @@ abstract class Doctrine_Relation implements ArrayAccess
*/
final public function getTable()
{
return Doctrine_Manager::getInstance()
->getConnectionForComponent($this->definition['class'])
->getMetadata($this->definition['class']);
return Doctrine_EntityManager::getManager($this->definition['class'])
->getClassMetadata($this->definition['class']);
}
/**
......
......@@ -271,7 +271,7 @@ class Doctrine_Relation_Parser
*/
public function getImpl(array &$def, $key)
{
$conn = $this->_table->getConnection();
$em = $this->_table->getEntityManager();
if (in_array('Doctrine_Template', class_parents($def[$key]))) {
$impl = $this->_table->getImpl($def[$key]);
if ($impl === null) {
......@@ -280,7 +280,7 @@ class Doctrine_Relation_Parser
$def[$key] = $impl;
}
return $conn->getMetadata($def[$key]);
return $em->getClassMetadata($def[$key]);
}
protected function _isTemplate($className)
......
......@@ -41,6 +41,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
public function setUp()
{
parent::setUp();
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->user = new ForumUser();
}
......@@ -57,10 +58,10 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/**
* @test
*/
public function shouldMarkExistingFieldAsSetOnNewRecord()
public function shouldMarkEmptyFieldAsNotSetOnNewRecord()
{
$this->assertTrue(isset($this->user->username));
$this->assertTrue(isset($this->user['username']));
$this->assertFalse(isset($this->user->username));
$this->assertFalse(isset($this->user['username']));
}
/**
......@@ -113,7 +114,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/**
* @test
* @expectedException Doctrine_Record_Exception
* @expectedException Doctrine_Entity_Exception
*/
public function shouldNotBeAbleToSetNonExistantField()
{
......@@ -122,7 +123,7 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/**
* @test
* @expectedException Doctrine_Record_Exception
* @expectedException Doctrine_Entity_Exception
*/
public function shouldNotBeAbleToSetNonExistantFieldWithOffset()
{
......@@ -131,14 +132,13 @@ class Orm_Component_AccessTest extends Doctrine_OrmTestCase
/**
* @test
* @expectedException Doctrine_Record_Exception
* @expectedException Doctrine_Entity_Exception
*/
public function shouldNotBeAbleToSetNonExistantFieldAsPartInSetArray()
{
$this->user->setArray(array(
'rat' => 'meus',
'id' => 22));
}
......
......@@ -6,7 +6,6 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
require_once 'lib/DoctrineTestInit.php';
// Tests
require_once 'Orm/Component/TestTest.php';
require_once 'Orm/Component/AccessTest.php';
require_once 'Orm/Component/CollectionTest.php';
......@@ -21,7 +20,6 @@ class Orm_Component_AllTests
{
$suite = new Doctrine_TestSuite('Doctrine Orm Component');
$suite->addTestSuite('Orm_Component_TestTest');
$suite->addTestSuite('Orm_Component_AccessTest');
$suite->addTestSuite('Orm_Component_CollectionTest');
......
......@@ -40,6 +40,8 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase
public function setUp()
{
parent::setUp();
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->coll = new Doctrine_Collection('ForumUser');
//we create a CmsUser with username as key column and add a user to it
......
<?php
require_once 'lib/DoctrineTestInit.php';
class Orm_Component_TestTest extends Doctrine_OrmTestCase
{
protected function setUp()
{
parent::setUp();
$this->loadFixtures('forum', 'common', array('users', 'admins'));
}
public function testTest()
{
$this->assertEquals(0, 0);
}
public function testFixture()
{
$forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u");
$this->assertEquals(2, count($forumUsers));
$forumUsers[0]->delete();
unset($forumUsers[0]);
$this->assertEquals(1, count($forumUsers));
}
public function testFixture2()
{
$forumUsers = $this->sharedFixture['connection']->query("FROM ForumUser u");
$this->assertEquals(2, count($forumUsers));
}
public function testFixture3()
{
$forumAdmins = $this->sharedFixture['connection']->query("FROM ForumAdministrator adm");
$this->assertEquals(1, count($forumAdmins));
$forumAdmins[0]->delete();
}
}
\ No newline at end of file
<?php
require_once 'lib/DoctrineTestInit.php';
class Orm_EntityManagerTest extends Doctrine_OrmTestCase
{
protected function setUp() {
parent::setUp();
}
protected function tearDown() {
Doctrine_EntityManager::unbindAllManagers();
Doctrine_EntityManager::releaseAllManagers();
parent::tearDown();
}
public function testInstantiationRegistersInstanceInStaticMap()
{
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->assertSame($em, Doctrine_EntityManager::getManager('SomeEntity'));
}
public function testStaticGetManagerThrowsExceptionIfNoManagerAvailable()
{
try {
Doctrine_EntityManager::getManager('SomeEntity');
$this->fail("Expected exception not thrown.");
} catch (Doctrine_EntityManager_Exception $ex) {}
}
public function testBindingValidEntityToNamedManager()
{
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock(null), 'myEM');
Doctrine_EntityManager::bindEntityToManager('SomeEntity', 'myEM');
$this->assertSame($em, Doctrine_EntityManager::getManager('SomeEntity'));
}
public function testBindingEntityToInvalidManagerThrowsExceptionOnRetrieval()
{
// will work. we don't check the existence of the EM during binding
Doctrine_EntityManager::bindEntityToManager('SomeEntity', 'myEM');
// exception on access
try {
Doctrine_EntityManager::getManager('SomeEntity');
$this->fail();
} catch (Doctrine_EntityManager_Exception $ex) {}
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -8,8 +8,9 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase
protected function setUp() {
parent::setUp();
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->_user = new ForumUser();
$this->_unitOfWork = $this->sharedFixture['connection']->unitOfWork;
$this->_unitOfWork = $em->getUnitOfWork();
}
protected function tearDown() {
......
......@@ -5,8 +5,10 @@ require_once 'Doctrine_TestCase.php';
require_once 'Doctrine_TestUtil.php';
require_once 'Doctrine_DbalTestCase.php';
require_once 'Doctrine_OrmTestCase.php';
require_once 'Doctrine_OrmFunctionalTestCase.php';
require_once 'Doctrine_TestSuite.php';
require_once 'Doctrine_OrmTestSuite.php';
require_once 'Doctrine_OrmFunctionalTestSuite.php';
require_once 'Doctrine_DbalTestSuite.php';
require_once '../lib/Doctrine.php';
......
......@@ -5,118 +5,5 @@
*/
class Doctrine_OrmTestCase extends Doctrine_TestCase
{
/**
* The currently loaded model names of the fixtures for the testcase.
*/
private $_loadedFixtures = array();
/**
* All loaded fixtures during test execution. Common fixture cache.
*/
private static $_fixtures = array();
/**
* The names of all tables that were already exported. Each table is exported
* only once. Then it's just filled & erased for each testmethod in a testcase
* that uses one or more fixtures.
*/
private static $_exportedTables = array();
/**
* setUp()
*
* Note: This setUp() and the one of DbalTestCase currently look identical. However,
* please dont pull this method up. In the future with a separation of Dbal/Orm
* this setUp() will take care of a ORM connection/session/manager initialization
* and the DBAL setUp() will take care of just a DBAL connection.
*/
protected function setUp()
{
// Setup a db connection if there is none, yet. This makes it possible
// to run tests that use a connection standalone.
if ( ! isset($this->sharedFixture['connection'])) {
$this->sharedFixture['connection'] = Doctrine_TestUtil::getConnection();
}
}
/**
* Loads a data fixture into the database. This method must only be called
* from within the setUp() method of testcases. The database will then be
* populated with fresh data of all loaded fixtures for each test method.
*
* WARNING: A single testcase should never load fixtures from different scenarios of
* the same package as the concistency and uniqueness of keys is not guaranteed.
*
* @param string $package The package name. Must be one of Doctrine's test model packages
* (forum, cms or ecommerce).
* @param string $scenario The fixture scenario. A model package can have many fixture
* scenarios. Within a scenario all primary keys and foreign keys
* of fixtures are consistent and unique.
* @param string $name The name of the fixture to load from the specified package.
*/
protected function loadFixture($package, $scenario, $name)
{
$uniqueName = $package . '/' . $scenario . '/' . $name;
if ( ! isset(self::$_fixtures[$uniqueName])) {
// load fixture file
$fixtureFile = 'fixtures'
. DIRECTORY_SEPARATOR . $package
. DIRECTORY_SEPARATOR . $scenario
. DIRECTORY_SEPARATOR . $name
. '.php';
require $fixtureFile;
self::$_fixtures[$uniqueName] = $fixture;
}
$fixture = self::$_fixtures[$uniqueName];
$this->_loadedFixtures[] = $fixture['model'];
$conn = $this->sharedFixture['connection'];
$classMetadata = $conn->getClassMetadata($fixture['model']);
$tableName = $classMetadata->getTableName();
if ( ! in_array($tableName, self::$_exportedTables)) {
$conn->export->exportClasses(array($fixture['model']));
self::$_exportedTables[] = $tableName;
}
foreach ($fixture['rows'] as $row) {
$conn->insert($tableName, $row);
}
}
/**
* Loads multiple fixtures of the same package and scenario.
* This method must only be called from within the setUp() method of testcases.
* The database will then be populated with fresh data of all loaded fixtures for each
* test method.
*
* WARNING: A single testcase should never load fixtures from different scenarios of
* the same package as the concistency and uniqueness of keys is not guaranteed.
*
* @param string $package The package name. Must be one of Doctrine's test model packages
* (forum, cms or ecommerce).
* @param string $scenario The fixture scenario. A model package can have many fixture
* scenarios. Within a scenario all primary keys and foreign keys
* of fixtures are consistent and unique.
* @param array $names The names of the fixtures to load from the specified package.
*/
protected function loadFixtures($package, $scenario, array $names)
{
foreach ($names as $name) {
$this->loadFixture($package, $scenario, $name);
}
}
/**
* Sweeps the database tables of all used fixtures.
*/
protected function tearDown()
{
$conn = $this->sharedFixture['connection'];
foreach (array_reverse($this->_loadedFixtures) as $model) {
$conn->exec("DELETE FROM " . $conn->getClassMetadata($model)->getTableName());
}
}
}
\ No newline at end of file
......@@ -8,11 +8,5 @@
*/
class Doctrine_OrmTestSuite extends Doctrine_TestSuite
{
protected function setUp()
{
$this->sharedFixture['connection'] = Doctrine_TestUtil::getConnection();
}
protected function tearDown()
{}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ class CmsUser extends Doctrine_Entity
public static function initMetadata($class)
{
$class->mapColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
$class->mapColumn('status', 'string', 50);
$class->mapColumn('username', 'string', 255);
$class->mapColumn('name', 'string', 255);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment