Commit d0ea5705 authored by romanb's avatar romanb

Initial support for scalar hydration (HYDRATE_SCALAR). EntityPersisters born.

parent 613d08f9
...@@ -473,11 +473,11 @@ final class Doctrine ...@@ -473,11 +473,11 @@ final class Doctrine
const HYDRATE_NONE = 4; const HYDRATE_NONE = 4;
/* new hydration modes. move to Query class when it's time. */ /* new hydration modes. move to Query class when it's time. */
//const HYDRATE_IDENTITY_OBJECT = 1; // default, auto-adds PKs, produces object graphs const HYDRATE_IDENTITY_OBJECT = 2; // default, auto-adds PKs, produces object graphs
//const HYDRATE_IDENTITY_ARRAY = 2; // auto-adds PKs, produces array graphs const HYDRATE_IDENTITY_ARRAY = 3; // auto-adds PKs, produces array graphs
//const HYDRATE_SCALAR = 3; // produces flat result list with scalar values const HYDRATE_SCALAR = 5; // produces flat result list with scalar values
//const HYDRATE_SINGLE_SCALAR = 4; // produces a single scalar value const HYDRATE_SINGLE_SCALAR = 6; // produces a single scalar value
//const HYDRATE_NONE = 5; // produces a result set as it's returned by the db //const HYDRATE_NONE = 4; // produces a result set as it's returned by the db
/** /**
......
...@@ -200,8 +200,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -200,8 +200,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function __construct($adapter, $user = null, $pass = null) public function __construct($adapter, $user = null, $pass = null)
{ {
if (is_object($adapter)) { if (is_object($adapter)) {
if ( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter))) { if ( ! $adapter instanceof PDO) {
throw new Doctrine_Connection_Exception('First argument should be an instance of PDO or implement Doctrine_Adapter_Interface'); throw new Doctrine_Connection_Exception(
'First argument should be an instance of PDO or implement Doctrine_Adapter_Interface');
} }
$this->dbh = $adapter; $this->dbh = $adapter;
$this->isConnected = true; $this->isConnected = true;
...@@ -216,12 +217,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -216,12 +217,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if (isset($adapter['other'])) { if (isset($adapter['other'])) {
$this->options['other'] = array(Doctrine::ATTR_PERSISTENT => $adapter['persistent']); $this->options['other'] = array(Doctrine::ATTR_PERSISTENT => $adapter['persistent']);
} }
} }
$this->setAttribute(Doctrine::ATTR_CASE, Doctrine::CASE_NATURAL);
$this->setAttribute(Doctrine::ATTR_ERRMODE, Doctrine::ERRMODE_EXCEPTION);
$this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this);
} }
...@@ -327,26 +323,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -327,26 +323,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->getListener()->preConnect($event); $this->getListener()->preConnect($event);
$e = explode(':', $this->options['dsn']); $e = explode(':', $this->options['dsn']);
$found = false;
if (extension_loaded('pdo')) { if (extension_loaded('pdo')) {
if (in_array($e[0], PDO::getAvailableDrivers())) { if (in_array($e[0], PDO::getAvailableDrivers())) {
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->dbh = new PDO(
$this->options['password'], $this->options['other']); $this->options['dsn'], $this->options['username'],
$this->options['password'], $this->options['other']);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$found = true; $this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
}
}
if ( ! $found) {
$class = 'Doctrine_Adapter_' . ucwords($e[0]);
if (class_exists($class)) {
$this->dbh = new $class($this->options['dsn'], $this->options['username'], $this->options['password']);
} else {
throw new Doctrine_Connection_Exception("Couldn't locate driver named " . $e[0]);
} }
} else {
throw new Doctrine_Connection_Exception("Couldn't locate driver named " . $e[0]);
} }
// attach the pending attributes to adapter // attach the pending attributes to adapter
......
This diff is collapsed.
<?php
class Doctrine_EntityManager_Exception extends Doctrine_Exception
{
public static function invalidFlushMode()
{
return new self("Invalid flush mode.");
}
public static function noEntityManagerAvailable()
{
return new self("No EntityManager available.");
}
public static function entityAlreadyBound($entityName)
{
return new self("The entity '$entityName' is already bound.");
}
public static function noManagerWithName($emName)
{
return new self("EntityManager named '$emName' not found.");
}
}
\ No newline at end of file
This diff is collapsed.
<?php
class Doctrine_EntityPersister_Exception extends Doctrine_Exception
{
}
?>
\ No newline at end of file
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>.
*/
/**
* The default mapping strategy maps a single entity instance to a single database table,
* as is the case in Single Table Inheritance & Concrete Table Inheritance.
*
* @author Roman Borschel <roman@code-factory.org>
* @package Doctrine
* @subpackage Abstract
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @link www.phpdoctrine.org
* @since 2.0
*/
class Doctrine_EntityPersister_Standard extends Doctrine_EntityPersister_Abstract
{
/**
* Deletes an entity.
*/
protected function _doDelete(Doctrine_Entity $record)
{
$conn = $this->_conn;
$metadata = $this->_classMetadata;
try {
$conn->beginInternalTransaction();
$this->_deleteComposites($record);
$record->state(Doctrine_Entity::STATE_TDIRTY);
$identifier = $this->_convertFieldToColumnNames($record->identifier(), $metadata);
$this->_deleteRow($metadata->getTableName(), $identifier);
$record->state(Doctrine_Entity::STATE_TCLEAN);
$this->removeRecord($record);
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw $e;
}
}
/**
* Inserts a single entity into the database, without any related entities.
*
* @param Doctrine_Entity $record The entity to insert.
*/
protected function _doInsert(Doctrine_Entity $record)
{
$conn = $this->_conn;
$fields = $record->getPrepared();
if (empty($fields)) {
return false;
}
//$class = $record->getClassMetadata();
$class = $this->_classMetadata;
$identifier = $class->getIdentifier();
$fields = $this->_convertFieldToColumnNames($fields, $class);
$seq = $class->getTableOption('sequenceName');
if ( ! empty($seq)) {
$id = $conn->sequence->nextId($seq);
$seqName = $identifier[0];
$fields[$seqName] = $id;
$record->assignIdentifier($id);
}
$this->_insertRow($class->getTableName(), $fields);
if (empty($seq) && count($identifier) == 1 &&
$class->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) {
if (strtolower($conn->getName()) == 'pgsql') {
$seq = $class->getTableName() . '_' . $identifier[0];
}
$id = $conn->sequence->lastInsertId($seq);
if ( ! $id) {
throw new Doctrine_Mapper_Exception("Couldn't get last insert identifier.");
}
$record->assignIdentifier($id);
} else {
$record->assignIdentifier(true);
}
}
/**
* Updates an entity.
*/
protected function _doUpdate(Doctrine_Entity $record)
{
$conn = $this->_conn;
$classMetadata = $this->_classMetadata;
$identifier = $this->_convertFieldToColumnNames($record->identifier(), $classMetadata);
$data = $this->_convertFieldToColumnNames($record->getPrepared(), $classMetadata);
$this->_updateRow($classMetadata->getTableName(), $data, $identifier);
$record->assignIdentifier(true);
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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