1
0
mirror of synced 2024-12-13 14:56:01 +03:00

remove '_' prefix at BasicEntityPersister

This commit is contained in:
Fabio B. Silva 2012-07-22 13:42:43 -03:00
parent 262c3eea6b
commit b998a522b0
6 changed files with 477 additions and 475 deletions

View File

@ -36,14 +36,14 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
/**
* {@inheritdoc}
*/
protected function _prepareInsertData($entity)
protected function prepareInsertData($entity)
{
$data = parent::_prepareInsertData($entity);
$data = parent::prepareInsertData($entity);
// Populate the discriminator column
$discColumn = $this->_class->discriminatorColumn;
$this->_columnTypes[$discColumn['name']] = $discColumn['type'];
$data[$this->_getDiscriminatorColumnTableName()][$discColumn['name']] = $this->_class->discriminatorValue;
$discColumn = $this->class->discriminatorColumn;
$this->columnTypes[$discColumn['name']] = $discColumn['type'];
$data[$this->getDiscriminatorColumnTableName()][$discColumn['name']] = $this->class->discriminatorValue;
return $data;
}
@ -53,21 +53,21 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
*
* @return string The table name.
*/
abstract protected function _getDiscriminatorColumnTableName();
abstract protected function getDiscriminatorColumnTableName();
/**
* {@inheritdoc}
*/
protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r')
protected function getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r')
{
$columnName = $class->columnNames[$field];
$sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $this->quoteStrategy->getColumnName($field, $class, $this->_platform);
$sql = $this->getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $this->quoteStrategy->getColumnName($field, $class, $this->platform);
$columnAlias = $this->getSQLColumnAlias($columnName);
$this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name);
$this->rsm->addFieldResult($alias, $columnAlias, $field, $class->name);
if (isset($class->fieldMappings[$field]['requireSQLConversion'])) {
$type = Type::getType($class->getTypeOfField($field));
$sql = $type->convertToPHPValueSQL($sql, $this->_platform);
$sql = $type->convertToPHPValueSQL($sql, $this->platform);
}
return $sql . ' AS ' . $columnAlias;
@ -76,7 +76,7 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $className)
{
$columnAlias = $this->getSQLColumnAlias($joinColumnName);
$this->_rsm->addMetaResult('r', $columnAlias, $joinColumnName);
$this->rsm->addMetaResult('r', $columnAlias, $joinColumnName);
return $tableAlias . '.' . $joinColumnName . ' AS ' . $columnAlias;
}

File diff suppressed because it is too large Load Diff

View File

