Commit 71ed9242 authored by romanb's avatar romanb

refactorings

parent d3a26152
......@@ -55,7 +55,7 @@ final class Doctrine
/**
* VERSION
*/
const VERSION = '1.0.0';
const VERSION = '2.0.0';
/**
* ERROR CONSTANTS
......@@ -171,46 +171,48 @@ final class Doctrine
* Doctrine constants
*/
const ATTR_LISTENER = 100;
const ATTR_QUOTE_IDENTIFIER = 101;
const ATTR_FIELD_CASE = 102;
const ATTR_IDXNAME_FORMAT = 103;
const ATTR_SEQNAME_FORMAT = 104;
const ATTR_SEQCOL_NAME = 105;
const ATTR_CMPNAME_FORMAT = 118;
const ATTR_DBNAME_FORMAT = 117;
const ATTR_TBLCLASS_FORMAT = 119;
const ATTR_TBLNAME_FORMAT = 120;
const ATTR_EXPORT = 140;
const ATTR_DECIMAL_PLACES = 141;
const ATTR_PORTABILITY = 106;
const ATTR_VALIDATE = 107;
const ATTR_COLL_KEY = 108;
const ATTR_QUERY_LIMIT = 109;
const ATTR_DEFAULT_TABLE_TYPE = 112;
const ATTR_DEF_TEXT_LENGTH = 113;
const ATTR_DEF_VARCHAR_LENGTH = 114;
const ATTR_DEF_TABLESPACE = 115;
const ATTR_EMULATE_DATABASE = 116;
const ATTR_USE_NATIVE_ENUM = 117;
const ATTR_DEFAULT_SEQUENCE = 133;
const ATTR_FETCHMODE = 118;
const ATTR_NAME_PREFIX = 121;
const ATTR_CREATE_TABLES = 122;
const ATTR_COLL_LIMIT = 123;
const ATTR_CACHE = 150;
const ATTR_RESULT_CACHE = 150;
const ATTR_CACHE_LIFESPAN = 151;
const ATTR_RESULT_CACHE_LIFESPAN = 151;
const ATTR_LOAD_REFERENCES = 153;
const ATTR_QUOTE_IDENTIFIER = 101; // manager/session attribute
const ATTR_FIELD_CASE = 102; // manager/session attribute
const ATTR_IDXNAME_FORMAT = 103; // manager/session attribute
const ATTR_SEQNAME_FORMAT = 104; // manager/session attribute
const ATTR_SEQCOL_NAME = 105; // class attribute
const ATTR_CMPNAME_FORMAT = 118; // ??
const ATTR_DBNAME_FORMAT = 117; // manager/session attribute
const ATTR_TBLCLASS_FORMAT = 119; // manager/session attribute
const ATTR_TBLNAME_FORMAT = 120; // manager/session attribute
const ATTR_EXPORT = 140; // manager/session attribute
const ATTR_DECIMAL_PLACES = 141; // manager/session attribute
const ATTR_PORTABILITY = 106; // manager/session attribute
const ATTR_VALIDATE = 107; // manager/session attribute
const ATTR_COLL_KEY = 108; // class attribute
const ATTR_QUERY_LIMIT = 109; // manager/session attribute
const ATTR_DEFAULT_TABLE_TYPE = 112; // manager/session attribute
const ATTR_DEF_TEXT_LENGTH = 113; // manager/session attribute
const ATTR_DEF_VARCHAR_LENGTH = 114; // manager/session attribute
const ATTR_DEF_TABLESPACE = 115; // manager/session attribute
const ATTR_EMULATE_DATABASE = 116; // manager/session attribute
const ATTR_USE_NATIVE_ENUM = 117; // manager/session attribute
const ATTR_DEFAULT_SEQUENCE = 133; // ??
const ATTR_FETCHMODE = 118; // deprecated
const ATTR_NAME_PREFIX = 121; // ??
const ATTR_CREATE_TABLES = 122; // manager/session attribute
const ATTR_COLL_LIMIT = 123; // manager/session attribute
const ATTR_CACHE = 150; // deprecated
const ATTR_RESULT_CACHE = 150; // manager/session attribute
const ATTR_CACHE_LIFESPAN = 151; // deprecated
const ATTR_RESULT_CACHE_LIFESPAN = 151; // manager/session attribute
const ATTR_LOAD_REFERENCES = 153; // class attribute
const ATTR_RECORD_LISTENER = 154;
const ATTR_THROW_EXCEPTIONS = 155;
const ATTR_DEFAULT_PARAM_NAMESPACE = 156;
const ATTR_QUERY_CACHE = 157;
const ATTR_QUERY_CACHE_LIFESPAN = 158;
const ATTR_MODEL_LOADING = 161;
const ATTR_LOCK = 162;
const ATTR_HYDRATE = 163;
const ATTR_IDENTIFIER = 164;
const ATTR_THROW_EXCEPTIONS = 155; // manager/session attribute
const ATTR_DEFAULT_PARAM_NAMESPACE = 156; // ??
const ATTR_QUERY_CACHE = 157; // manager/session attribute
const ATTR_QUERY_CACHE_LIFESPAN = 158; // manager/session attribute
const ATTR_MODEL_LOADING = 161; // manager/session attribute
const ATTR_LOCK = 162; // ??
const ATTR_HYDRATE = 163; // ??
const ATTR_IDENTIFIER = 164; // ??
const ATTR_METADATA_CACHE = 165; // manager/session attribute
const ATTR_METADATA_CACHE_LIFESPAN = 166; // manager/session attribute
/**
* QUERY_LIMIT CONSTANTS
......@@ -281,6 +283,7 @@ final class Doctrine
* FETCHMODE_VHOLDER
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_VHOLDER = 1;
......@@ -293,6 +296,7 @@ final class Doctrine
* This is the default fetchmode.
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_RECORD = 2;
......@@ -300,6 +304,7 @@ final class Doctrine
* FETCHMODE_ARRAY
*
* @see self::ATTR_FETCHMODE
* @deprecated???
*/
const FETCHMODE_ARRAY = 3;
......@@ -493,6 +498,7 @@ final class Doctrine
* VALIDATE_CONSTRAINTS
*
* @see self::ATTR_VALIDATE
* Not used? Purpose?
*/
const VALIDATE_CONSTRAINTS = 4;
......@@ -557,7 +563,7 @@ final class Doctrine
*
* @see self::ATTR_MODEL_LOADING
*/
const MODEL_LOADING_CONSERVATIVE= 2;
const MODEL_LOADING_CONSERVATIVE = 2;
/**
* INHERITANCE TYPE CONSTANTS.
......@@ -583,7 +589,7 @@ final class Doctrine
* @see http://martinfowler.com/eaaCatalog/concreteTableInheritance.html
*/
const INHERITANCETYPE_TABLE_PER_CLASS = 3;
/**
* Path
......@@ -763,8 +769,7 @@ final class Doctrine
// - not a subclass of Doctrine_Record
// - don't have a setTableDefinition method
if (!$class->isAbstract() &&
$class->isSubClassOf('Doctrine_Record') &&
$class->hasMethod('setTableDefinition')) {
$class->isSubClassOf('Doctrine_Record')) {
return true;
}
......
......@@ -20,8 +20,8 @@
*/
/**
* A <tt>ClassMetadata</tt> instance holds all the information (metadata) of an entity and it's relations.
* These informations are used for the proper object-relational mapping of the class.
* A <tt>ClassMetadata</tt> instance holds all the information (metadata) of an entity and
* it's associations and how they're mapped to the relational model.
*
* @package Doctrine
* @subpackage ClassMetadata
......@@ -48,6 +48,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* The name of the custom mapper class used for the entity class.
* (Optional).
*
* @var string
*/
......@@ -60,7 +61,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
protected $_conn;
/**
* The names of the parent classes.
* The names of the parent classes (ancestors).
*/
protected $_parentClasses = array();
......@@ -75,13 +76,14 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* The identifier type of the class.
*
* @see Doctrine_Identifier constants
* @see Doctrine::IDENTIFIER_* constants
* @var integer
*/
protected $_identifierType;
/**
* The inheritance mapping type used by the class.
*
*
* @var integer
*/
......@@ -115,9 +117,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* The mapped columns and their mapping definitions.
* Keys are column names and values are definitions.
* Keys are column names and values are mapping definitions.
*
* The definition array has atleast the following values:
* The mapping definition array has at least the following values:
*
* -- type the column type, eg. 'integer'
* -- length the column length, eg. 11
......@@ -156,11 +158,6 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
protected $_enumValues = array();
/**
* @todo Implementation.
*/
protected $_readOnlyFieldNames = array();
/**
* Tree object associated with the class.
*
......@@ -219,8 +216,10 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* Inheritance options.
*/
protected $_inheritanceOptions = array(
// JOINED & TABLE_PER_CLASS options
'discriminatorColumn' => null,
'discriminatorMap' => array(),
// JOINED options
'joinSubclasses' => true
);
......@@ -261,9 +260,9 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* Constructs a new metadata instance.
* Constructs a new ClassMetadata instance.
*
* @param string $domainClassName Name of the class the metadata instance is used for.
* @param string $entityName Name of the entity class the metadata info is used for.
*/
public function __construct($entityName, Doctrine_Connection $conn)
{
......@@ -272,7 +271,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
$this->_conn = $conn;
$this->_parser = new Doctrine_Relation_Parser($this);
$this->_filters[] = new Doctrine_Record_Filter_Standard();
$this->setParent($this->_conn);
$this->setConfigurableParent($this->_conn);
}
/**
......@@ -286,13 +285,20 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* getComponentName
*
* @return void
* @return string
*/
public function getClassName()
{
return $this->_entityName;
}
/**
* Gets the name of the root class of the entity hierarchy. If the entity described
* by the ClassMetadata is not participating in a hierarchy, this is the same as the
* name returned by {@link getClassName()}.
*
* @return string
*/
public function getRootClassName()
{
return $this->_rootEntityName;
......@@ -315,7 +321,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
public function isIdentifier($fieldName)
{
return in_array($fieldName, (array)$this->getIdentifier());
return in_array($fieldName, $this->getIdentifier());
}
/**
......@@ -353,10 +359,11 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
* @param string $name the name of the option to set
* @param mixed $value the value of the option
* @return Doctrine_Table this object
* @deprecated
*/
public function setOption($name, $value)
{
switch ($name) {
/*switch ($name) {
case 'tableName':
case 'index':
case 'sequenceName':
......@@ -368,7 +375,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
case 'enumMap':
$this->_enumMap = $value;
return;
}
}*/
$this->_options[$name] = $value;
}
......@@ -457,11 +464,8 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/
public function getColumnName($fieldName)
{
if (isset($this->_columnNames[$fieldName])) {
return $this->_columnNames[$fieldName];
}
return $fieldName;
return isset($this->_columnNames[$fieldName]) ?
$this->_columnNames[$fieldName] : $fieldName;
}
/**
......@@ -481,21 +485,21 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
/**
* getFieldName
*
* returns a column alias for a column name
* if no alias can be found the column name is returned.
* returns the field name for a column name
* if no field name can be found the column name is returned.
*
* @param string $columnName column name
* @return string column alias
*/
public function getFieldName($columnName)
{
if (isset($this->_fieldNames[$columnName])) {
return $this->_fieldNames[$columnName];
}
return $columnName;
return isset($this->_fieldNames[$columnName]) ?
$this->_fieldNames[$columnName] : $columnName;
}
/**
* @deprecated
*/
public function setColumns(array $definitions)
{
foreach ($definitions as $name => $options) {
......@@ -1792,6 +1796,21 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this;
}
public function hasAttribute($key)
{
switch ($key) {
case Doctrine::ATTR_SEQCOL_NAME:
case Doctrine::ATTR_COLL_KEY:
case Doctrine::ATTR_LOAD_REFERENCES:
case Doctrine::ATTR_EXPORT:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_VALIDATE:
return true;
default:
return false;
}
}
/**
......
......@@ -20,9 +20,9 @@
*/
Doctrine::autoload('Doctrine_Access');
/**
* A Doctrine_Collection represents a collection of record objects.
* A Doctrine_Collection represents a collection of entities.
* A collection object is strongly typed in the sense that it can only contain
* records of a specific type or one it's subtypes.
* entities of a specific type or one it's subtypes.
*
* @package Doctrine
* @subpackage Collection
......@@ -113,7 +113,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
if ($keyColumn === null) {
$keyColumn = $mapper->getAttribute(Doctrine::ATTR_COLL_KEY);
$keyColumn = $mapper->getClassMetadata()->getAttribute(Doctrine::ATTR_COLL_KEY);
}
if ($keyColumn !== null) {
......
This diff is collapsed.
......@@ -53,6 +53,9 @@ Doctrine::autoload('Doctrine_Configurable');
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (MDB2 library)
* @author Roman Borschel <roman@code-factory.org>
* @todo Split up into Doctrine::DBAL::Connection & Doctrine::ORM::EntityManager.
* Doctrine::DBAL::Connection must have no dependencies on ORM components since
* it sits one layer below.
*/
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate
{
......@@ -229,7 +232,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
$this->setParent($manager);
$this->setConfigurableParent($manager);
$this->setAttribute(Doctrine::ATTR_CASE, Doctrine::CASE_NATURAL);
$this->setAttribute(Doctrine::ATTR_ERRMODE, Doctrine::ERRMODE_EXCEPTION);
......@@ -275,10 +278,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function getAttribute($attribute)
{
if ($attribute >= 100) {
if ( ! isset($this->attributes[$attribute])) {
if ( ! isset($this->_attributes[$attribute])) {
return parent::getAttribute($attribute);
}
return $this->attributes[$attribute];
return $this->_attributes[$attribute];
}
if ($this->isConnected) {
......@@ -1563,4 +1566,48 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
return Doctrine_Lib::getConnectionAsString($this);
}
public function hasAttribute($key)
{
switch ($key) {
case Doctrine::ATTR_COLL_KEY:
case Doctrine::ATTR_LISTENER:
case Doctrine::ATTR_RECORD_LISTENER:
case Doctrine::ATTR_QUOTE_IDENTIFIER:
case Doctrine::ATTR_SEQCOL_NAME:
case Doctrine::ATTR_FIELD_CASE:
case Doctrine::ATTR_IDXNAME_FORMAT:
case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_DBNAME_FORMAT:
case Doctrine::ATTR_TBLCLASS_FORMAT:
case Doctrine::ATTR_TBLNAME_FORMAT:
case Doctrine::ATTR_EXPORT:
case Doctrine::ATTR_DECIMAL_PLACES:
case Doctrine::ATTR_PORTABILITY:
case Doctrine::ATTR_VALIDATE:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
case Doctrine::ATTR_DEF_TEXT_LENGTH:
case Doctrine::ATTR_DEF_VARCHAR_LENGTH:
case Doctrine::ATTR_DEF_TABLESPACE:
case Doctrine::ATTR_EMULATE_DATABASE:
case Doctrine::ATTR_USE_NATIVE_ENUM:
case Doctrine::ATTR_CREATE_TABLES:
case Doctrine::ATTR_COLL_LIMIT:
case Doctrine::ATTR_CACHE: // deprecated
case Doctrine::ATTR_RESULT_CACHE:
case Doctrine::ATTR_CACHE_LIFESPAN: // deprecated
case Doctrine::ATTR_RESULT_CACHE_LIFESPAN:
case Doctrine::ATTR_LOAD_REFERENCES:
case Doctrine::ATTR_THROW_EXCEPTIONS:
case Doctrine::ATTR_QUERY_CACHE:
case Doctrine::ATTR_QUERY_CACHE_LIFESPAN:
case Doctrine::ATTR_MODEL_LOADING:
case Doctrine::ATTR_METADATA_CACHE:
case Doctrine::ATTR_METADATA_CACHE_LIFESPAN:
return true;
default:
return false;
}
}
}
......@@ -38,8 +38,9 @@ class Doctrine_Connection_Common extends Doctrine_Connection
* @param string $query
* @param mixed $limit
* @param mixed $offset
* @todo 4th parameter not used? Remove?
*/
public function modifyLimitQuery($query, $limit = false,$offset = false,$isManip=false)
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
{
$limit = (int) $limit;
$offset = (int) $offset;
......
......@@ -106,9 +106,9 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// Initialize
foreach ($this->_queryComponents as $dqlAlias => $component) {
// disable lazy-loading of related elements during hydration
$component['mapper']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
$component['table']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
$componentName = $component['mapper']->getComponentName();
$listeners[$componentName] = $component['mapper']->getRecordListener();
$listeners[$componentName] = $component['table']->getRecordListener();
$identifierMap[$dqlAlias] = array();
$prev[$dqlAlias] = array();
$id[$dqlAlias] = '';
......@@ -121,7 +121,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
$rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents);
//
// hydrate the data of the root component from the current row
// hydrate the data of the root entity from the current row
//
$table = $this->_queryComponents[$rootAlias]['table'];
$mapper = $this->_queryComponents[$rootAlias]['mapper'];
......@@ -162,9 +162,10 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// $prev[$rootAlias] now points to the last element in $result.
// now hydrate the rest of the data found in the current row, that belongs to other
// (related) components.
$oneToOne = false;
foreach ($rowData as $dqlAlias => $data) {
$index = false;
$oneToOne = false;
$map = $this->_queryComponents[$dqlAlias];
$table = $map['table'];
$mapper = $map['mapper'];
......@@ -181,7 +182,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
$path = $parent . '.' . $dqlAlias;
if ( ! isset($prev[$parent])) {
break;
continue;
}
// check the type of the relation
......@@ -232,7 +233,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// re-enable lazy loading
foreach ($this->_queryComponents as $dqlAlias => $data) {
$data['mapper']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, true);
$data['table']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, true);
}
//$e = microtime(true);
......
......@@ -122,11 +122,57 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
}
return false;
}
public function hasAttribute($key)
{
switch ($key) {
case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE:
case Doctrine::ATTR_COLL_KEY:
case Doctrine::ATTR_SEQCOL_NAME:
case Doctrine::ATTR_LISTENER:
case Doctrine::ATTR_RECORD_LISTENER:
case Doctrine::ATTR_QUOTE_IDENTIFIER:
case Doctrine::ATTR_FIELD_CASE:
case Doctrine::ATTR_IDXNAME_FORMAT:
case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_DBNAME_FORMAT:
case Doctrine::ATTR_TBLCLASS_FORMAT:
case Doctrine::ATTR_TBLNAME_FORMAT:
case Doctrine::ATTR_EXPORT:
case Doctrine::ATTR_DECIMAL_PLACES:
case Doctrine::ATTR_PORTABILITY:
case Doctrine::ATTR_VALIDATE:
case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
case Doctrine::ATTR_DEF_TEXT_LENGTH:
case Doctrine::ATTR_DEF_VARCHAR_LENGTH:
case Doctrine::ATTR_DEF_TABLESPACE:
case Doctrine::ATTR_EMULATE_DATABASE:
case Doctrine::ATTR_USE_NATIVE_ENUM:
case Doctrine::ATTR_CREATE_TABLES:
case Doctrine::ATTR_COLL_LIMIT:
case Doctrine::ATTR_CACHE: // deprecated
case Doctrine::ATTR_RESULT_CACHE:
case Doctrine::ATTR_CACHE_LIFESPAN: // deprecated
case Doctrine::ATTR_RESULT_CACHE_LIFESPAN:
case Doctrine::ATTR_LOAD_REFERENCES:
case Doctrine::ATTR_THROW_EXCEPTIONS:
case Doctrine::ATTR_QUERY_CACHE:
case Doctrine::ATTR_QUERY_CACHE_LIFESPAN:
case Doctrine::ATTR_MODEL_LOADING:
case Doctrine::ATTR_METADATA_CACHE:
case Doctrine::ATTR_METADATA_CACHE_LIFESPAN:
return true;
default:
return false;
}
}
/**
* returns the root directory of Doctrine
*
* @return string
* @todo Better name.
*/
final public function getRoot()
{
......
This diff is collapsed.
......@@ -238,15 +238,7 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
return $this->_columnNameFieldNameMap[$columnName];
}
foreach ($classMetadata->getParentClasses() as $parentClass) {
$parentTable = $conn->getClassMetadata($parentClass);
if ($parentTable->hasColumn($columnName)) {
$this->_columnNameFieldNameMap[$columnName] = $parentTable->getFieldName($columnName);
return $this->_columnNameFieldNameMap[$columnName];
}
}
foreach ((array)$classMetadata->getSubclasses() as $subClass) {
foreach ($classMetadata->getSubclasses() as $subClass) {
$subTable = $conn->getClassMetadata($subClass);
if ($subTable->hasColumn($columnName)) {
$this->_columnNameFieldNameMap[$columnName] = $subTable->getFieldName($columnName);
......@@ -261,7 +253,7 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
*
* @todo Looks like this better belongs into the ClassMetadata class.
*/
public function getOwningTable($fieldName)
public function getOwningClass($fieldName)
{
$conn = $this->_mapper->getConnection();
$classMetadata = $this->_mapper->getClassMetadata();
......@@ -283,13 +275,14 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
}
}
throw new Doctrine_Mapper_Exception("Unable to find owner of field '$fieldName'.");
throw new Doctrine_Mapper_Exception("Unable to find defining class of field '$fieldName'.");
}
/**
* Analyzes the fields of the entity and creates a map in which the field names
* are grouped by the class names they belong to.
*
* @return array
*/
protected function _groupFieldsByDefiningClass(Doctrine_Record $record)
{
......
......@@ -90,7 +90,7 @@ abstract class Doctrine_Mapper_Strategy
return $this->_fieldNames;
}
public function getOwningTable($fieldName)
public function getOwningClass($fieldName)
{
return $this->_mapper->getClassMetadata();
}
......
......@@ -34,7 +34,18 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
final class Doctrine_Null
{
{
private static $_instance;
public function __construct() {}
public static function getInstance()
{
if (is_null(self::$_instance)) {
self::$_instance = new Doctrine_Null();
}
return self::$_instance;
}
public function exists()
{
return false;
......
......@@ -470,7 +470,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$sql = array();
foreach ($fields as $fieldName) {
$table = $mapper->getOwningTable($fieldName);
$table = $mapper->getOwningClass($fieldName);
if ($table !== $baseTable) {
$tableAlias = $this->getSqlTableAlias($componentAlias . '.' . $table->getComponentName());
} else {
......
This diff is collapsed.
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Access');
/**
* Doctrine_Record_Abstract
*
* @package Doctrine
* @subpackage Record
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
*/
abstract class Doctrine_Record_Abstract extends Doctrine_Access
{
/**
* The metadata container that describes the entity class.
*
* @param Doctrine_ClassMetadata
*/
protected $_table;
/**
*
* @var Doctrine_Mapper
*/
protected $_mapper;
/**
* @deprecated
*/
public function setTableDefinition()
{}
/**
* @deprecated
*/
public function setUp()
{}
/**
* getTable
* returns the table object for this record
*
* @return Doctrine_Table a Doctrine_Table object
* @deprecated
*/
public function getTable()
{
return $this->getClassMetadata();
}
/**
* Gets the ClassMetadata object that describes the entity class.
*/
public function getClassMetadata()
{
return $this->_table;
}
/**
* Returns the mapper of the entity.
*
* @return Doctrine_Mapper
*/
public function getMapper()
{
return $this->_mapper;
}
/**
* addListener
*
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_Record
*/
public function addListener($listener, $name = null)
{
$this->_table->addRecordListener($listener, $name = null);
return $this;
}
/**
* getListener
*
* @return Doctrine_EventListener_Interface|Doctrine_Overloadable
*/
public function getListener()
{
return $this->_table->getRecordListener();
}
/**
* setListener
*
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_Record
*/
public function setListener($listener)
{
$this->_table->setRecordListener($listener);
return $this;
}
public function setAttribute($attr, $value)
{
$this->_table->setAttribute($attr, $value);
}
/**
* attribute
* sets or retrieves an option
*
* @see Doctrine::ATTR_* constants availible attributes
* @param mixed $attr
* @param mixed $value
* @return mixed
*/
public function attribute($attr, $value)
{
if ($value == null) {
if (is_array($attr)) {
foreach ($attr as $k => $v) {
$this->_table->setAttribute($k, $v);
}
} else {
return $this->_table->getAttribute($attr);
}
} else {
$this->_table->setAttribute($attr, $value);
}
}
}
......@@ -97,7 +97,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
$id = $record->getIncremented();
//var_dump($id);
//echo "<br /><br />";
if (empty($id) || ! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
if (empty($id) || ! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
//echo "here" . $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES);
$coll = new Doctrine_Collection($this->getForeignComponentName());
} else {
......
......@@ -55,7 +55,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
if ($this->isOneToOne()) {
if ( ! $record->exists() || empty($id) ||
! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->_foreignMapper->create();
} else {
$dql = 'FROM ' . $this->_foreignMapper->getComponentName()
......@@ -69,7 +69,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
$record, false);
} else {
if ( ! $record->exists() || empty($id) ||
! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = new Doctrine_Collection($this->_foreignMapper->getComponentName());
} else {
$query = $this->getRelationDql(1);
......
......@@ -46,7 +46,7 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation
$localFieldName = $record->getTable()->getFieldName($this->definition['local']);
$id = $record->get($localFieldName);
if (empty($id) || ! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
if (empty($id) || ! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->_foreignMapper->create();
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName()
......
......@@ -105,7 +105,7 @@ class Doctrine_Relation_Nest extends Doctrine_Relation_Association
$id = $record->getIncremented();
if (empty($id) || ! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
if (empty($id) || ! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
return new Doctrine_Collection($this->getForeignComponentName());
} else {
......
This diff is collapsed.
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Record_Abstract');
/**
* Doctrine_Template
*
......@@ -30,7 +30,7 @@ Doctrine::autoload('Doctrine_Record_Abstract');
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Template extends Doctrine_Record_Abstract
class Doctrine_Template
{
/**
* @param Doctrine_Record $_invoker the record that invoked the last delegated call
......
......@@ -160,7 +160,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
* get the current transaction nesting level
*
* @return integer
* @todo Name suggestion: getLevel(). $transaction->getTransactionLevel() looks odd.
* @todo Name suggestion: getNestingLevel(). $transaction->getTransactionLevel() looks odd.
*/
public function getTransactionLevel()
{
......
......@@ -9,6 +9,7 @@ require_once 'lib/DoctrineTestInit.php';
require_once 'Orm/Component/AllTests.php';
require_once 'Orm/Ticket/AllTests.php';
require_once 'Orm/UnitOfWorkTestCase.php';
require_once 'Orm/ConfigurableTestCase.php';
class Orm_AllTests
{
......@@ -22,6 +23,8 @@ class Orm_AllTests
$suite = new Doctrine_OrmTestSuite('Doctrine Orm');
$suite->addTestSuite('Orm_UnitOfWorkTestCase');
$suite->addTestSuite('Orm_ConfigurableTestCase');
$suite->addTest(Orm_Component_AllTests::suite());
$suite->addTest(Orm_Ticket_AllTests::suite());
......
......@@ -173,43 +173,6 @@ class Doctrine_Configurable_TestCase extends Doctrine_UnitTestCase {
$this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE, 5);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_BATCH_SIZE),5);
$this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
$this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_LOCKMODE), Doctrine::LOCK_PESSIMISTIC);
// test invalid arguments
/**
try {
$this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
try {
$this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
try {
$this->manager->setAttribute(Doctrine::ATTR_BATCH_SIZE,-12);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
}
*/
try {
$this->connection->beginTransaction();
$this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_OPTIMISTIC);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
$this->connection->commit();
}
try {
$this->connection->beginTransaction();
$this->connection->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
} catch(Exception $e) {
$this->assertTrue($e instanceof Exception);
$this->connection->commit();
}
}
public function testGetAttributes() {
$this->assertTrue(is_array($this->manager->getAttributes()));
......
......@@ -60,7 +60,8 @@ class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase
public function testHydrateHooks()
{
$user = new User();
$user->getMapper()->addRecordListener(new HydrationListener);
$listener = new HydrationListener;
$user->getClassMetadata()->addRecordListener($listener);
$user->name = 'zYne';
$user->save();
......@@ -72,7 +73,7 @@ class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($user->name, 'ZYNE');
$this->assertEqual($user->password, 'DEFAULT PASS');
$user->getClassMetadata()->removeRecordListeners();
}
}
class HydrationListener extends Doctrine_Record_Listener
......
......@@ -79,7 +79,7 @@ class Doctrine_Record_Hook_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($r->pop(), 'preDelete');
}
public function testSoftDelete()
/*public function testSoftDelete()
{
$r = new SoftDeleteTest();
$r->name = 'something';
......@@ -99,5 +99,5 @@ class Doctrine_Record_Hook_TestCase extends Doctrine_UnitTestCase
} catch(Doctrine_Exception $e) {
$this->fail();
}
}
}*/
}
......@@ -7,35 +7,35 @@ class RecordHookTest extends Doctrine_Record
{
$class->setColumn('name', 'string', null, array('primary' => true));
}
public function preSave(Doctrine_Event $event)
public function preSave()
{
$this->_messages[] = __FUNCTION__;
}
public function postSave(Doctrine_Event $event)
public function postSave()
{
$this->_messages[] = __FUNCTION__;
}
public function preInsert(Doctrine_Event $event)
public function preInsert()
{
$this->_messages[] = __FUNCTION__;
}
public function postInsert(Doctrine_Event $event)
public function postInsert()
{
$this->_messages[] = __FUNCTION__;
}
public function preUpdate(Doctrine_Event $event)
public function preUpdate()
{
$this->_messages[] = __FUNCTION__;
}
public function postUpdate(Doctrine_Event $event)
public function postUpdate()
{
$this->_messages[] = __FUNCTION__;
}
public function preDelete(Doctrine_Event $event)
public function preDelete()
{
$this->_messages[] = __FUNCTION__;
}
public function postDelete(Doctrine_Event $event)
public function postDelete()
{
$this->_messages[] = __FUNCTION__;
}
......
......@@ -7,14 +7,14 @@ class SoftDeleteTest extends Doctrine_Record
$class->setColumn('something', 'string', '25', array('notnull' => true, 'unique' => true));
$class->setColumn('deleted', 'boolean', 1);
}
public function preDelete(Doctrine_Event $event)
/*public function preDelete()
{
$event->skipOperation();
}
public function postDelete(Doctrine_Event $event)
public function postDelete()
{
$this->deleted = true;
$this->save();
}
}*/
}
......@@ -122,7 +122,6 @@ $core->addTestCase(new Doctrine_Access_TestCase());
//$core->addTestCase(new Doctrine_Configurable_TestCase());
$core->addTestCase(new Doctrine_Manager_TestCase());
$core->addTestCase(new Doctrine_Connection_TestCase());
$core->addTestCase(new Doctrine_Table_TestCase());
$core->addTestCase(new Doctrine_UnitOfWork_TestCase());
//$core->addTestCase(new Doctrine_Collection_TestCase());
$core->addTestCase(new Doctrine_Collection_Snapshot_TestCase());
......@@ -259,8 +258,8 @@ $test->addTestCase(new Doctrine_Inheritance_TablePerClass_TestCase());
$test->addTestCase(new Doctrine_Metadata_Factory_TestCase());
// nestedset tests
$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase());
$test->addTestCase(new Doctrine_NestedSet_LoadInSetUp_TestCase());
//$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase());
//$test->addTestCase(new Doctrine_NestedSet_LoadInSetUp_TestCase());
// Search tests
$search = new GroupTest('Search tests','search');
......
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