Permalink
Browse files

Small changes for code readability. Added type binding in JoinedSubcl…

…assPersister, which was missing. Fixes DDC-1316.
  • Loading branch information...
1 parent f29c907 commit 666691f84fd5a48d0eb6af7e93b83c2651555e61 @guilhermeblanco guilhermeblanco committed Sep 5, 2011
@@ -65,9 +65,11 @@ public function __construct(EntityManager $em)
public function delete(PersistentCollection $coll)
{
$mapping = $coll->getMapping();
+
if ( ! $mapping['isOwningSide']) {
return; // ignore inverse side
}
+
$sql = $this->_getDeleteSQL($coll);
$this->_conn->executeUpdate($sql, $this->_getDeleteSQLParameters($coll));
}
@@ -96,9 +98,11 @@ public function delete(PersistentCollection $coll)
public function update(PersistentCollection $coll)
{
$mapping = $coll->getMapping();
+
if ( ! $mapping['isOwningSide']) {
return; // ignore inverse side
}
+
$this->deleteRows($coll);
//$this->updateRows($coll);
$this->insertRows($coll);
@@ -108,6 +112,7 @@ public function deleteRows(PersistentCollection $coll)
{
$deleteDiff = $coll->getDeleteDiff();
$sql = $this->_getDeleteRowSQL($coll);
+
foreach ($deleteDiff as $element) {
$this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element));
}
@@ -120,6 +125,7 @@ public function insertRows(PersistentCollection $coll)
{
$insertDiff = $coll->getInsertDiff();
$sql = $this->_getInsertRowSQL($coll);
+
foreach ($insertDiff as $element) {
$this->_conn->executeUpdate($sql, $this->_getInsertRowSQLParameters($coll, $element));
}
@@ -39,10 +39,12 @@
protected function _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;
+
return $data;
}
@@ -63,7 +65,7 @@ protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r
$columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++);
$this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name);
- return "$sql AS $columnAlias";
+ return $sql . ' AS ' . $columnAlias;
}
protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $className)
@@ -72,6 +74,6 @@ protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $classNa
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addMetaResult('r', $resultColumnName, $joinColumnName);
- return $tableAlias . ".$joinColumnName AS $columnAlias";
+ return $tableAlias . '.' . $joinColumnName . ' AS ' . $columnAlias;
}
}
@@ -229,6 +229,7 @@ public function executeInserts()
if (isset($insertData[$tableName])) {
$paramIndex = 1;
+
foreach ($insertData[$tableName] as $column => $value) {
$stmt->bindValue($paramIndex++, $value, $this->_columnTypes[$column]);
}
@@ -22,6 +22,7 @@
use Doctrine\ORM\ORMException,
Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\DBAL\LockMode,
+ Doctrine\DBAL\Types\Type,
Doctrine\ORM\Query\ResultSetMapping;
/**
@@ -143,9 +144,11 @@ public function executeInserts()
// Execute insert on root table
$paramIndex = 1;
+
foreach ($insertData[$rootTableName] as $columnName => $value) {
$rootTableStmt->bindValue($paramIndex++, $value, $this->_columnTypes[$columnName]);
}
+
$rootTableStmt->execute();
if ($isPostInsertId) {
@@ -160,12 +163,17 @@ public function executeInserts()
foreach ($subTableStmts as $tableName => $stmt) {
$data = isset($insertData[$tableName]) ? $insertData[$tableName] : array();
$paramIndex = 1;
- foreach ((array) $id as $idVal) {
- $stmt->bindValue($paramIndex++, $idVal);
+
+ foreach ((array) $id as $idName => $idVal) {
+ $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->execute();
}
}
@@ -191,7 +199,7 @@ public function update($entity)
{
$updateData = $this->_prepareUpdateData($entity);
- if ($isVersioned = $this->_class->isVersioned) {
+ if (($isVersioned = $this->_class->isVersioned) != false) {
$versionedClass = $this->_getVersionedClassMetadata();
$versionedTable = $versionedClass->table['name'];
}
@@ -200,6 +208,7 @@ public function update($entity)
foreach ($updateData as $tableName => $data) {
$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])) {
@@ -229,6 +238,7 @@ public function delete($entity)
} 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);
+
foreach ($this->_class->parentClasses as $parentClass) {
$this->_conn->delete($this->_em->getClassMetadata($parentClass)->getQuotedTableName($this->_platform), $id);
}
@@ -39,9 +39,10 @@ class ManyToManyPersister extends AbstractCollectionPersister
*/
protected function _getDeleteRowSQL(PersistentCollection $coll)
{
- $mapping = $coll->getMapping();
+ $mapping = $coll->getMapping();
$joinTable = $mapping['joinTable'];
- $columns = $mapping['joinTableColumns'];
+ $columns = $mapping['joinTableColumns'];
+
return 'DELETE FROM ' . $joinTable['name'] . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?';
}

0 comments on commit 666691f

Please sign in to comment.