1
0
mirror of synced 2025-01-22 08:11:40 +03:00

DDC-870 - Fix several bugs with optimistic locking, conversion of types, multiple updating of values and inheritance related stuff.

This commit is contained in:
Benjamin Eberlei 2010-11-09 23:15:14 +01:00
parent 53e8b8f32d
commit ac85584e9b
3 changed files with 30 additions and 2 deletions

View File

@ -251,6 +251,8 @@ class BasicEntityPersister
$sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform)
. " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
$value = $this->_conn->fetchColumn($sql, array_values((array)$id));
$value = Type::getType($class->fieldMappings[$versionField]['type'])->convertToPHPValue($value, $this->_platform);
$this->_class->setFieldValue($entity, $versionField, $value);
}
@ -277,6 +279,11 @@ class BasicEntityPersister
$entity, $this->_class->getQuotedTableName($this->_platform),
$updateData[$tableName], $this->_class->isVersioned
);
if ($this->_class->isVersioned) {
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$this->_assignDefaultVersionValue($this->_class, $entity, $id);
}
}
}
@ -313,7 +320,7 @@ class BasicEntityPersister
if ($versioned) {
$versionField = $this->_class->versionField;
$versionFieldType = $this->_class->getTypeOfField($versionField);
$versionFieldType = $this->_class->fieldMappings[$versionField]['type'];
$versionColumn = $this->_class->getQuotedColumnName($versionField, $this->_platform);
if ($versionFieldType == Type::INTEGER) {
$set[] = $versionColumn . ' = ' . $versionColumn . ' + 1';

View File

@ -205,6 +205,9 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
// table were affected.
if ($isVersioned && ! isset($updateData[$versionedTable])) {
$this->_updateTable($entity, $versionedClass->getQuotedTableName($this->_platform), array(), true);
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$this->_assignDefaultVersionValue($this->_class, $entity, $id);
}
}
}

View File

@ -100,6 +100,20 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
}
}
public function testMultipleFlushesDoIncrementalUpdates()
{
$test = new OptimisticStandard();
for ($i = 0; $i < 5; $i++) {
$test->name = 'test' . $i;
$this->_em->persist($test);
$this->_em->flush();
$this->assertType('int', $test->getVersion());
$this->assertEquals($i + 1, $test->getVersion());
}
}
public function testStandardInsertSetsInitialVersionValue()
{
$test = new OptimisticStandard();
@ -107,6 +121,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->persist($test);
$this->_em->flush();
$this->assertType('int', $test->getVersion());
$this->assertEquals(1, $test->getVersion());
return $test;
@ -139,10 +154,13 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
$test = new OptimisticTimestamp();
$test->name = 'Testing';
$this->assertNull($test->version, "Pre-Condition");
$this->_em->persist($test);
$this->_em->flush();
$this->assertTrue(strtotime($test->version) > 0);
$this->assertType('DateTime', $test->version);
return $test;
}