Commit a758b565 authored by romanb's avatar romanb

[2.0] Introduced SQL logging facilities. Made Type constructor private to...

[2.0] Introduced SQL logging facilities. Made Type constructor private to prevent instantiation and force use of the factory method getType().
parent 0ed8e7a3
......@@ -47,10 +47,31 @@ class Configuration
public function __construct()
{
$this->_attributes = array(
'quoteIdentifiers' => false
'quoteIdentifiers' => false,
'sqlLogger' => null
);
}
/**
* Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled.
*
* @param SqlLogger $logger
*/
public function setSqlLogger($logger)
{
$this->_attributes['sqlLogger'] = $logger;
}
/**
* Gets the SQL logger that is used.
*
* @return SqlLogger
*/
public function getSqlLogger()
{
return $this->_attributes['sqlLogger'];
}
public function getQuoteIdentifiers()
{
return $this->_attributes['quoteIdentifiers'];
......
......@@ -280,6 +280,43 @@ class Connection
return true;
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetch(PDO::FETCH_ASSOC).
*
* @param string $statement The SQL query.
* @param array $params The query parameters.
* @return array
*/
public function fetchRow($statement, array $params = array())
{
return $this->execute($statement, $params)->fetch(\PDO::FETCH_ASSOC);
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetch(PDO::FETCH_NUM).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @return array
*/
public function fetchArray($statement, array $params = array())
{
return $this->execute($statement, $params)->fetch(\PDO::FETCH_NUM);
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetchAll(PDO::FETCH_COLUMN, ...).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @param int $colnum 0-indexed column number to retrieve
* @return array
*/
public function fetchColumn($statement, array $params = array(), $colnum = 0)
{
return $this->execute($statement, $params)->fetchAll(\PDO::FETCH_COLUMN, $colnum);
}
/**
* Whether an actual connection to the database is established.
*
......@@ -290,6 +327,18 @@ class Connection
return $this->_isConnected;
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetchAll(PDO::FETCH_BOTH).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @return array
*/
public function fetchBoth($statement, array $params = array())
{
return $this->execute($statement, $params)->fetchAll(\PDO::FETCH_BOTH);
}
/**
* Deletes table row(s) matching the specified identifier.
*
......@@ -312,6 +361,38 @@ class Connection
return $this->exec($query, array_values($identifier));
}
/**
* Closes the connection.
*
* @return void
*/
public function close()
{
unset($this->_conn);
$this->_isConnected = false;
}
/**
* Sets the transaction isolation level.
*
* @param integer $level The level to set.
*/
public function setTransactionIsolation($level)
{
$this->_transactionIsolationLevel = $level;
return $this->exec($this->_platform->getSetTransactionIsolationSql($level));
}
/**
* Gets the currently active transaction isolation level.
*
* @return integer The current transaction isolation level.
*/
public function getTransactionIsolation()
{
return $this->_transactionIsolationLevel;
}
/**
* Updates table row(s) with specified data
*
......@@ -445,55 +526,6 @@ class Connection
return $this->execute($statement, $params)->fetchColumn($colnum);
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetch(PDO::FETCH_ASSOC).
*
* @param string $statement The SQL query.
* @param array $params The query parameters.
* @return array
*/
public function fetchRow($statement, array $params = array())
{
return $this->execute($statement, $params)->fetch(\PDO::FETCH_ASSOC);
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetch(PDO::FETCH_NUM).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @return array
*/
public function fetchArray($statement, array $params = array())
{
return $this->execute($statement, $params)->fetch(\PDO::FETCH_NUM);
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetchAll(PDO::FETCH_COLUMN, ...).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @param int $colnum 0-indexed column number to retrieve
* @return array
*/
public function fetchColumn($statement, array $params = array(), $colnum = 0)
{
return $this->execute($statement, $params)->fetchAll(\PDO::FETCH_COLUMN, $colnum);
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetchAll(PDO::FETCH_BOTH).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @return array
*/
public function fetchBoth($statement, array $params = array())
{
return $this->execute($statement, $params)->fetchAll(\PDO::FETCH_BOTH);
}
/**
* Prepares an SQL statement.
*
......@@ -534,7 +566,11 @@ class Connection
public function execute($query, array $params = array())
{
$this->connect();
try {
if ($this->_config->getSqlLogger()) {
$this->_config->getSqlLogger()->logSql($query, $params);
}
if ( ! empty($params)) {
$stmt = $this->prepare($query);
$stmt->execute($params);
......@@ -544,9 +580,6 @@ class Connection
$this->_queryCount++;
return $stmt;
}
} catch (PDOException $e) {
$this->rethrowException($e, $this);
}
}
/**
......@@ -560,9 +593,12 @@ class Connection
*/
public function exec($query, array $params = array()) {
$this->connect();
try {
if ($this->_config->getSqlLogger()) {
$this->_config->getSqlLogger()->logSql($query, $params);
}
if ( ! empty($params)) {
var_dump($params);
$stmt = $this->prepare($query);
$stmt->execute($params);
return $stmt->rowCount();
......@@ -571,20 +607,6 @@ class Connection
$this->_queryCount++;
return $count;
}
} catch (PDOException $e) {
//TODO: Wrap
throw $e;
}
}
/**
* Wraps the given exception into a driver-specific exception and rethrows it.
*
* @throws Doctrine\DBAL\ConnectionException
*/
public function rethrowException(\Exception $e, $invoker)
{
throw $e;
}
/**
......@@ -597,38 +619,6 @@ class Connection
return $this->_queryCount;
}
/**
* Closes the connection.
*
* @return void
*/
public function close()
{
unset($this->_conn);
$this->_isConnected = false;
}
/**
* Sets the transaction isolation level.
*
* @param integer $level The level to set.
*/
public function setTransactionIsolation($level)
{
$this->_transactionIsolationLevel = $level;
return $this->exec($this->_platform->getSetTransactionIsolationSql($level));
}
/**
* Gets the currently active transaction isolation level.
*
* @return integer The current transaction isolation level.
*/
public function getTransactionIsolation()
{
return $this->_transactionIsolationLevel;
}
/**
* Returns the current transaction nesting level.
*
......
<?php
namespace Doctrine\DBAL\Logging;
/**
* A SQL logger that logs to the standard output using echo/var_dump.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class EchoSqlLogger implements SqlLogger
{
public function logSql($sql, array $params = null)
{
echo $sql . PHP_EOL;
if ($params) {
var_dump($params);
}
}
}
\ No newline at end of file
<?php
namespace Doctrine\DBAL\Logging;
/**
* Interface for SQL loggers.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
interface SqlLogger
{
public function logSql($sql, array $params = null);
}
\ No newline at end of file
......@@ -37,6 +37,9 @@ abstract class Type
'double' => 'Doctrine\DBAL\Types\DoubleType'
);
/* Prevent instantiation and force use of the factory method. */
private function __construct() {}
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
return $value;
......
......@@ -170,11 +170,11 @@ class EntityManager
}
/**
* Starts a transaction on the underlying connection.
* Starts a transaction on the underlying database connection.
*/
public function beginTransaction()
{
return $this->_conn->beginTransaction();
$this->_conn->beginTransaction();
}
/**
......@@ -182,15 +182,23 @@ class EntityManager
*
* This causes a flush() of the EntityManager if the flush mode is set to
* AUTO or COMMIT.
*
* @return boolean
*/
public function commit()
{
if ($this->_flushMode == self::FLUSHMODE_AUTO || $this->_flushMode == self::FLUSHMODE_COMMIT) {
$this->flush();
}
return $this->_conn->commitTransaction();
$this->_conn->commitTransaction();
}
/**
* Performs a rollback on the underlying database connection and closes the
* EntityManager as it may now be in a corrupted state.
*/
public function rollback()
{
$this->_conn->rollback();
$this->close();
}
/**
......@@ -401,6 +409,7 @@ class EntityManager
*/
public function refresh($entity)
{
$this->_errorIfClosed();
throw DoctrineException::notImplemented();
}
......
......@@ -26,7 +26,7 @@ namespace Doctrine\ORM;
*
* This class cannot be instantiated.
*
* @author robo
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
final class Events
......@@ -35,6 +35,9 @@ final class Events
const preDelete = 'preDelete';
const postDelete = 'postDelete';
const preSave = 'preSave';
const postSave = 'postSave';
const preInsert = 'preSave';
const postInsert = 'postSave';
const preUpdate = 'preUpdate';
const postUpdate = 'postUpdate';
const load = 'load';
}
\ No newline at end of file
......@@ -185,7 +185,7 @@ abstract class AbstractHydrator
$classMetadata = $this->_lookupDeclaringClass($classMetadata, $fieldName);
$cache[$key]['fieldName'] = $fieldName;
$cache[$key]['isScalar'] = false;
$cache[$key]['type'] = Type::getType($classMetadata->getTypeOfField($fieldName));
$cache[$key]['type'] = Type::getType($classMetadata->fieldMappings[$fieldName]['type']);
$cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName);
$cache[$key]['dqlAlias'] = $this->_rsm->columnOwnerMap[$key];
} else {
......
......@@ -55,17 +55,12 @@ class ArrayHydrator extends AbstractHydrator
/** @override */
protected function _hydrateAll()
{
$s = microtime(true);
$result = array();
$cache = array();
while ($data = $this->_stmt->fetch(PDO::FETCH_ASSOC)) {
$this->_hydrateRow($data, $cache, $result);
}
$e = microtime(true);
echo 'Hydration took: ' . ($e - $s) . PHP_EOL;
return $result;
}
......
......@@ -113,8 +113,6 @@ class ObjectHydrator extends AbstractHydrator
*/
protected function _hydrateAll()
{
$s = microtime(true);
$result = $this->_rsm->isMixed ? array() : new Collection;
$cache = array();
......@@ -132,10 +130,6 @@ class ObjectHydrator extends AbstractHydrator
$this->_collections = array();
$this->_initializedRelations = array();
$e = microtime(true);
echo 'Hydration took: ' . ($e - $s) . ' for '.count($result).' records' . PHP_EOL;
return $result;
}
......@@ -279,10 +273,10 @@ class ObjectHydrator extends AbstractHydrator
*/
private function setRelatedElement($entity1, $property, $entity2)
{
$classMetadata1 = $this->_ce[get_class($entity1)];
$classMetadata1->reflFields[$property]->setValue($entity1, $entity2);
$class = $this->_ce[get_class($entity1)];
$class->reflFields[$property]->setValue($entity1, $entity2);
$this->_uow->setOriginalEntityProperty(spl_object_hash($entity1), $property, $entity2);
$relation = $classMetadata1->associationMappings[$property];
$relation = $class->associationMappings[$property];
if ($relation->isOneToOne()) {
$targetClass = $this->_ce[$relation->targetEntityName];
if ($relation->isOwningSide) {
......@@ -290,7 +284,7 @@ class ObjectHydrator extends AbstractHydrator
if (isset($targetClass->inverseMappings[$property])) {
$sourceProp = $targetClass->inverseMappings[$property]->sourceFieldName;
$targetClass->reflFields[$sourceProp]->setValue($entity2, $entity1);
} else if ($classMetadata1 === $targetClass) {
} else if ($class === $targetClass) {
// Special case: self-referencing one-one on the same class
$targetClass->reflFields[$property]->setValue($entity2, $entity1);
}
......
......@@ -254,15 +254,6 @@ final class ClassMetadata
*/
public $columnNames = array();
/**
* Map that maps lowercased column names (keys) to field names (values).
* Mainly used during hydration because Doctrine enforces PDO_CASE_LOWER
* for portability.
*
* @var array
*/
public $lcColumnToFieldNames = array();
/**
* Whether to automatically OUTER JOIN subtypes when a basetype is queried.
*
......@@ -724,29 +715,6 @@ final class ClassMetadata
$this->fieldNames[$columnName] : $columnName;
}
/**
* Gets the field name for a completely lowercased column name.
* Mainly used during hydration.
*
* @param string $lcColumnName The all-lowercase column name.
* @return string The field name.
*/
public function getFieldNameForLowerColumnName($lcColumnName)
{
return $this->lcColumnToFieldNames[$lcColumnName];
}
/**
* Checks whether a specified column name (all lowercase) exists in this class.
*
* @param string $lcColumnName
* @return boolean
*/
public function hasLowerColumn($lcColumnName)
{
return isset($this->lcColumnToFieldNames[$lcColumnName]);
}
/**
* Validates & completes the given field mapping.
*
......@@ -767,11 +735,9 @@ final class ClassMetadata
if ( ! isset($mapping['columnName'])) {
$mapping['columnName'] = $mapping['fieldName'];
}
$lcColumnName = strtolower($mapping['columnName']);
$this->columnNames[$mapping['fieldName']] = $mapping['columnName'];
$this->fieldNames[$mapping['columnName']] = $mapping['fieldName'];
$this->lcColumnToFieldNames[$lcColumnName] = $mapping['fieldName'];
// Complete id mapping
if (isset($mapping['id']) && $mapping['id'] === true) {
......
......@@ -246,6 +246,7 @@ class ClassMetadataFactory
// Generate INSERT SQL
$columns = $values = array();
if ($class->inheritanceType == ClassMetadata::INHERITANCE_TYPE_JOINED) {
// Generate INSERT SQL for inheritance type JOINED
foreach ($class->reflFields as $name => $field) {
if (isset($class->fieldMappings[$name]['inherited']) && ! isset($class->fieldMappings[$name]['id'])
|| isset($class->inheritedAssociationFields[$name])) {
......@@ -266,6 +267,7 @@ class ClassMetadataFactory
}
}
} else {
// Generate INSERT SQL for inheritance types NONE, SINGLE_TABLE, TABLE_PER_CLASS
foreach ($class->reflFields as $name => $field) {
if (isset($class->associationMappings[$name])) {
$assoc = $class->associationMappings[$name];
......@@ -281,6 +283,8 @@ class ClassMetadataFactory
}
}
}
// Add discriminator column to the INSERT SQL if necessary
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined() && $class->name == $class->rootEntityName) {
$columns[] = $class->discriminatorColumn['name'];
$values[] = '?';
......
......@@ -53,6 +53,7 @@ final class DoctrineColumn extends \Addendum\Annotation {
public $length;
public $unique = false;
public $nullable = false;
public $quote = false;
}
final class DoctrineOneToOne extends \Addendum\Annotation {
public $targetEntity;
......
......@@ -97,27 +97,38 @@ class JoinedSubclassPersister extends StandardEntityPersister
$postInsertIds = array();
$idGen = $this->_class->idGenerator;
$isPostInsertId = $idGen->isPostInsertGenerator();
$sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
// Prepare statements for all tables
$stmts = $classes = array();
$stmts[$this->_class->primaryTable['name']] = $this->_conn->prepare($this->_class->insertSql);
$classes[$this->_class->name] = $this->_class;
$sql[$this->_class->primaryTable['name']] = $this->_class->insertSql;
foreach ($this->_class->parentClasses as $parentClass) {
$classes[$parentClass] = $this->_em->getClassMetadata($parentClass);
$stmts[$classes[$parentClass]->primaryTable['name']] = $this->_conn->prepare($classes[$parentClass]->insertSql);
$parentClass = $this->_em->getClassMetadata($parentClass);
$sql[$parentClass->primaryTable['name']] = $parentClass->insertSql;
$stmts[$parentClass->primaryTable['name']] = $this->_conn->prepare($parentClass->insertSql);
}
$rootTableName = $classes[$this->_class->rootEntityName]->primaryTable['name'];
$rootTableName = $this->_em->getClassMetadata($this->_class->rootEntityName)->primaryTable['name'];
foreach ($this->_queuedInserts as $entity) {
$insertData = array();
$this->_prepareData($entity, $insertData, true);
// Execute insert on root table
$paramIndex = 1;
$stmt = $stmts[$rootTableName];
$paramIndex = 1;
if ($sqlLogger) {
$params = array();
foreach ($insertData[$rootTableName] as $columnName => $value) {
$params[$paramIndex] = $value;
$stmt->bindValue($paramIndex++, $value/*, TODO: TYPE*/);
}
$sqlLogger->logSql($sql[$rootTableName], $params);
} else {
foreach ($insertData[$rootTableName] as $columnName => $value) {
$stmt->bindValue($paramIndex++, $value/*, TODO: TYPE*/);
}
}
$stmt->execute();
unset($insertData[$rootTableName]);
......@@ -132,12 +143,26 @@ class JoinedSubclassPersister extends StandardEntityPersister
foreach ($insertData as $tableName => $data) {
$stmt = $stmts[$tableName];
$paramIndex = 1;
if ($sqlLogger) {
//TODO: Log type
$params = array();
foreach ((array)$id as $idVal) {
$params[$paramIndex] = $idVal;
$stmt->bindValue($paramIndex++, $idVal/*, TODO: TYPE*/);
}
foreach ($data as $columnName => $value) {
$params[$paramIndex] = $value;
$stmt->bindValue($paramIndex++, $value/*, TODO: TYPE*/);
}
$sqlLogger->logSql($sql[$tableName], $params);
} else {
foreach ((array)$id as $idVal) {
$stmt->bindValue($paramIndex++, $idVal/*, TODO: TYPE*/);
}
foreach ($data as $columnName => $value) {
$stmt->bindValue($paramIndex++, $value/*, TODO: TYPE*/);
}
}
$stmt->execute();
}
}
......
......@@ -113,20 +113,34 @@ class StandardEntityPersister
$stmt = $this->_conn->prepare($this->_class->insertSql);
$primaryTableName = $this->_class->primaryTable['name'];
$sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
foreach ($this->_queuedInserts as $entity) {
$insertData = array();
$this->_prepareData($entity, $insertData, true);
$paramIndex = 1;
if ($sqlLogger) {
//TODO: Log type
$params = array();
foreach ($insertData[$primaryTableName] as $value) {
$params[$paramIndex] = $value;
$stmt->bindValue($paramIndex++, $value/*, Type::getType()*/);
}
$sqlLogger->logSql($this->_class->insertSql, $params);
} else {
foreach ($insertData[$primaryTableName] as $value) {
$stmt->bindValue($paramIndex++, $value/*, Type::getType()*/);
}
}
$stmt->execute();
if ($isPostInsertId) {
$postInsertIds[$idGen->generate($this->_em, $entity)] = $entity;
}
}
$stmt->closeCursor();
$this->_queuedInserts = array();
......@@ -261,8 +275,7 @@ class StandardEntityPersister
$result[$this->getOwningTable($field)][$sourceColumn] = null;
} else {
$result[$this->getOwningTable($field)][$sourceColumn] =
$otherClass->reflFields[$otherClass->fieldNames[$targetColumn]]
->getValue($newVal);
$otherClass->reflFields[$otherClass->fieldNames[$targetColumn]]->getValue($newVal);
}
}
} else if ($newVal === null) {
......@@ -325,7 +338,7 @@ class StandardEntityPersister
if ( ! $this->_em->getConfiguration()->getAllowPartialObjects()) {
foreach ($this->_class->associationMappings as $field => $assoc) {
if ($assoc->isOneToOne()) {
if ($assoc->isLazilyFetched()) {
if ($assoc->isLazilyFetched) {
// Inject proxy
$proxy = $this->_em->getProxyGenerator()->getAssociationProxy($entity, $assoc);
$this->_class->reflFields[$field]->setValue($entity, $proxy);
......
......@@ -56,9 +56,8 @@ class ResultSetMapping
/**
*
* @param <type> $class
* @param <type> $alias The alias for this class. The alias must be unique within this ResultSetMapping.
* @param <type> $discriminatorColumn
* @param string $class The class name.
* @param string $alias The alias for this class. The alias must be unique within this ResultSetMapping.
*/
public function addEntityResult($class, $alias)
{
......@@ -67,9 +66,8 @@ class ResultSetMapping
/**
*
* @param <type> $className
* @param <type> $alias
* @param <type> $discrColumn
* @param string $alias
* @param string $discrColumn
*/
public function setDiscriminatorColumn($alias, $discrColumn)
{
......@@ -130,9 +128,9 @@ class ResultSetMapping
/**
*
* @param <type> $alias
* @param <type> $columnName
* @param <type> $fieldName
* @param string $alias
* @param string $columnName
* @param string $fieldName
*/
public function addFieldResult($alias, $columnName, $fieldName)
{
......@@ -145,10 +143,10 @@ class ResultSetMapping
/**
*
* @param <type> $class
* @param <type> $alias
* @param <type> $parentAlias
* @param <type> $relation
* @param string $class
* @param string $alias
* @param string $parentAlias
* @param object $relation
*/
public function addJoinedEntityResult($class, $alias, $parentAlias, $relation)
{
......@@ -157,11 +155,11 @@ class ResultSetMapping
$this->relationMap[$alias] = $relation;
}
/*public function isDiscriminatorColumn($columnName)
{
return isset($this->_discriminatorMap[$columnName]);
}*/
/**
*
* @param string $columnName
* @param string $alias
*/
public function addScalarResult($columnName, $alias)
{
$this->scalarMappings[$columnName] = $alias;
......
......@@ -483,7 +483,6 @@ class UnitOfWork implements PropertyChangedListener
}
if ( ! $assoc->isCascadeSave) {
//echo "NOT CASCADING INTO " . $assoc->getSourceFieldName() . PHP_EOL;
return; // "Persistence by reachability" only if save cascade specified
}
......@@ -498,7 +497,7 @@ class UnitOfWork implements PropertyChangedListener
$oid = spl_object_hash($entry);
if ($state == self::STATE_NEW) {
// Get identifier, if possible (not post-insert)
$idGen = $targetClass->getIdGenerator();
$idGen = $targetClass->idGenerator;
if ( ! $idGen->isPostInsertGenerator()) {
$idValue = $idGen->generate($this->_em, $entry);
$this->_entityStates[$oid] = self::STATE_MANAGED;
......@@ -803,35 +802,6 @@ class UnitOfWork implements PropertyChangedListener
isset($this->_entityDeletions[$oid]);
}
/**
* Detaches all currently managed entities.
* Alternatively, if an entity class name is given, all entities of that type
* (or subtypes) are detached. Don't forget that entities are registered in
* the identity map with the name of the root entity class. So calling detachAll()
* with a class name that is not the name of a root entity has no effect.
*
* @return integer The number of detached entities.
*/
public function detachAll($entityName = null)
{
$numDetached = 0;
if ($entityName !== null && isset($this->_identityMap[$entityName])) {
$numDetached = count($this->_identityMap[$entityName]);
foreach ($this->_identityMap[$entityName] as $entity) {
$this->detach($entity);
}
$this->_identityMap[$entityName] = array();
} else {
$numDetached = count($this->_identityMap);
$this->_identityMap = array();
$this->_entityInsertions = array();
$this->_entityUpdates = array();
$this->_entityDeletions = array();
}
return $numDetached;
}
/**
* Registers an entity in the identity map.
* Note that entities in a hierarchy are registered with the class name of
......@@ -960,8 +930,7 @@ class UnitOfWork implements PropertyChangedListener
return isset($this->_identityMap
[$classMetadata->rootEntityName]
[$idHash]
);
[$idHash]);
}
/**
......@@ -1174,6 +1143,10 @@ class UnitOfWork implements PropertyChangedListener
/**
* Cascades a merge operation to associated entities.
*
* @param object $entity
* @param object $managedCopy
* @param array $visited
*/
private function _cascadeMerge($entity, $managedCopy, array &$visited)
{
......@@ -1199,6 +1172,7 @@ class UnitOfWork implements PropertyChangedListener
*
* @param object $entity
* @param array $visited
* @param array $insertNow
*/
private function _cascadeSave($entity, array &$visited, array &$insertNow)
{
......@@ -1223,6 +1197,7 @@ class UnitOfWork implements PropertyChangedListener
* Cascades the delete operation to associated entities.
*
* @param object $entity
* @param array $visited
*/
private function _cascadeDelete($entity, array &$visited)
{
......
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\Tests\TestUtil;
use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types\Type;
require_once __DIR__ . '/../../../TestInit.php';
......@@ -59,13 +60,13 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -86,13 +87,13 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -114,13 +115,13 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -158,13 +159,13 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -197,13 +198,13 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -245,7 +246,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createView('test_create_view', 'SELECT * from mysql.user');
$views = $this->_sm->listViews();
$this->assertEquals($views[0]['name'], 'test_create_view');
$this->assertEquals($views[0]['sql'], '/* ALGORITHM=UNDEFINED */ select `mysql`.`user`.`Host` AS `Host`,`mysql`.`user`.`User` AS `User`,`mysql`.`user`.`Password` AS `Password`,`mysql`.`user`.`Select_priv` AS `Select_priv`,`mysql`.`user`.`Insert_priv` AS `Insert_priv`,`mysql`.`user`.`Update_priv` AS `Update_priv`,`mysql`.`user`.`Delete_priv` AS `Delete_priv`,`mysql`.`user`.`Create_priv` AS `Create_priv`,`mysql`.`user`.`Drop_priv` AS `Drop_priv`,`mysql`.`user`.`Reload_priv` AS `Reload_priv`,`mysql`.`user`.`Shutdown_priv` AS `Shutdown_priv`,`mysql`.`user`.`Process_priv` AS `Process_priv`,`mysql`.`user`.`File_priv` AS `File_priv`,`mysql`.`user`.`Grant_priv` AS `Grant_priv`,`mysql`.`user`.`References_priv` AS `References_priv`,`mysql`.`user`.`Index_priv` AS `Index_priv`,`mysql`.`user`.`Alter_priv` AS `Alter_priv`,`mysql`.`user`.`Show_db_priv` AS `Show_db_priv`,`mysql`.`user`.`Super_priv` AS `Super_priv`,`mysql`.`user`.`Create_tmp_table_priv` AS `Create_tmp_table_priv`,`mysql`.`user`.`Lock_tables_priv` AS `Lock_tables_priv`,`mysql`.`user`.`Execute_priv` AS `Execute_priv`,`mysql`.`user`.`Repl_slave_priv` AS `Repl_slave_priv`,`mysql`.`user`.`Repl_client_priv` AS `Repl_client_priv`,`mysql`.`user`.`Create_view_priv` AS `Create_view_priv`,`mysql`.`user`.`Show_view_priv` AS `Show_view_priv`,`mysql`.`user`.`Create_routine_priv` AS `Create_routine_priv`,`mysql`.`user`.`Alter_routine_priv` AS `Alter_routine_priv`,`mysql`.`user`.`Create_user_priv` AS `Create_user_priv`,`mysql`.`user`.`ssl_type` AS `ssl_type`,`mysql`.`user`.`ssl_cipher` AS `ssl_cipher`,`mysql`.`user`.`x509_issuer` AS `x509_issuer`,`mysql`.`user`.`x509_subject` AS `x509_subject`,`mysql`.`user`.`max_questions` AS `max_questions`,`mysql`.`user`.`max_updates` AS `max_updates`,`mysql`.`user`.`max_connections` AS `max_connections`,`mysql`.`user`.`max_user_connections` AS `max_user_connections` from `mysql`.`user`');
$this->assertEquals('test_create_view', $views[0]['name']);
$this->assertEquals('/* ALGORITHM=UNDEFINED */ select `mysql`.`user`.`Host` AS `Host`,`mysql`.`user`.`User` AS `User`,`mysql`.`user`.`Password` AS `Password`,`mysql`.`user`.`Select_priv` AS `Select_priv`,`mysql`.`user`.`Insert_priv` AS `Insert_priv`,`mysql`.`user`.`Update_priv` AS `Update_priv`,`mysql`.`user`.`Delete_priv` AS `Delete_priv`,`mysql`.`user`.`Create_priv` AS `Create_priv`,`mysql`.`user`.`Drop_priv` AS `Drop_priv`,`mysql`.`user`.`Reload_priv` AS `Reload_priv`,`mysql`.`user`.`Shutdown_priv` AS `Shutdown_priv`,`mysql`.`user`.`Process_priv` AS `Process_priv`,`mysql`.`user`.`File_priv` AS `File_priv`,`mysql`.`user`.`Grant_priv` AS `Grant_priv`,`mysql`.`user`.`References_priv` AS `References_priv`,`mysql`.`user`.`Index_priv` AS `Index_priv`,`mysql`.`user`.`Alter_priv` AS `Alter_priv`,`mysql`.`user`.`Show_db_priv` AS `Show_db_priv`,`mysql`.`user`.`Super_priv` AS `Super_priv`,`mysql`.`user`.`Create_tmp_table_priv` AS `Create_tmp_table_priv`,`mysql`.`user`.`Lock_tables_priv` AS `Lock_tables_priv`,`mysql`.`user`.`Execute_priv` AS `Execute_priv`,`mysql`.`user`.`Repl_slave_priv` AS `Repl_slave_priv`,`mysql`.`user`.`Repl_client_priv` AS `Repl_client_priv`,`mysql`.`user`.`Create_view_priv` AS `Create_view_priv`,`mysql`.`user`.`Show_view_priv` AS `Show_view_priv`,`mysql`.`user`.`Create_routine_priv` AS `Create_routine_priv`,`mysql`.`user`.`Alter_routine_priv` AS `Alter_routine_priv`,`mysql`.`user`.`Create_user_priv` AS `Create_user_priv`,`mysql`.`user`.`ssl_type` AS `ssl_type`,`mysql`.`user`.`ssl_cipher` AS `ssl_cipher`,`mysql`.`user`.`x509_issuer` AS `x509_issuer`,`mysql`.`user`.`x509_subject` AS `x509_subject`,`mysql`.`user`.`max_questions` AS `max_questions`,`mysql`.`user`.`max_updates` AS `max_updates`,`mysql`.`user`.`max_connections` AS `max_connections`,`mysql`.`user`.`max_user_connections` AS `max_user_connections` from `mysql`.`user`', $views[0]['sql']);
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\Tests\TestUtil;
use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types\Type;
require_once __DIR__ . '/../../../TestInit.php';
......@@ -58,13 +59,13 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -91,13 +92,13 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -131,13 +132,13 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -164,13 +165,13 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -198,13 +199,13 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -250,13 +251,13 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......@@ -314,13 +315,13 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......
......@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\Type;
require_once __DIR__ . '/../../TestInit.php';
......@@ -19,13 +20,13 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'type' => Type::getType('string'),
'length' => 255
)
);
......
......@@ -23,4 +23,20 @@ class ForumUser
* @DoctrineJoinColumn(name="avatar_id", referencedColumnName="id")
*/
public $avatar;
public function getId() {
return $this->id;
}
public function getUsername() {
return $this->username;
}
public function getAvatar() {
return $this->avatar;
}
public function setAvatar(CmsAvatar $avatar) {
$this->avatar = $avatar;
}
}
\ No newline at end of file
......@@ -150,8 +150,6 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
public function testManyToManyCollectionClearing()
{
echo PHP_EOL . "MANY-MANY" . PHP_EOL;
$user = new CmsUser;
$user->name = 'Guilherme';
$user->username = 'gblanco';
......@@ -176,7 +174,6 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
//$user->groups->clear();
unset($user->groups);
echo PHP_EOL . "FINAL FLUSH" . PHP_EOL;
$this->_em->flush();
// Check that the links in the association table have been deleted
......
......@@ -24,7 +24,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
*
* MAXIMUM TIME: 3 seconds
*/
public function testNewHydrationSimpleQueryArrayHydrationPerformance()
public function testSimpleQueryArrayHydrationPerformance()
{
$rsm = new ResultSetMapping;
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
......@@ -69,7 +69,10 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$this->setMaxRunningTime(3);
$s = microtime(true);
$result = $hydrator->hydrateAll($stmt, $rsm);
$e = microtime(true);
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
}
/**
......@@ -79,7 +82,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
*
* MAXIMUM TIME: 4 seconds
*/
public function testNewHydrationMixedQueryFetchJoinArrayHydrationPerformance()
public function testMixedQueryFetchJoinArrayHydrationPerformance()
{
$rsm = new ResultSetMapping;
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
......@@ -140,7 +143,10 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
$this->setMaxRunningTime(4);
$s = microtime(true);
$result = $hydrator->hydrateAll($stmt, $rsm);
$e = microtime(true);
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
}
/**
......@@ -193,8 +199,10 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$this->setMaxRunningTime(5);
$s = microtime(true);
$result = $hydrator->hydrateAll($stmt, $rsm);
echo count($result);
$e = microtime(true);
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
}
/**
......@@ -263,7 +271,10 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$this->setMaxRunningTime(4);
$s = microtime(true);
$result = $hydrator->hydrateAll($stmt, $rsm);
$e = microtime(true);
echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL;
}
}
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