@ -45,23 +45,23 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*
* @var array
*/
private $_owningTableMap = array();
private $owningTableMap = array();
/**
* Map of table to quoted table names.
*
* @var array
*/
private $_quotedTableMap = array();
private $quotedTableMap = array();
/**
* {@inheritdoc}
*/
protected function _getDiscriminatorColumnTableName()
protected function getDiscriminatorColumnTableName()
{
$class = ($this->_class->name !== $this->_class->rootEntityName)
? $this->_em->getClassMetadata($this->_class->rootEntityName)
: $this->_class;
$class = ($this->class->name !== $this->class->rootEntityName)
? $this->em->getClassMetadata($this->class->rootEntityName)
: $this->class;
return $class->getTableName();
}
@ -72,15 +72,15 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*
* @return \Doctrine\ORM\Mapping\ClassMetadata
*/
private function _getVersionedClassMetadata()
private function getVersionedClassMetadata()
{
if (isset($this->_class->fieldMappings[$this->_class->versionField]['inherited'])) {
$definingClassName = $this->_class->fieldMappings[$this->_class->versionField]['inherited'];
if (isset($this->class->fieldMappings[$this->class->versionField]['inherited'])) {
$definingClassName = $this->class->fieldMappings[$this->class->versionField]['inherited'];
return $this->_em->getClassMetadata($definingClassName);
return $this->em->getClassMetadata($definingClassName);
}
return $this->_class;
return $this->class;
}
/**
@ -92,22 +92,22 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*/
public function getOwningTable($fieldName)
{
if (isset($this->_owningTableMap[$fieldName])) {
return $this->_owningTableMap[$fieldName];
if (isset($this->owningTableMap[$fieldName])) {
return $this->owningTableMap[$fieldName];
}
if (isset($this->_class->associationMappings[$fieldName]['inherited'])) {
$cm = $this->_em->getClassMetadata($this->_class->associationMappings[$fieldName]['inherited']);
} else if (isset($this->_class->fieldMappings[$fieldName]['inherited'])) {
$cm = $this->_em->getClassMetadata($this->_class->fieldMappings[$fieldName]['inherited']);
if (isset($this->class->associationMappings[$fieldName]['inherited'])) {
$cm = $this->em->getClassMetadata($this->class->associationMappings[$fieldName]['inherited']);
} else if (isset($this->class->fieldMappings[$fieldName]['inherited'])) {
$cm = $this->em->getClassMetadata($this->class->fieldMappings[$fieldName]['inherited']);
} else {
$cm = $this->_class;
$cm = $this->class;
}
$tableName = $cm->getTableName();
$this->_owningTableMap[$fieldName] = $tableName;
$this->_quotedTableMap[$tableName] = $this->quoteStrategy->getTableName($cm, $this->_platform);
$this->owningTableMap[$fieldName] = $tableName;
$this->quotedTableMap[$tableName] = $this->quoteStrategy->getTableName($cm, $this->platform);
return $tableName;
}
@ -117,57 +117,57 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*/
public function executeInserts()
{
if ( ! $this->_queuedInserts) {
if ( ! $this->queuedInserts) {
return;
}
$postInsertIds = array();
$idGen = $this->_class->idGenerator;
$idGen = $this->class->idGenerator;
$isPostInsertId = $idGen->isPostInsertGenerator();
// Prepare statement for the root table
$rootClass = ($this->_class->name !== $this->_class->rootEntityName) ? $this->_em->getClassMetadata($this->_class->rootEntityName) : $this->_class;
$rootPersister = $this->_em->getUnitOfWork()->getEntityPersister($rootClass->name);
$rootClass = ($this->class->name !== $this->class->rootEntityName) ? $this->em->getClassMetadata($this->class->rootEntityName) : $this->class;
$rootPersister = $this->em->getUnitOfWork()->getEntityPersister($rootClass->name);
$rootTableName = $rootClass->getTableName();
$rootTableStmt = $this->_conn->prepare($rootPersister->_getInsertSQL());
$rootTableStmt = $this->conn->prepare($rootPersister->getInsertSQL());
// Prepare statements for sub tables.
$subTableStmts = array();
if ($rootClass !== $this->_class) {
$subTableStmts[$this->_class->getTableName()] = $this->_conn->prepare($this->_getInsertSQL());
if ($rootClass !== $this->class) {
$subTableStmts[$this->class->getTableName()] = $this->conn->prepare($this->getInsertSQL());
}
foreach ($this->_class->parentClasses as $parentClassName) {
$parentClass = $this->_em->getClassMetadata($parentClassName);
foreach ($this->class->parentClasses as $parentClassName) {
$parentClass = $this->em->getClassMetadata($parentClassName);
$parentTableName = $parentClass->getTableName();
if ($parentClass !== $rootClass) {
$parentPersister = $this->_em->getUnitOfWork()->getEntityPersister($parentClassName);
$subTableStmts[$parentTableName] = $this->_conn->prepare($parentPersister->_getInsertSQL());
$parentPersister = $this->em->getUnitOfWork()->getEntityPersister($parentClassName);
$subTableStmts[$parentTableName] = $this->conn->prepare($parentPersister->getInsertSQL());
}
}
// Execute all inserts. For each entity:
// 1) Insert on root table
// 2) Insert on sub tables
foreach ($this->_queuedInserts as $entity) {
$insertData = $this->_prepareInsertData($entity);
foreach ($this->queuedInserts as $entity) {
$insertData = $this->prepareInsertData($entity);
// Execute insert on root table
$paramIndex = 1;
foreach ($insertData[$rootTableName] as $columnName => $value) {
$rootTableStmt->bindValue($paramIndex++, $value, $this->_columnTypes[$columnName]);
$rootTableStmt->bindValue($paramIndex++, $value, $this->columnTypes[$columnName]);
}
$rootTableStmt->execute();
if ($isPostInsertId) {
$id = $idGen->generate($this->_em, $entity);
$id = $idGen->generate($this->em, $entity);
$postInsertIds[$id] = $entity;
} else {
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$id = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
}
// Execute inserts on subtables.
@ -177,13 +177,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$paramIndex = 1;
foreach ((array) $id as $idName => $idVal) {
$type = isset($this->_columnTypes[$idName]) ? $this->_columnTypes[$idName] : Type::STRING;
$type = isset($this->columnTypes[$idName]) ? $this->columnTypes[$idName] : Type::STRING;
$stmt->bindValue($paramIndex++, $idVal, $type);
}
foreach ($data as $columnName => $value) {
$stmt->bindValue($paramIndex++, $value, $this->_columnTypes[$columnName]);
$stmt->bindValue($paramIndex++, $value, $this->columnTypes[$columnName]);
}
$stmt->execute();
@ -196,11 +196,11 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$stmt->closeCursor();
}
if ($this->_class->isVersioned) {
if ($this->class->isVersioned) {
$this->assignDefaultVersionValue($entity, $id);
}
$this->_queuedInserts = array();
$this->queuedInserts = array();
return $postInsertIds;
}
@ -210,26 +210,26 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*/
public function update($entity)
{
$updateData = $this->_prepareUpdateData($entity);
$updateData = $this->prepareUpdateData($entity);
if (($isVersioned = $this->_class->isVersioned) != false) {
$versionedClass = $this->_getVersionedClassMetadata();
if (($isVersioned = $this->class->isVersioned) != false) {
$versionedClass = $this->getVersionedClassMetadata();
$versionedTable = $versionedClass->getTableName();
}
if ($updateData) {
foreach ($updateData as $tableName => $data) {
$this->_updateTable(
$entity, $this->_quotedTableMap[$tableName], $data, $isVersioned && $versionedTable == $tableName
$this->updateTable(
$entity, $this->quotedTableMap[$tableName], $data, $isVersioned && $versionedTable == $tableName
);
}
// 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, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true);
$this->updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->platform), array(), true);
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$id = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
$this->assignDefaultVersionValue($entity, $id);
}
}
@ -240,24 +240,24 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*/
public function delete($entity)
{
$identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
$this->deleteJoinTableRecords($identifier);
$id = array_combine($this->_class->getIdentifierColumnNames(), $identifier);
$id = array_combine($this->class->getIdentifierColumnNames(), $identifier);
// If the database platform supports FKs, just
// delete the row from the root table. Cascades do the rest.
if ($this->_platform->supportsForeignKeyConstraints()) {
$this->_conn->delete(
$this->quoteStrategy->getTableName($this->_em->getClassMetadata($this->_class->rootEntityName), $this->_platform), $id
if ($this->platform->supportsForeignKeyConstraints()) {
$this->conn->delete(
$this->quoteStrategy->getTableName($this->em->getClassMetadata($this->class->rootEntityName), $this->platform), $id
);
} else {
// Delete from all tables individually, starting from this class' table up to the root table.
$this->_conn->delete($this->quoteStrategy->getTableName($this->_class, $this->_platform), $id);
$this->conn->delete($this->quoteStrategy->getTableName($this->class, $this->platform), $id);
foreach ($this->_class->parentClasses as $parentClass) {
$this->_conn->delete(
$this->quoteStrategy->getTableName($this->_em->getClassMetadata($parentClass), $this->_platform), $id
foreach ($this->class->parentClasses as $parentClass) {
$this->conn->delete(
$this->quoteStrategy->getTableName($this->em->getClassMetadata($parentClass), $this->platform), $id
);
}
}
@ -266,33 +266,33 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
/**
* {@inheritdoc}
*/
protected function _getSelectEntitiesSQL($criteria, $assoc = null, $lockMode = 0, $limit = null, $offset = null, array $orderBy = null)
protected function getSelectEntitiesSQL($criteria, $assoc = null, $lockMode = 0, $limit = null, $offset = null, array $orderBy = null)
{
$idColumns = $this->_class->getIdentifierColumnNames();
$baseTableAlias = $this->_getSQLTableAlias($this->_class->name);
$idColumns = $this->class->getIdentifierColumnNames();
$baseTableAlias = $this->getSQLTableAlias($this->class->name);
// Create the column list fragment only once
if ($this->_selectColumnListSql === null) {
if ($this->selectColumnListSql === null) {
$this->_rsm = new ResultSetMapping();
$this->_rsm->addEntityResult($this->_class->name, 'r');
$this->rsm = new ResultSetMapping();
$this->rsm->addEntityResult($this->class->name, 'r');
// Add regular columns
$columnList = '';
foreach ($this->_class->fieldMappings as $fieldName => $mapping) {
foreach ($this->class->fieldMappings as $fieldName => $mapping) {
if ($columnList != '') $columnList .= ', ';
$columnList .= $this->_getSelectColumnSQL(
$columnList .= $this->getSelectColumnSQL(
$fieldName,
isset($mapping['inherited']) ? $this->_em->getClassMetadata($mapping['inherited']) : $this->_class
isset($mapping['inherited']) ? $this->em->getClassMetadata($mapping['inherited']) : $this->class
);
}
// Add foreign key columns
foreach ($this->_class->associationMappings as $assoc2) {
foreach ($this->class->associationMappings as $assoc2) {
if ($assoc2['isOwningSide'] && $assoc2['type'] & ClassMetadata::TO_ONE) {
$tableAlias = isset($assoc2['inherited']) ? $this->_getSQLTableAlias($assoc2['inherited']) : $baseTableAlias;
$tableAlias = isset($assoc2['inherited']) ? $this->getSQLTableAlias($assoc2['inherited']) : $baseTableAlias;
foreach ($assoc2['targetToSourceKeyColumns'] as $srcColumn) {
if ($columnList != '') $columnList .= ', ';
@ -300,30 +300,30 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$columnList .= $this->getSelectJoinColumnSQL(
$tableAlias,
$srcColumn,
isset($assoc2['inherited']) ? $assoc2['inherited'] : $this->_class->name
isset($assoc2['inherited']) ? $assoc2['inherited'] : $this->class->name
);
}
}
}
// Add discriminator column (DO NOT ALIAS, see AbstractEntityInheritancePersister#_processSQLResult).
$discrColumn = $this->_class->discriminatorColumn['name'];
$tableAlias = ($this->_class->rootEntityName == $this->_class->name) ? $baseTableAlias : $this->_getSQLTableAlias($this->_class->rootEntityName);
$discrColumn = $this->class->discriminatorColumn['name'];
$tableAlias = ($this->class->rootEntityName == $this->class->name) ? $baseTableAlias : $this->getSQLTableAlias($this->class->rootEntityName);
$columnList .= ', ' . $tableAlias . '.' . $discrColumn;
$resultColumnName = $this->_platform->getSQLResultCasing($discrColumn);
$resultColumnName = $this->platform->getSQLResultCasing($discrColumn);
$this->_rsm->setDiscriminatorColumn('r', $resultColumnName);
$this->_rsm->addMetaResult('r', $resultColumnName, $discrColumn);
$this->rsm->setDiscriminatorColumn('r', $resultColumnName);
$this->rsm->addMetaResult('r', $resultColumnName, $discrColumn);
}
// INNER JOIN parent tables
$joinSql = '';
foreach ($this->_class->parentClasses as $parentClassName) {
$parentClass = $this->_em->getClassMetadata($parentClassName);
$tableAlias = $this->_getSQLTableAlias($parentClassName);
$joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->_platform) . ' ' . $tableAlias . ' ON ';
foreach ($this->class->parentClasses as $parentClassName) {
$parentClass = $this->em->getClassMetadata($parentClassName);
$tableAlias = $this->getSQLTableAlias($parentClassName);
$joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->platform) . ' ' . $tableAlias . ' ON ';
$first = true;
foreach ($idColumns as $idColumn) {
@ -334,16 +334,16 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
}
// OUTER JOIN sub tables
foreach ($this->_class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
$tableAlias = $this->_getSQLTableAlias($subClassName);
foreach ($this->class->subClasses as $subClassName) {
$subClass = $this->em->getClassMetadata($subClassName);
$tableAlias = $this->getSQLTableAlias($subClassName);
if ($this->_selectColumnListSql === null) {
if ($this->selectColumnListSql === null) {
// Add subclass columns
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if (isset($mapping['inherited'])) continue;
$columnList .= ', ' . $this->_getSelectColumnSQL($fieldName, $subClass);
$columnList .= ', ' . $this->getSelectColumnSQL($fieldName, $subClass);
}
// Add join columns (foreign keys)
@ -363,7 +363,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
}
// Add LEFT JOIN
$joinSql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass, $this->_platform) . ' ' . $tableAlias . ' ON ';
$joinSql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass, $this->platform) . ' ' . $tableAlias . ' ON ';
$first = true;
foreach ($idColumns as $idColumn) {
@ -373,14 +373,14 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
}
}
$joinSql .= ($assoc != null && $assoc['type'] == ClassMetadata::MANY_TO_MANY) ? $this->_getSelectManyToManyJoinSQL($assoc) : '';
$joinSql .= ($assoc != null && $assoc['type'] == ClassMetadata::MANY_TO_MANY) ? $this->getSelectManyToManyJoinSQL($assoc) : '';
$conditionSql = ($criteria instanceof Criteria)
? $this->_getSelectConditionCriteriaSQL($criteria)
: $this->_getSelectConditionSQL($criteria, $assoc);
? $this->getSelectConditionCriteriaSQL($criteria)
: $this->getSelectConditionSQL($criteria, $assoc);
// If the current class in the root entity, add the filters
if ($filterSql = $this->generateFilterConditionSQL($this->_em->getClassMetadata($this->_class->rootEntityName), $this->_getSQLTableAlias($this->_class->rootEntityName))) {
if ($filterSql = $this->generateFilterConditionSQL($this->em->getClassMetadata($this->class->rootEntityName), $this->getSQLTableAlias($this->class->rootEntityName))) {
if ($conditionSql) {
$conditionSql .= ' AND ';
}
@ -389,22 +389,22 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
}
$orderBy = ($assoc !== null && isset($assoc['orderBy'])) ? $assoc['orderBy'] : $orderBy;
$orderBySql = $orderBy ? $this->_getOrderBySQL($orderBy, $baseTableAlias) : '';
$orderBySql = $orderBy ? $this->getOrderBySQL($orderBy, $baseTableAlias) : '';
if ($this->_selectColumnListSql === null) {
$this->_selectColumnListSql = $columnList;
if ($this->selectColumnListSql === null) {
$this->selectColumnListSql = $columnList;
}
$lockSql = '';
if ($lockMode == LockMode::PESSIMISTIC_READ) {
$lockSql = ' ' . $this->_platform->getReadLockSql();
$lockSql = ' ' . $this->platform->getReadLockSql();
} else if ($lockMode == LockMode::PESSIMISTIC_WRITE) {
$lockSql = ' ' . $this->_platform->getWriteLockSql();
$lockSql = ' ' . $this->platform->getWriteLockSql();
}
return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql
. ' FROM ' . $this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' ' . $baseTableAlias
return $this->platform->modifyLimitQuery('SELECT ' . $this->selectColumnListSql
. ' FROM ' . $this->quoteStrategy->getTableName($this->class, $this->platform) . ' ' . $baseTableAlias
. $joinSql
. ($conditionSql != '' ? ' WHERE ' . $conditionSql : '') . $orderBySql, $limit, $offset)
. $lockSql;
@ -417,16 +417,16 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*/
public function getLockTablesSql()
{
$idColumns = $this->_class->getIdentifierColumnNames();
$baseTableAlias = $this->_getSQLTableAlias($this->_class->name);
$idColumns = $this->class->getIdentifierColumnNames();
$baseTableAlias = $this->getSQLTableAlias($this->class->name);
// INNER JOIN parent tables
$joinSql = '';
foreach ($this->_class->parentClasses as $parentClassName) {
$parentClass = $this->_em->getClassMetadata($parentClassName);
$tableAlias = $this->_getSQLTableAlias($parentClassName);
$joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->_platform) . ' ' . $tableAlias . ' ON ';
foreach ($this->class->parentClasses as $parentClassName) {
$parentClass = $this->em->getClassMetadata($parentClassName);
$tableAlias = $this->getSQLTableAlias($parentClassName);
$joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->platform) . ' ' . $tableAlias . ' ON ';
$first = true;
foreach ($idColumns as $idColumn) {
@ -436,45 +436,45 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
}
}
return 'FROM ' .$this->quoteStrategy->getTableName($this->_class, $this->_platform) . ' ' . $baseTableAlias . $joinSql;
return 'FROM ' .$this->quoteStrategy->getTableName($this->class, $this->platform) . ' ' . $baseTableAlias . $joinSql;
}
/* Ensure this method is never called. This persister overrides _getSelectEntitiesSQL directly. */
protected function _getSelectColumnListSQL()
protected function getSelectColumnListSQL()
{
throw new \BadMethodCallException("Illegal invocation of ".__METHOD__.".");
}
/** {@inheritdoc} */
protected function _getInsertColumnList()
protected function getInsertColumnList()
{
// Identifier columns must always come first in the column list of subclasses.
$columns = $this->_class->parentClasses ? $this->_class->getIdentifierColumnNames() : array();
$columns = $this->class->parentClasses ? $this->class->getIdentifierColumnNames() : array();
foreach ($this->_class->reflFields as $name => $field) {
if (isset($this->_class->fieldMappings[$name]['inherited']) && ! isset($this->_class->fieldMappings[$name]['id'])
|| isset($this->_class->associationMappings[$name]['inherited'])
|| ($this->_class->isVersioned && $this->_class->versionField == $name)) {
foreach ($this->class->reflFields as $name => $field) {
if (isset($this->class->fieldMappings[$name]['inherited']) && ! isset($this->class->fieldMappings[$name]['id'])
|| isset($this->class->associationMappings[$name]['inherited'])
|| ($this->class->isVersioned && $this->class->versionField == $name)) {
continue;
}
if (isset($this->_class->associationMappings[$name])) {
$assoc = $this->_class->associationMappings[$name];
if (isset($this->class->associationMappings[$name])) {
$assoc = $this->class->associationMappings[$name];
if ($assoc['type'] & ClassMetadata::TO_ONE && $assoc['isOwningSide']) {
foreach ($assoc['targetToSourceKeyColumns'] as $sourceCol) {
$columns[] = $sourceCol;
}
}
} else if ($this->_class->name != $this->_class->rootEntityName ||
! $this->_class->isIdGeneratorIdentity() || $this->_class->identifier[0] != $name) {
$columns[] = $this->quoteStrategy->getColumnName($name, $this->_class, $this->_platform);
$this->_columnTypes[$name] = $this->_class->fieldMappings[$name]['type'];
} else if ($this->class->name != $this->class->rootEntityName ||
! $this->class->isIdGeneratorIdentity() || $this->class->identifier[0] != $name) {
$columns[] = $this->quoteStrategy->getColumnName($name, $this->class, $this->platform);
$this->columnTypes[$name] = $this->class->fieldMappings[$name]['type'];
}
}
// Add discriminator column if it is the topmost class.
if ($this->_class->name == $this->_class->rootEntityName) {
$columns[] = $this->_class->discriminatorColumn['name'];
if ($this->class->name == $this->class->rootEntityName) {
$columns[] = $this->class->discriminatorColumn['name'];
}
return $columns;
@ -485,8 +485,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
*/
protected function assignDefaultVersionValue($entity, $id)
{
$value = $this->fetchVersionValue($this->_getVersionedClassMetadata(), $id);
$this->_class->setFieldValue($entity, $this->_class->versionField, $value);
$value = $this->fetchVersionValue($this->getVersionedClassMetadata(), $id);
$this->class->setFieldValue($entity, $this->class->versionField, $value);
}
}

View File

@ -35,40 +35,40 @@ use Doctrine\Common\Collections\Criteria;
class SingleTablePersister extends AbstractEntityInheritancePersister
{
/** {@inheritdoc} */
protected function _getDiscriminatorColumnTableName()
protected function getDiscriminatorColumnTableName()
{
return $this->_class->getTableName();
return $this->class->getTableName();
}
/** {@inheritdoc} */
protected function _getSelectColumnListSQL()
protected function getSelectColumnListSQL()
{
if ($this->_selectColumnListSql !== null) {
return $this->_selectColumnListSql;
if ($this->selectColumnListSql !== null) {
return $this->selectColumnListSql;
}
$columnList = parent::_getSelectColumnListSQL();
$columnList = parent::getSelectColumnListSQL();
$rootClass = $this->_em->getClassMetadata($this->_class->rootEntityName);
$tableAlias = $this->_getSQLTableAlias($rootClass->name);
$rootClass = $this->em->getClassMetadata($this->class->rootEntityName);
$tableAlias = $this->getSQLTableAlias($rootClass->name);
// Append discriminator column
$discrColumn = $this->_class->discriminatorColumn['name'];
$discrColumn = $this->class->discriminatorColumn['name'];
$columnList .= ', ' . $tableAlias . '.' . $discrColumn;
$resultColumnName = $this->_platform->getSQLResultCasing($discrColumn);
$resultColumnName = $this->platform->getSQLResultCasing($discrColumn);
$this->_rsm->setDiscriminatorColumn('r', $resultColumnName);
$this->_rsm->addMetaResult('r', $resultColumnName, $discrColumn);
$this->rsm->setDiscriminatorColumn('r', $resultColumnName);
$this->rsm->addMetaResult('r', $resultColumnName, $discrColumn);
// Append subclass columns
foreach ($this->_class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
foreach ($this->class->subClasses as $subClassName) {
$subClass = $this->em->getClassMetadata($subClassName);
// Regular columns
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if ( ! isset($mapping['inherited'])) {
$columnList .= ', ' . $this->_getSelectColumnSQL($fieldName, $subClass);
$columnList .= ', ' . $this->getSelectColumnSQL($fieldName, $subClass);
}
}
@ -81,73 +81,73 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
$columnList .= $this->getSelectJoinColumnSQL(
$tableAlias,
$srcColumn,
isset($assoc['inherited']) ? $assoc['inherited'] : $this->_class->name
isset($assoc['inherited']) ? $assoc['inherited'] : $this->class->name
);
}
}
}
}
$this->_selectColumnListSql = $columnList;
return $this->_selectColumnListSql;
$this->selectColumnListSql = $columnList;
return $this->selectColumnListSql;
}
/** {@inheritdoc} */
protected function _getInsertColumnList()
protected function getInsertColumnList()
{
$columns = parent::_getInsertColumnList();
$columns = parent::getInsertColumnList();
// Add discriminator column to the INSERT SQL
$columns[] = $this->_class->discriminatorColumn['name'];
$columns[] = $this->class->discriminatorColumn['name'];
return $columns;
}
/** {@inheritdoc} */
protected function _getSQLTableAlias($className, $assocName = '')
protected function getSQLTableAlias($className, $assocName = '')
{
return parent::_getSQLTableAlias($this->_class->rootEntityName, $assocName);
return parent::getSQLTableAlias($this->class->rootEntityName, $assocName);
}
/** {@inheritdoc} */
protected function _getSelectConditionSQL(array $criteria, $assoc = null)
protected function getSelectConditionSQL(array $criteria, $assoc = null)
{
$conditionSql = parent::_getSelectConditionSQL($criteria, $assoc);
$conditionSql = parent::getSelectConditionSQL($criteria, $assoc);
if ($conditionSql) {
$conditionSql .= ' AND ';
}
return $conditionSql . $this->_getSelectConditionDiscriminatorValueSQL();
return $conditionSql . $this->getSelectConditionDiscriminatorValueSQL();
}
/** {@inheritdoc} */
protected function _getSelectConditionCriteriaSQL(Criteria $criteria)
protected function getSelectConditionCriteriaSQL(Criteria $criteria)
{
$conditionSql = parent::_getSelectConditionCriteriaSQL($criteria);
$conditionSql = parent::getSelectConditionCriteriaSQL($criteria);
if ($conditionSql) {
$conditionSql .= ' AND ';
}
return $conditionSql . $this->_getSelectConditionDiscriminatorValueSQL();
return $conditionSql . $this->getSelectConditionDiscriminatorValueSQL();
}
protected function _getSelectConditionDiscriminatorValueSQL()
protected function getSelectConditionDiscriminatorValueSQL()
{
$values = array();
if ($this->_class->discriminatorValue !== null) { // discriminators can be 0
$values[] = $this->_conn->quote($this->_class->discriminatorValue);
if ($this->class->discriminatorValue !== null) { // discriminators can be 0
$values[] = $this->conn->quote($this->class->discriminatorValue);
}
$discrValues = array_flip($this->_class->discriminatorMap);
$discrValues = array_flip($this->class->discriminatorMap);
foreach ($this->_class->subClasses as $subclassName) {
$values[] = $this->_conn->quote($discrValues[$subclassName]);
foreach ($this->class->subClasses as $subclassName) {
$values[] = $this->conn->quote($discrValues[$subclassName]);
}
return $this->_getSQLTableAlias($this->_class->name) . '.' . $this->_class->discriminatorColumn['name']
return $this->getSQLTableAlias($this->class->name) . '.' . $this->class->discriminatorColumn['name']
. ' IN (' . implode(', ', $values) . ')';
}
@ -155,7 +155,7 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias)
{
// Ensure that the filters are applied to the root entity of the inheritance tree
$targetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName);
$targetEntity = $this->em->getClassMetadata($targetEntity->rootEntityName);
// we dont care about the $targetTableAlias, in a STI there is only one table.
return parent::generateFilterConditionSQL($targetEntity, $targetTableAlias);

View File

@ -7,12 +7,12 @@ namespace Doctrine\Tests\Mocks;
*/
class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
{
private $_inserts = array();
private $_updates = array();
private $_deletes = array();
private $_identityColumnValueCounter = 0;
private $_mockIdGeneratorType;
private $_postInsertIds = array();
private $inserts = array();
private $updates = array();
private $deletes = array();
private $identityColumnValueCounter = 0;
private $mockIdGeneratorType;
private $postInsertIds = array();
private $existsCalled = false;
/**
@ -22,11 +22,11 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
*/
public function insert($entity)
{
$this->_inserts[] = $entity;
if ( ! is_null($this->_mockIdGeneratorType) && $this->_mockIdGeneratorType == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY
|| $this->_class->isIdGeneratorIdentity()) {
$id = $this->_identityColumnValueCounter++;
$this->_postInsertIds[$id] = $entity;
$this->inserts[] = $entity;
if ( ! is_null($this->mockIdGeneratorType) && $this->mockIdGeneratorType == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY
|| $this->class->isIdGeneratorIdentity()) {
$id = $this->identityColumnValueCounter++;
$this->postInsertIds[$id] = $entity;
return $id;
}
return null;
@ -34,11 +34,11 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
public function addInsert($entity)
{
$this->_inserts[] = $entity;
if ( ! is_null($this->_mockIdGeneratorType) && $this->_mockIdGeneratorType == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY
|| $this->_class->isIdGeneratorIdentity()) {
$id = $this->_identityColumnValueCounter++;
$this->_postInsertIds[$id] = $entity;
$this->inserts[] = $entity;
if ( ! is_null($this->mockIdGeneratorType) && $this->mockIdGeneratorType == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY
|| $this->class->isIdGeneratorIdentity()) {
$id = $this->identityColumnValueCounter++;
$this->postInsertIds[$id] = $entity;
return $id;
}
return null;
@ -46,17 +46,17 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
public function executeInserts()
{
return $this->_postInsertIds;
return $this->postInsertIds;
}
public function setMockIdGeneratorType($genType)
{
$this->_mockIdGeneratorType = $genType;
$this->mockIdGeneratorType = $genType;
}
public function update($entity)
{
$this->_updates[] = $entity;
$this->updates[] = $entity;
}
public function exists($entity, array $extraConditions = array())
@ -66,31 +66,31 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
public function delete($entity)
{
$this->_deletes[] = $entity;
$this->deletes[] = $entity;
}
public function getInserts()
{
return $this->_inserts;
return $this->inserts;
}
public function getUpdates()
{
return $this->_updates;
return $this->updates;
}
public function getDeletes()
{
return $this->_deletes;
return $this->deletes;
}
public function reset()
{
$this->existsCalled = false;
$this->_identityColumnValueCounter = 0;
$this->_inserts = array();
$this->_updates = array();
$this->_deletes = array();
$this->identityColumnValueCounter = 0;
$this->inserts = array();
$this->updates = array();
$this->deletes = array();
}
public function isExistsCalled()

View File

@ -38,7 +38,7 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase
public function testGetInsertSQLUsesTypeValuesSQL()
{
$method = new \ReflectionMethod($this->_persister, '_getInsertSQL');
$method = new \ReflectionMethod($this->_persister, 'getInsertSQL');
$method->setAccessible(true);
$sql = $method->invoke($this->_persister);
@ -69,7 +69,7 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase
public function testGetSelectConditionSQLUsesTypeValuesSQL()
{
$method = new \ReflectionMethod($this->_persister, '_getSelectConditionSQL');
$method = new \ReflectionMethod($this->_persister, 'getSelectConditionSQL');
$method->setAccessible(true);
$sql = $method->invoke($this->_persister, array('customInteger' => 1, 'child' => 1));
@ -83,7 +83,7 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase
public function testStripNonAlphanumericCharactersFromSelectColumnListSQL()
{
$persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\SimpleEntity'));
$method = new \ReflectionMethod($persister, '_getSelectColumnListSQL');
$method = new \ReflectionMethod($persister, 'getSelectColumnListSQL');
$method->setAccessible(true);
$this->assertEquals('t0."simple-entity-id" AS simpleentityid1, t0."simple-entity-value" AS simpleentityvalue2', $method->invoke($persister));