[2.0] Formatting issues.
This commit is contained in:
parent
6e760bacc0
commit
d23607910b
@ -15,15 +15,15 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
*/
|
||||
abstract class Type
|
||||
{
|
||||
/* The following constants represent type codes and mirror the PDO::PARAM_X constants
|
||||
* to decouple ourself from PDO.
|
||||
*/
|
||||
const CODE_BOOL = 5;
|
||||
const CODE_NULL = 0;
|
||||
const CODE_INT = 1;
|
||||
const CODE_STR = 2;
|
||||
const CODE_LOB = 3;
|
||||
|
||||
/* The following constants represent type codes and mirror the PDO::PARAM_X constants
|
||||
* to decouple ourself from PDO.
|
||||
*/
|
||||
const CODE_BOOL = 5;
|
||||
const CODE_NULL = 0;
|
||||
const CODE_INT = 1;
|
||||
const CODE_STR = 2;
|
||||
const CODE_LOB = 3;
|
||||
|
||||
private static $_typeObjects = array();
|
||||
private static $_typesMap = array(
|
||||
'integer' => 'Doctrine\DBAL\Types\IntegerType',
|
||||
@ -61,7 +61,7 @@ abstract class Type
|
||||
|
||||
public function getTypeCode()
|
||||
{
|
||||
return self::CODE_STR;
|
||||
return self::CODE_STR;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,252 +36,252 @@ use Doctrine\Common\DoctrineException;
|
||||
*/
|
||||
class JoinedSubclassPersister extends StandardEntityPersister
|
||||
{
|
||||
/** Map that maps column names to the table names that own them.
|
||||
* This is mainly a temporary cache, used during a single request.
|
||||
*/
|
||||
private $_owningTableMap = array();
|
||||
/** Map that maps column names to the table names that own them.
|
||||
* This is mainly a temporary cache, used during a single request.
|
||||
*/
|
||||
private $_owningTableMap = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
protected function _prepareData($entity, array &$result, $isInsert = false)
|
||||
{
|
||||
parent::_prepareData($entity, $result, $isInsert);
|
||||
// Populate the discriminator column
|
||||
if ($isInsert) {
|
||||
$discColumn = $this->_class->discriminatorColumn;
|
||||
$rootClass = $this->_em->getClassMetadata($this->_class->rootEntityName);
|
||||
$result[$rootClass->primaryTable['name']][$discColumn['name']] =
|
||||
$this->_class->discriminatorValue;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
protected function _prepareData($entity, array &$result, $isInsert = false)
|
||||
{
|
||||
parent::_prepareData($entity, $result, $isInsert);
|
||||
// Populate the discriminator column
|
||||
if ($isInsert) {
|
||||
$discColumn = $this->_class->discriminatorColumn;
|
||||
$rootClass = $this->_em->getClassMetadata($this->_class->rootEntityName);
|
||||
$result[$rootClass->primaryTable['name']][$discColumn['name']] =
|
||||
$this->_class->discriminatorValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function getOwningTable($fieldName)
|
||||
{
|
||||
if ( ! isset($this->_owningTableMap[$fieldName])) {
|
||||
if (isset($this->_class->associationMappings[$fieldName])) {
|
||||
if (isset($this->_class->inheritedAssociationFields[$fieldName])) {
|
||||
$this->_owningTableMap[$fieldName] = $this->_em->getClassMetadata(
|
||||
$this->_class->inheritedAssociationFields[$fieldName])->primaryTable['name'];
|
||||
} else {
|
||||
$this->_owningTableMap[$fieldName] = $this->_class->primaryTable['name'];
|
||||
}
|
||||
} else if (isset($this->_class->fieldMappings[$fieldName]['inherited'])) {
|
||||
$this->_owningTableMap[$fieldName] = $this->_em->getClassMetadata(
|
||||
$this->_class->fieldMappings[$fieldName]['inherited'])->primaryTable['name'];
|
||||
} else {
|
||||
$this->_owningTableMap[$fieldName] = $this->_class->primaryTable['name'];
|
||||
}
|
||||
}
|
||||
return $this->_owningTableMap[$fieldName];
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function getOwningTable($fieldName)
|
||||
{
|
||||
if ( ! isset($this->_owningTableMap[$fieldName])) {
|
||||
if (isset($this->_class->associationMappings[$fieldName])) {
|
||||
if (isset($this->_class->inheritedAssociationFields[$fieldName])) {
|
||||
$this->_owningTableMap[$fieldName] = $this->_em->getClassMetadata(
|
||||
$this->_class->inheritedAssociationFields[$fieldName])->primaryTable['name'];
|
||||
} else {
|
||||
$this->_owningTableMap[$fieldName] = $this->_class->primaryTable['name'];
|
||||
}
|
||||
} else if (isset($this->_class->fieldMappings[$fieldName]['inherited'])) {
|
||||
$this->_owningTableMap[$fieldName] = $this->_em->getClassMetadata(
|
||||
$this->_class->fieldMappings[$fieldName]['inherited'])->primaryTable['name'];
|
||||
} else {
|
||||
$this->_owningTableMap[$fieldName] = $this->_class->primaryTable['name'];
|
||||
}
|
||||
}
|
||||
return $this->_owningTableMap[$fieldName];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function executeInserts()
|
||||
{
|
||||
if ( ! $this->_queuedInserts) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
public function executeInserts()
|
||||
{
|
||||
if ( ! $this->_queuedInserts) {
|
||||
return;
|
||||
}
|
||||
|
||||
$postInsertIds = array();
|
||||
$idGen = $this->_class->idGenerator;
|
||||
$isPostInsertId = $idGen->isPostInsertGenerator();
|
||||
$sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
|
||||
$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);
|
||||
$sql[$this->_class->primaryTable['name']] = $this->_class->insertSql;
|
||||
foreach ($this->_class->parentClasses as $parentClass) {
|
||||
$parentClass = $this->_em->getClassMetadata($parentClass);
|
||||
$sql[$parentClass->primaryTable['name']] = $parentClass->insertSql;
|
||||
$stmts[$parentClass->primaryTable['name']] = $this->_conn->prepare($parentClass->insertSql);
|
||||
}
|
||||
$rootTableName = $this->_em->getClassMetadata($this->_class->rootEntityName)->primaryTable['name'];
|
||||
// Prepare statements for all tables
|
||||
$stmts = $classes = array();
|
||||
$stmts[$this->_class->primaryTable['name']] = $this->_conn->prepare($this->_class->insertSql);
|
||||
$sql[$this->_class->primaryTable['name']] = $this->_class->insertSql;
|
||||
foreach ($this->_class->parentClasses as $parentClass) {
|
||||
$parentClass = $this->_em->getClassMetadata($parentClass);
|
||||
$sql[$parentClass->primaryTable['name']] = $parentClass->insertSql;
|
||||
$stmts[$parentClass->primaryTable['name']] = $this->_conn->prepare($parentClass->insertSql);
|
||||
}
|
||||
$rootTableName = $this->_em->getClassMetadata($this->_class->rootEntityName)->primaryTable['name'];
|
||||
|
||||
foreach ($this->_queuedInserts as $entity) {
|
||||
$insertData = array();
|
||||
$this->_prepareData($entity, $insertData, true);
|
||||
foreach ($this->_queuedInserts as $entity) {
|
||||
$insertData = array();
|
||||
$this->_prepareData($entity, $insertData, true);
|
||||
|
||||
// Execute insert on root table
|
||||
$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]);
|
||||
// Execute insert on root table
|
||||
$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]);
|
||||
|
||||
if ($isPostInsertId) {
|
||||
$id = $idGen->generate($this->_em, $entity);
|
||||
$postInsertIds[$id] = $entity;
|
||||
} else {
|
||||
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||
}
|
||||
if ($isPostInsertId) {
|
||||
$id = $idGen->generate($this->_em, $entity);
|
||||
$postInsertIds[$id] = $entity;
|
||||
} else {
|
||||
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||
}
|
||||
|
||||
// Execute inserts on subtables
|
||||
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();
|
||||
}
|
||||
}
|
||||
// Execute inserts on subtables
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($stmts as $stmt)
|
||||
$stmt->closeCursor();
|
||||
foreach ($stmts as $stmt)
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->_queuedInserts = array();
|
||||
$this->_queuedInserts = array();
|
||||
|
||||
return $postInsertIds;
|
||||
}
|
||||
return $postInsertIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an entity.
|
||||
*
|
||||
* @param object $entity The entity to update.
|
||||
* @override
|
||||
*/
|
||||
public function update($entity)
|
||||
{
|
||||
$updateData = array();
|
||||
$this->_prepareData($entity, $updateData);
|
||||
/**
|
||||
* Updates an entity.
|
||||
*
|
||||
* @param object $entity The entity to update.
|
||||
* @override
|
||||
*/
|
||||
public function update($entity)
|
||||
{
|
||||
$updateData = array();
|
||||
$this->_prepareData($entity, $updateData);
|
||||
|
||||
$id = array_combine(
|
||||
$this->_class->getIdentifierFieldNames(),
|
||||
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
|
||||
);
|
||||
$id = array_combine(
|
||||
$this->_class->getIdentifierFieldNames(),
|
||||
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
|
||||
);
|
||||
|
||||
foreach ($updateData as $tableName => $data) {
|
||||
$this->_conn->update($tableName, $updateData[$tableName], $id);
|
||||
}
|
||||
}
|
||||
foreach ($updateData as $tableName => $data) {
|
||||
$this->_conn->update($tableName, $updateData[$tableName], $id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an entity.
|
||||
*
|
||||
* @param object $entity The entity to delete.
|
||||
* @override
|
||||
*/
|
||||
public function delete($entity)
|
||||
{
|
||||
$id = array_combine(
|
||||
$this->_class->getIdentifierFieldNames(),
|
||||
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
|
||||
);
|
||||
/**
|
||||
* Deletes an entity.
|
||||
*
|
||||
* @param object $entity The entity to delete.
|
||||
* @override
|
||||
*/
|
||||
public function delete($entity)
|
||||
{
|
||||
$id = array_combine(
|
||||
$this->_class->getIdentifierFieldNames(),
|
||||
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
|
||||
);
|
||||
|
||||
// If the database platform supports FKs, just
|
||||
// delete the row from the root table. Cascades do the rest.
|
||||
if ($this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->_conn->delete($this->_em->getClassMetadata($this->_class->rootEntityName)
|
||||
->primaryTable['name'], $id);
|
||||
} else {
|
||||
// Delete the parent tables, starting from this class' table up to the root table
|
||||
$this->_conn->delete($this->_class->primaryTable['name'], $id);
|
||||
foreach ($this->_class->parentClasses as $parentClass) {
|
||||
$this->_conn->delete($this->_em->getClassMetadata($parentClass)->primaryTable['name'], $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the database platform supports FKs, just
|
||||
// delete the row from the root table. Cascades do the rest.
|
||||
if ($this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->_conn->delete($this->_em->getClassMetadata($this->_class->rootEntityName)
|
||||
->primaryTable['name'], $id);
|
||||
} else {
|
||||
// Delete the parent tables, starting from this class' table up to the root table
|
||||
$this->_conn->delete($this->_class->primaryTable['name'], $id);
|
||||
foreach ($this->_class->parentClasses as $parentClass) {
|
||||
$this->_conn->delete($this->_em->getClassMetadata($parentClass)->primaryTable['name'], $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SELECT SQL to select a single entity by a set of field criteria.
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return string The SQL.
|
||||
* @todo Quote identifier.
|
||||
* @override
|
||||
*/
|
||||
protected function _getSelectSingleEntitySql(array $criteria)
|
||||
{
|
||||
$tableAliases = array();
|
||||
$aliasIndex = 1;
|
||||
$idColumns = $this->_class->getIdentifierColumnNames();
|
||||
$baseTableAlias = 't0';
|
||||
|
||||
foreach (array_merge($this->_class->subClasses, $this->_class->parentClasses) as $className) {
|
||||
$tableAliases[$className] = 't' . $aliasIndex++;
|
||||
}
|
||||
/**
|
||||
* Gets the SELECT SQL to select a single entity by a set of field criteria.
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return string The SQL.
|
||||
* @todo Quote identifier.
|
||||
* @override
|
||||
*/
|
||||
protected function _getSelectSingleEntitySql(array $criteria)
|
||||
{
|
||||
$tableAliases = array();
|
||||
$aliasIndex = 1;
|
||||
$idColumns = $this->_class->getIdentifierColumnNames();
|
||||
$baseTableAlias = 't0';
|
||||
|
||||
foreach (array_merge($this->_class->subClasses, $this->_class->parentClasses) as $className) {
|
||||
$tableAliases[$className] = 't' . $aliasIndex++;
|
||||
}
|
||||
|
||||
$columnList = '';
|
||||
foreach ($this->_class->fieldMappings as $fieldName => $mapping) {
|
||||
$tableAlias = isset($mapping['inherited']) ?
|
||||
$tableAliases[$mapping['inherited']] : $baseTableAlias;
|
||||
if ($columnList != '') $columnList .= ', ';
|
||||
$columnList .= $tableAlias . '.' . $this->_class->columnNames[$fieldName];
|
||||
}
|
||||
$columnList = '';
|
||||
foreach ($this->_class->fieldMappings as $fieldName => $mapping) {
|
||||
$tableAlias = isset($mapping['inherited']) ?
|
||||
$tableAliases[$mapping['inherited']] : $baseTableAlias;
|
||||
if ($columnList != '') $columnList .= ', ';
|
||||
$columnList .= $tableAlias . '.' . $this->_class->columnNames[$fieldName];
|
||||
}
|
||||
|
||||
$sql = 'SELECT ' . $columnList . ' FROM ' . $this->_class->primaryTable['name']. ' ' . $baseTableAlias;
|
||||
$sql = 'SELECT ' . $columnList . ' FROM ' . $this->_class->primaryTable['name']. ' ' . $baseTableAlias;
|
||||
|
||||
// INNER JOIN parent tables
|
||||
foreach ($this->_class->parentClasses as $parentClassName) {
|
||||
$parentClass = $this->_em->getClassMetadata($parentClassName);
|
||||
$tableAlias = $tableAliases[$parentClassName];
|
||||
$sql .= ' INNER JOIN ' . $parentClass->primaryTable['name'] . ' ' . $tableAlias . ' ON ';
|
||||
$first = true;
|
||||
foreach ($idColumns as $idColumn) {
|
||||
if ($first) $first = false; else $sql .= ' AND ';
|
||||
$sql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn;
|
||||
}
|
||||
}
|
||||
// INNER JOIN parent tables
|
||||
foreach ($this->_class->parentClasses as $parentClassName) {
|
||||
$parentClass = $this->_em->getClassMetadata($parentClassName);
|
||||
$tableAlias = $tableAliases[$parentClassName];
|
||||
$sql .= ' INNER JOIN ' . $parentClass->primaryTable['name'] . ' ' . $tableAlias . ' ON ';
|
||||
$first = true;
|
||||
foreach ($idColumns as $idColumn) {
|
||||
if ($first) $first = false; else $sql .= ' AND ';
|
||||
$sql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn;
|
||||
}
|
||||
}
|
||||
|
||||
// OUTER JOIN sub tables
|
||||
foreach ($this->_class->subClasses as $subClassName) {
|
||||
$subClass = $this->_em->getClassMetadata($subClassName);
|
||||
$tableAlias = $tableAliases[$subClassName];
|
||||
$sql .= ' LEFT JOIN ' . $subClass->primaryTable['name'] . ' ' . $tableAlias . ' ON ';
|
||||
$first = true;
|
||||
foreach ($idColumns as $idColumn) {
|
||||
if ($first) $first = false; else $sql .= ' AND ';
|
||||
$sql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn;
|
||||
}
|
||||
}
|
||||
// OUTER JOIN sub tables
|
||||
foreach ($this->_class->subClasses as $subClassName) {
|
||||
$subClass = $this->_em->getClassMetadata($subClassName);
|
||||
$tableAlias = $tableAliases[$subClassName];
|
||||
$sql .= ' LEFT JOIN ' . $subClass->primaryTable['name'] . ' ' . $tableAlias . ' ON ';
|
||||
$first = true;
|
||||
foreach ($idColumns as $idColumn) {
|
||||
if ($first) $first = false; else $sql .= ' AND ';
|
||||
$sql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn;
|
||||
}
|
||||
}
|
||||
|
||||
$conditionSql = '';
|
||||
foreach ($criteria as $field => $value) {
|
||||
if ($conditionSql != '') $conditionSql .= ' AND ';
|
||||
$conditionSql .= $baseTableAlias . '.' . $this->_class->columnNames[$field] . ' = ?';
|
||||
}
|
||||
$conditionSql = '';
|
||||
foreach ($criteria as $field => $value) {
|
||||
if ($conditionSql != '') $conditionSql .= ' AND ';
|
||||
$conditionSql .= $baseTableAlias . '.' . $this->_class->columnNames[$field] . ' = ?';
|
||||
}
|
||||
|
||||
return $sql . ' WHERE ' . $conditionSql;
|
||||
}
|
||||
return $sql . ' WHERE ' . $conditionSql;
|
||||
}
|
||||
}
|
@ -38,348 +38,348 @@ use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
*/
|
||||
class StandardEntityPersister
|
||||
{
|
||||
/**
|
||||
* Metadata object that describes the mapping of the mapped entity class.
|
||||
*
|
||||
* @var Doctrine\ORM\Mapping\ClassMetadata
|
||||
*/
|
||||
protected $_class;
|
||||
/**
|
||||
* Metadata object that describes the mapping of the mapped entity class.
|
||||
*
|
||||
* @var Doctrine\ORM\Mapping\ClassMetadata
|
||||
*/
|
||||
protected $_class;
|
||||
|
||||
/**
|
||||
* The name of the entity the persister is used for.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entityName;
|
||||
/**
|
||||
* The name of the entity the persister is used for.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entityName;
|
||||
|
||||
/**
|
||||
* The Connection instance.
|
||||
*
|
||||
* @var Doctrine\DBAL\Connection $conn
|
||||
*/
|
||||
protected $_conn;
|
||||
/**
|
||||
* The Connection instance.
|
||||
*
|
||||
* @var Doctrine\DBAL\Connection $conn
|
||||
*/
|
||||
protected $_conn;
|
||||
|
||||
/**
|
||||
* The EntityManager instance.
|
||||
*
|
||||
* @var Doctrine\ORM\EntityManager
|
||||
*/
|
||||
protected $_em;
|
||||
/**
|
||||
* The EntityManager instance.
|
||||
*
|
||||
* @var Doctrine\ORM\EntityManager
|
||||
*/
|
||||
protected $_em;
|
||||
|
||||
/**
|
||||
* Queued inserts.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_queuedInserts = array();
|
||||
/**
|
||||
* Queued inserts.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_queuedInserts = array();
|
||||
|
||||
/**
|
||||
* Initializes a new instance of a class derived from AbstractEntityPersister
|
||||
* that uses the given EntityManager and persists instances of the class described
|
||||
* by the given class metadata descriptor.
|
||||
*/
|
||||
public function __construct(EntityManager $em, ClassMetadata $class)
|
||||
{
|
||||
$this->_em = $em;
|
||||
$this->_entityName = $class->name;
|
||||
$this->_conn = $em->getConnection();
|
||||
$this->_class = $class;
|
||||
}
|
||||
/**
|
||||
* Initializes a new instance of a class derived from AbstractEntityPersister
|
||||
* that uses the given EntityManager and persists instances of the class described
|
||||
* by the given class metadata descriptor.
|
||||
*/
|
||||
public function __construct(EntityManager $em, ClassMetadata $class)
|
||||
{
|
||||
$this->_em = $em;
|
||||
$this->_entityName = $class->name;
|
||||
$this->_conn = $em->getConnection();
|
||||
$this->_class = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entity to the queued inserts.
|
||||
*
|
||||
* @param object $entity
|
||||
*/
|
||||
public function addInsert($entity)
|
||||
{
|
||||
$this->_queuedInserts[spl_object_hash($entity)] = $entity;
|
||||
}
|
||||
/**
|
||||
* Adds an entity to the queued inserts.
|
||||
*
|
||||
* @param object $entity
|
||||
*/
|
||||
public function addInsert($entity)
|
||||
{
|
||||
$this->_queuedInserts[spl_object_hash($entity)] = $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all queued inserts.
|
||||
*
|
||||
* @return array An array of any generated post-insert IDs.
|
||||
*/
|
||||
public function executeInserts()
|
||||
{
|
||||
if ( ! $this->_queuedInserts) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Executes all queued inserts.
|
||||
*
|
||||
* @return array An array of any generated post-insert IDs.
|
||||
*/
|
||||
public function executeInserts()
|
||||
{
|
||||
if ( ! $this->_queuedInserts) {
|
||||
return;
|
||||
}
|
||||
|
||||
$postInsertIds = array();
|
||||
$idGen = $this->_class->idGenerator;
|
||||
$isPostInsertId = $idGen->isPostInsertGenerator();
|
||||
$postInsertIds = array();
|
||||
$idGen = $this->_class->idGenerator;
|
||||
$isPostInsertId = $idGen->isPostInsertGenerator();
|
||||
|
||||
$stmt = $this->_conn->prepare($this->_class->insertSql);
|
||||
$primaryTableName = $this->_class->primaryTable['name'];
|
||||
$sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
|
||||
$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);
|
||||
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()*/);
|
||||
}
|
||||
}
|
||||
$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();
|
||||
$stmt->execute();
|
||||
|
||||
if ($isPostInsertId) {
|
||||
$postInsertIds[$idGen->generate($this->_em, $entity)] = $entity;
|
||||
}
|
||||
}
|
||||
if ($isPostInsertId) {
|
||||
$postInsertIds[$idGen->generate($this->_em, $entity)] = $entity;
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
$this->_queuedInserts = array();
|
||||
$stmt->closeCursor();
|
||||
$this->_queuedInserts = array();
|
||||
|
||||
return $postInsertIds;
|
||||
}
|
||||
return $postInsertIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an entity.
|
||||
*
|
||||
* @param object $entity The entity to update.
|
||||
*/
|
||||
public function update($entity)
|
||||
{
|
||||
$updateData = array();
|
||||
$this->_prepareData($entity, $updateData);
|
||||
$id = array_combine($this->_class->getIdentifierFieldNames(),
|
||||
$this->_em->getUnitOfWork()->getEntityIdentifier($entity));
|
||||
$tableName = $this->_class->primaryTable['name'];
|
||||
$this->_conn->update($tableName, $updateData[$tableName], $id);
|
||||
}
|
||||
/**
|
||||
* Updates an entity.
|
||||
*
|
||||
* @param object $entity The entity to update.
|
||||
*/
|
||||
public function update($entity)
|
||||
{
|
||||
$updateData = array();
|
||||
$this->_prepareData($entity, $updateData);
|
||||
$id = array_combine($this->_class->getIdentifierFieldNames(),
|
||||
$this->_em->getUnitOfWork()->getEntityIdentifier($entity));
|
||||
$tableName = $this->_class->primaryTable['name'];
|
||||
$this->_conn->update($tableName, $updateData[$tableName], $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an entity.
|
||||
*
|
||||
* @param object $entity The entity to delete.
|
||||
*/
|
||||
public function delete($entity)
|
||||
{
|
||||
$id = array_combine(
|
||||
$this->_class->getIdentifierFieldNames(),
|
||||
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
|
||||
);
|
||||
$this->_conn->delete($this->_class->primaryTable['name'], $id);
|
||||
}
|
||||
/**
|
||||
* Deletes an entity.
|
||||
*
|
||||
* @param object $entity The entity to delete.
|
||||
*/
|
||||
public function delete($entity)
|
||||
{
|
||||
$id = array_combine(
|
||||
$this->_class->getIdentifierFieldNames(),
|
||||
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
|
||||
);
|
||||
$this->_conn->delete($this->_class->primaryTable['name'], $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entity to delete.
|
||||
*
|
||||
* @param object $entity
|
||||
*/
|
||||
public function addDelete($entity)
|
||||
{
|
||||
/**
|
||||
* Adds an entity to delete.
|
||||
*
|
||||
* @param object $entity
|
||||
*/
|
||||
public function addDelete($entity)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all pending entity deletions.
|
||||
*
|
||||
* @see addDelete()
|
||||
*/
|
||||
public function executeDeletions()
|
||||
{
|
||||
/**
|
||||
* Executes all pending entity deletions.
|
||||
*
|
||||
* @see addDelete()
|
||||
*/
|
||||
public function executeDeletions()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ClassMetadata instance of the entity class this persister is used for.
|
||||
*
|
||||
* @return Doctrine\ORM\Mapping\ClassMetadata
|
||||
*/
|
||||
public function getClassMetadata()
|
||||
{
|
||||
return $this->_class;
|
||||
}
|
||||
/**
|
||||
* Gets the ClassMetadata instance of the entity class this persister is used for.
|
||||
*
|
||||
* @return Doctrine\ORM\Mapping\ClassMetadata
|
||||
*/
|
||||
public function getClassMetadata()
|
||||
{
|
||||
return $this->_class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the table name to use for temporary identifier tables.
|
||||
*/
|
||||
public function getTemporaryIdTableName()
|
||||
{
|
||||
//...
|
||||
}
|
||||
/**
|
||||
* Gets the table name to use for temporary identifier tables.
|
||||
*/
|
||||
public function getTemporaryIdTableName()
|
||||
{
|
||||
//...
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the data changeset of an entity for database insertion.
|
||||
* The array that is passed as the second parameter is filled with
|
||||
* <columnName> => <value> pairs, grouped by table name, during this preparation.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* array(
|
||||
* 'foo_table' => array('column1' => 'value1', 'column2' => 'value2', ...),
|
||||
* 'bar_table' => array('columnX' => 'valueX', 'columnY' => 'valueY', ...),
|
||||
* ...
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* Notes to inheritors: Be sure to call <code>parent::_prepareData($entity, $result, $isInsert);</code>
|
||||
*
|
||||
* @param object $entity
|
||||
* @param array $result The reference to the data array.
|
||||
* @param boolean $isInsert
|
||||
*/
|
||||
protected function _prepareData($entity, array &$result, $isInsert = false)
|
||||
{
|
||||
$platform = $this->_conn->getDatabasePlatform();
|
||||
$uow = $this->_em->getUnitOfWork();
|
||||
/**
|
||||
* Prepares the data changeset of an entity for database insertion.
|
||||
* The array that is passed as the second parameter is filled with
|
||||
* <columnName> => <value> pairs, grouped by table name, during this preparation.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* array(
|
||||
* 'foo_table' => array('column1' => 'value1', 'column2' => 'value2', ...),
|
||||
* 'bar_table' => array('columnX' => 'valueX', 'columnY' => 'valueY', ...),
|
||||
* ...
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* Notes to inheritors: Be sure to call <code>parent::_prepareData($entity, $result, $isInsert);</code>
|
||||
*
|
||||
* @param object $entity
|
||||
* @param array $result The reference to the data array.
|
||||
* @param boolean $isInsert
|
||||
*/
|
||||
protected function _prepareData($entity, array &$result, $isInsert = false)
|
||||
{
|
||||
$platform = $this->_conn->getDatabasePlatform();
|
||||
$uow = $this->_em->getUnitOfWork();
|
||||
|
||||
foreach ($uow->getEntityChangeSet($entity) as $field => $change) {
|
||||
$oldVal = $change[0];
|
||||
$newVal = $change[1];
|
||||
foreach ($uow->getEntityChangeSet($entity) as $field => $change) {
|
||||
$oldVal = $change[0];
|
||||
$newVal = $change[1];
|
||||
|
||||
$columnName = $this->_class->getColumnName($field);
|
||||
$columnName = $this->_class->getColumnName($field);
|
||||
|
||||
if (isset($this->_class->associationMappings[$field])) {
|
||||
$assocMapping = $this->_class->associationMappings[$field];
|
||||
// Only owning side of x-1 associations can have a FK column.
|
||||
if ( ! $assocMapping->isOneToOne() || $assocMapping->isInverseSide()) {
|
||||
continue;
|
||||
}
|
||||
if (isset($this->_class->associationMappings[$field])) {
|
||||
$assocMapping = $this->_class->associationMappings[$field];
|
||||
// Only owning side of x-1 associations can have a FK column.
|
||||
if ( ! $assocMapping->isOneToOne() || $assocMapping->isInverseSide()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Special case: One-one self-referencing of the same class.
|
||||
if ($newVal !== null && $assocMapping->sourceEntityName == $assocMapping->targetEntityName) {
|
||||
$oid = spl_object_hash($newVal);
|
||||
$isScheduledForInsert = $uow->isRegisteredNew($newVal);
|
||||
if (isset($this->_queuedInserts[$oid]) || $isScheduledForInsert) {
|
||||
// The associated entity $newVal is not yet persisted, so we must
|
||||
// set $newVal = null, in order to insert a null value and update later.
|
||||
$newVal = null;
|
||||
} else if ($isInsert && ! $isScheduledForInsert && $uow->getEntityState($newVal) == UnitOfWork::STATE_MANAGED) {
|
||||
// $newVal is already fully persisted
|
||||
// Clear changeset of $newVal, so that only the identifier is updated.
|
||||
// Not sure this is really rock-solid here but it seems to work.
|
||||
$uow->clearEntityChangeSet($oid);
|
||||
$uow->propertyChanged($newVal, $field, $entity, $entity);
|
||||
}
|
||||
}
|
||||
// Special case: One-one self-referencing of the same class.
|
||||
if ($newVal !== null && $assocMapping->sourceEntityName == $assocMapping->targetEntityName) {
|
||||
$oid = spl_object_hash($newVal);
|
||||
$isScheduledForInsert = $uow->isRegisteredNew($newVal);
|
||||
if (isset($this->_queuedInserts[$oid]) || $isScheduledForInsert) {
|
||||
// The associated entity $newVal is not yet persisted, so we must
|
||||
// set $newVal = null, in order to insert a null value and update later.
|
||||
$newVal = null;
|
||||
} else if ($isInsert && ! $isScheduledForInsert && $uow->getEntityState($newVal) == UnitOfWork::STATE_MANAGED) {
|
||||
// $newVal is already fully persisted
|
||||
// Clear changeset of $newVal, so that only the identifier is updated.
|
||||
// Not sure this is really rock-solid here but it seems to work.
|
||||
$uow->clearEntityChangeSet($oid);
|
||||
$uow->propertyChanged($newVal, $field, $entity, $entity);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($assocMapping->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) {
|
||||
$otherClass = $this->_em->getClassMetadata($assocMapping->targetEntityName);
|
||||
if ($newVal === null) {
|
||||
$result[$this->getOwningTable($field)][$sourceColumn] = null;
|
||||
} else {
|
||||
$result[$this->getOwningTable($field)][$sourceColumn] =
|
||||
$otherClass->reflFields[$otherClass->fieldNames[$targetColumn]]->getValue($newVal);
|
||||
}
|
||||
}
|
||||
} else if ($newVal === null) {
|
||||
$result[$this->getOwningTable($field)][$columnName] = null;
|
||||
} else {
|
||||
$result[$this->getOwningTable($field)][$columnName] = Type::getType(
|
||||
$this->_class->fieldMappings[$field]['type'])
|
||||
->convertToDatabaseValue($newVal, $platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($assocMapping->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) {
|
||||
$otherClass = $this->_em->getClassMetadata($assocMapping->targetEntityName);
|
||||
if ($newVal === null) {
|
||||
$result[$this->getOwningTable($field)][$sourceColumn] = null;
|
||||
} else {
|
||||
$result[$this->getOwningTable($field)][$sourceColumn] =
|
||||
$otherClass->reflFields[$otherClass->fieldNames[$targetColumn]]->getValue($newVal);
|
||||
}
|
||||
}
|
||||
} else if ($newVal === null) {
|
||||
$result[$this->getOwningTable($field)][$columnName] = null;
|
||||
} else {
|
||||
$result[$this->getOwningTable($field)][$columnName] = Type::getType(
|
||||
$this->_class->fieldMappings[$field]['type'])
|
||||
->convertToDatabaseValue($newVal, $platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the table that owns the column the given field is mapped to.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @return string
|
||||
*/
|
||||
public function getOwningTable($fieldName)
|
||||
{
|
||||
return $this->_class->primaryTable['name'];
|
||||
}
|
||||
/**
|
||||
* Gets the name of the table that owns the column the given field is mapped to.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @return string
|
||||
*/
|
||||
public function getOwningTable($fieldName)
|
||||
{
|
||||
return $this->_class->primaryTable['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an entity by a list of field criteria.
|
||||
*
|
||||
* @param array $criteria The criteria by which to load the entity.
|
||||
* @param object $entity The entity to load the data into. If not specified,
|
||||
* a new entity is created.
|
||||
*/
|
||||
public function load(array $criteria, $entity = null)
|
||||
{
|
||||
$stmt = $this->_conn->prepare($this->_getSelectSingleEntitySql($criteria));
|
||||
$stmt->execute(array_values($criteria));
|
||||
$data = array();
|
||||
foreach ($stmt->fetch(\PDO::FETCH_ASSOC) as $column => $value) {
|
||||
$fieldName = $this->_class->fieldNames[$column];
|
||||
$data[$fieldName] = Type::getType($this->_class->getTypeOfField($fieldName))
|
||||
->convertToPHPValue($value);
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
/**
|
||||
* Loads an entity by a list of field criteria.
|
||||
*
|
||||
* @param array $criteria The criteria by which to load the entity.
|
||||
* @param object $entity The entity to load the data into. If not specified,
|
||||
* a new entity is created.
|
||||
*/
|
||||
public function load(array $criteria, $entity = null)
|
||||
{
|
||||
$stmt = $this->_conn->prepare($this->_getSelectSingleEntitySql($criteria));
|
||||
$stmt->execute(array_values($criteria));
|
||||
$data = array();
|
||||
foreach ($stmt->fetch(\PDO::FETCH_ASSOC) as $column => $value) {
|
||||
$fieldName = $this->_class->fieldNames[$column];
|
||||
$data[$fieldName] = Type::getType($this->_class->getTypeOfField($fieldName))
|
||||
->convertToPHPValue($value);
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($entity === null) {
|
||||
$entity = $this->_em->getUnitOfWork()->createEntity($this->_entityName, $data);
|
||||
} else {
|
||||
foreach ($data as $field => $value) {
|
||||
$this->_class->reflFields[$field]->setValue($entity, $value);
|
||||
}
|
||||
$id = array();
|
||||
if ($this->_class->isIdentifierComposite) {
|
||||
foreach ($this->_class->identifier as $fieldName) {
|
||||
$id[] = $data[$fieldName];
|
||||
}
|
||||
} else {
|
||||
$id = array($data[$this->_class->getSingleIdentifierFieldName()]);
|
||||
}
|
||||
$this->_em->getUnitOfWork()->registerManaged($entity, $id, $data);
|
||||
}
|
||||
if ($entity === null) {
|
||||
$entity = $this->_em->getUnitOfWork()->createEntity($this->_entityName, $data);
|
||||
} else {
|
||||
foreach ($data as $field => $value) {
|
||||
$this->_class->reflFields[$field]->setValue($entity, $value);
|
||||
}
|
||||
$id = array();
|
||||
if ($this->_class->isIdentifierComposite) {
|
||||
foreach ($this->_class->identifier as $fieldName) {
|
||||
$id[] = $data[$fieldName];
|
||||
}
|
||||
} else {
|
||||
$id = array($data[$this->_class->getSingleIdentifierFieldName()]);
|
||||
}
|
||||
$this->_em->getUnitOfWork()->registerManaged($entity, $id, $data);
|
||||
}
|
||||
|
||||
if ( ! $this->_em->getConfiguration()->getAllowPartialObjects()) {
|
||||
foreach ($this->_class->associationMappings as $field => $assoc) {
|
||||
if ($assoc->isOneToOne()) {
|
||||
if ($assoc->isLazilyFetched) {
|
||||
// Inject proxy
|
||||
$proxy = $this->_em->getProxyGenerator()->getAssociationProxy($entity, $assoc);
|
||||
$this->_class->reflFields[$field]->setValue($entity, $proxy);
|
||||
} else {
|
||||
//TODO: Eager fetch?
|
||||
}
|
||||
} else {
|
||||
// Inject collection
|
||||
$this->_class->reflFields[$field]->setValue(
|
||||
$entity, new PersistentCollection($this->_em,
|
||||
$this->_em->getClassMetadata($assoc->targetEntityName)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( ! $this->_em->getConfiguration()->getAllowPartialObjects()) {
|
||||
foreach ($this->_class->associationMappings as $field => $assoc) {
|
||||
if ($assoc->isOneToOne()) {
|
||||
if ($assoc->isLazilyFetched) {
|
||||
// Inject proxy
|
||||
$proxy = $this->_em->getProxyGenerator()->getAssociationProxy($entity, $assoc);
|
||||
$this->_class->reflFields[$field]->setValue($entity, $proxy);
|
||||
} else {
|
||||
//TODO: Eager fetch?
|
||||
}
|
||||
} else {
|
||||
// Inject collection
|
||||
$this->_class->reflFields[$field]->setValue(
|
||||
$entity, new PersistentCollection($this->_em,
|
||||
$this->_em->getClassMetadata($assoc->targetEntityName)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SELECT SQL to select a single entity by a set of field criteria.
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return string The SQL.
|
||||
* @todo Quote identifier.
|
||||
*/
|
||||
protected function _getSelectSingleEntitySql(array $criteria)
|
||||
{
|
||||
$columnList = '';
|
||||
foreach ($this->_class->columnNames as $column) {
|
||||
if ($columnList != '') $columnList .= ', ';
|
||||
$columnList .= $column;
|
||||
}
|
||||
/**
|
||||
* Gets the SELECT SQL to select a single entity by a set of field criteria.
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return string The SQL.
|
||||
* @todo Quote identifier.
|
||||
*/
|
||||
protected function _getSelectSingleEntitySql(array $criteria)
|
||||
{
|
||||
$columnList = '';
|
||||
foreach ($this->_class->columnNames as $column) {
|
||||
if ($columnList != '') $columnList .= ', ';
|
||||
$columnList .= $column;
|
||||
}
|
||||
|
||||
$conditionSql = '';
|
||||
foreach ($criteria as $field => $value) {
|
||||
if ($conditionSql != '') $conditionSql .= ' AND ';
|
||||
$conditionSql .= $this->_class->columnNames[$field] . ' = ?';
|
||||
}
|
||||
$conditionSql = '';
|
||||
foreach ($criteria as $field => $value) {
|
||||
if ($conditionSql != '') $conditionSql .= ' AND ';
|
||||
$conditionSql .= $this->_class->columnNames[$field] . ' = ?';
|
||||
}
|
||||
|
||||
return 'SELECT ' . $columnList . ' FROM ' . $this->_class->getTableName()
|
||||
. ' WHERE ' . $conditionSql;
|
||||
}
|
||||
return 'SELECT ' . $columnList . ' FROM ' . $this->_class->getTableName()
|
||||
. ' WHERE ' . $conditionSql;
|
||||
}
|
||||
}
|
@ -28,12 +28,12 @@ namespace Doctrine\ORM\Query\AST;
|
||||
*/
|
||||
class StateFieldPathExpression extends Node
|
||||
{
|
||||
//const TYPE_COLLECTION_VALUED_ASSOCIATION = 1;
|
||||
//const TYPE_SINGLE_VALUED_ASSOCIATION = 2;
|
||||
//const TYPE_STATE_FIELD = 3;
|
||||
//private $_type;
|
||||
|
||||
|
||||
//const TYPE_COLLECTION_VALUED_ASSOCIATION = 1;
|
||||
//const TYPE_SINGLE_VALUED_ASSOCIATION = 2;
|
||||
//const TYPE_STATE_FIELD = 3;
|
||||
//private $_type;
|
||||
|
||||
|
||||
private $_parts;
|
||||
// Information that is attached during semantical analysis.
|
||||
private $_isSimpleStateFieldPathExpression = false;
|
||||
|
@ -884,7 +884,7 @@ class Parser
|
||||
|
||||
while ($this->_lexer->isNextToken('.')) {
|
||||
if ($stateFieldSeen) {
|
||||
$this->syntaxError();
|
||||
$this->syntaxError();
|
||||
}
|
||||
$this->match('.');
|
||||
$part = $this->_IdentificationVariable();
|
||||
@ -1098,7 +1098,7 @@ class Parser
|
||||
{
|
||||
$condPrimary = new AST\ConditionalPrimary;
|
||||
if ($this->_lexer->isNextToken('(')) {
|
||||
// Peek beyond the matching closing paranthesis ')'
|
||||
// Peek beyond the matching closing paranthesis ')'
|
||||
$numUnmatched = 1;
|
||||
$peek = $this->_lexer->peek();
|
||||
while ($numUnmatched > 0) {
|
||||
@ -1276,8 +1276,8 @@ class Parser
|
||||
*/
|
||||
private function _isNextAllAnySome()
|
||||
{
|
||||
return $this->_lexer->lookahead['type'] === Lexer::T_ALL ||
|
||||
$this->_lexer->lookahead['type'] === Lexer::T_ANY ||
|
||||
return $this->_lexer->lookahead['type'] === Lexer::T_ALL ||
|
||||
$this->_lexer->lookahead['type'] === Lexer::T_ANY ||
|
||||
$this->_lexer->lookahead['type'] === Lexer::T_SOME;
|
||||
}
|
||||
|
||||
@ -1499,7 +1499,7 @@ class Parser
|
||||
}
|
||||
|
||||
/**
|
||||
* Subselect ::= SimpleSelectClause SubselectFromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
|
||||
* Subselect ::= SimpleSelectClause SubselectFromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
|
||||
*/
|
||||
public function _Subselect()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user