1
0
mirror of synced 2025-02-20 22:23:14 +03:00

use quote strategy in persister

This commit is contained in:
Fabio B. Silva 2012-06-01 20:44:26 -03:00
parent 2af7b3fd38
commit 7f64474f3e
5 changed files with 30 additions and 22 deletions

View File

@ -45,6 +45,13 @@ abstract class AbstractCollectionPersister
*/
protected $_uow;
/**
* The quote strategy.
*
* @var \Doctrine\ORM\Mapping\QuoteStrategy
*/
protected $quoteStrategy;
/**
* Initializes a new instance of a class derived from AbstractCollectionPersister.
*
@ -52,9 +59,10 @@ abstract class AbstractCollectionPersister
*/
public function __construct(EntityManager $em)
{
$this->_em = $em;
$this->_uow = $em->getUnitOfWork();
$this->_conn = $em->getConnection();
$this->_em = $em;
$this->_uow = $em->getUnitOfWork();
$this->_conn = $em->getConnection();
$this->quoteStrategy = $em->getQuoteStrategy();
}
/**

View File

@ -61,7 +61,7 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r')
{
$columnName = $class->columnNames[$field];
$sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $class->getQuotedColumnName($field, $this->_platform);
$sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $this->quoteStrategy->getColumnName($field, $class);
$columnAlias = $this->getSQLColumnAlias($columnName);
$this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name);

View File

@ -175,7 +175,7 @@ class BasicEntityPersister
*
* @var \Doctrine\ORM\Mapping\QuoteStrategy
*/
private $quoteStrategy;
protected $quoteStrategy;
/**
* Initializes a new <tt>BasicEntityPersister</tt> that uses the given EntityManager
@ -295,7 +295,7 @@ class BasicEntityPersister
//FIXME: Order with composite keys might not be correct
$sql = 'SELECT ' . $versionFieldColumnName
. ' FROM ' . $versionedClass->getQuotedTableName($this->_platform)
. ' FROM ' . $this->quoteStrategy->getTableName($versionedClass)
. ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?';
$value = $this->_conn->fetchColumn($sql, array_values((array)$id));
@ -469,7 +469,7 @@ class BasicEntityPersister
$identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$this->deleteJoinTableRecords($identifier);
$id = array_combine($this->quoteStrategy->getIdentifierColumnNames($this->_class), $identifier);
$id = array_combine($this->_class->getIdentifierColumnNames(), $identifier);
$this->_conn->delete($this->quoteStrategy->getTableName($this->_class), $id);
}

View File

@ -105,7 +105,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$tableName = $cm->getTableName();
$this->_owningTableMap[$fieldName] = $tableName;
$this->_quotedTableMap[$tableName] = $cm->getQuotedTableName($this->_platform);
$this->_quotedTableMap[$tableName] = $this->quoteStrategy->getTableName($cm);
return $tableName;
}
@ -225,7 +225,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
// Make sure the table with the version column is updated even if no columns on that
// table were affected.
if ($isVersioned && ! isset($updateData[$versionedTable])) {
$this->_updateTable($entity, $versionedClass->getQuotedTableName($this->_platform), array(), true);
$this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass), array(), true);
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$this->assignDefaultVersionValue($entity, $id);
@ -247,11 +247,11 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
// delete the row from the root table. Cascades do the rest.
if ($this->_platform->supportsForeignKeyConstraints()) {
$this->_conn->delete(
$this->_em->getClassMetadata($this->_class->rootEntityName)->getQuotedTableName($this->_platform), $id
$this->quoteStrategy->getTableName($this->_em->getClassMetadata($this->_class->rootEntityName)), $id
);
} else {
// Delete from all tables individually, starting from this class' table up to the root table.
$this->_conn->delete($this->_class->getQuotedTableName($this->_platform), $id);
$this->_conn->delete($this->quoteStrategy->getTableName($this->_class), $id);
foreach ($this->_class->parentClasses as $parentClass) {
$this->_conn->delete(

View File

@ -78,11 +78,10 @@ class ManyToManyPersister extends AbstractCollectionPersister
*/
protected function _getInsertRowSQL(PersistentCollection $coll)
{
$mapping = $coll->getMapping();
$columns = $mapping['joinTableColumns'];
$class = $this->_em->getClassMetadata(get_class($coll->getOwner()));
$joinTable = $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform());
$mapping = $coll->getMapping();
$columns = $mapping['joinTableColumns'];
$class = $this->_em->getClassMetadata(get_class($coll->getOwner()));
$joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class);
return 'INSERT INTO ' . $joinTable . ' (' . implode(', ', $columns) . ')'
. ' VALUES (' . implode(', ', array_fill(0, count($columns), '?')) . ')';
@ -150,10 +149,11 @@ class ManyToManyPersister extends AbstractCollectionPersister
*/
protected function _getDeleteSQL(PersistentCollection $coll)
{
$class = $this->_em->getClassMetadata(get_class($coll->getOwner()));
$mapping = $coll->getMapping();
$class = $this->_em->getClassMetadata(get_class($coll->getOwner()));
$mapping = $coll->getMapping();
$joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class);
return 'DELETE FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform())
return 'DELETE FROM ' . $joinTable
. ' WHERE ' . implode(' = ? AND ', array_keys($mapping['relationToSourceKeyColumns'])) . ' = ?';
}
@ -224,7 +224,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
}
$sql = 'SELECT COUNT(*)'
. ' FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) . ' t'
. ' FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class) . ' t'
. $joinTargetEntitySQL
. ' WHERE ' . implode(' AND ', $whereClauses);
@ -326,7 +326,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
$targetId = $uow->getEntityIdentifier($element);
}
$quotedJoinTable = $sourceClass->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform());
$quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass);
$whereClauses = array();
$params = array();
@ -387,7 +387,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
$joinTargetEntitySQL = '';
if ($filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) {
$joinTargetEntitySQL = ' JOIN '
. $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te'
. $this->quoteStrategy->getTableName($targetClass) . ' te'
. ' ON';
$joinTargetEntitySQLClauses = array();