Permalink
Browse files

[DDC-692] Add respective metadata mapping possiblities for read-only …

…entities and a test.
  • Loading branch information...
1 parent 9a75277 commit 34ad308599bf6470e6d43f88985b781543d0bbc4 @beberlei beberlei committed Mar 29, 2011
View
@@ -88,6 +88,7 @@
<xs:attribute name="repository-class" type="xs:string"/>
<xs:attribute name="inheritance-type" type="orm:inheritance-type"/>
<xs:attribute name="change-tracking-policy" type="orm:change-tracking-policy" />
+ <xs:attribute name="read-only" type="xs:boolean" default="false" />
</xs:complexType>
<xs:complexType name="mapped-superclass" >
@@ -132,6 +132,10 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) {
$entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity'];
$metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
+
+ if ($entityAnnot->readOnly) {
+ $metadata->markReadOnly();
+ }
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
$metadata->isMappedSuperclass = true;
} else {
@@ -1,7 +1,5 @@
<?php
/*
- * $Id$
- *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -27,6 +25,7 @@
final class Entity extends Annotation {
public $repositoryClass;
+ public $readOnly = false;
}
final class MappedSuperclass extends Annotation {}
final class InheritanceType extends Annotation {}
@@ -55,6 +55,9 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
$metadata->setCustomRepositoryClass(
isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null
);
+ if (isset($xmlRoot['read-only']) && $xmlRoot['read-only'] == "true") {
+ $metadata->markReadOnly();
+ }
} else if ($xmlRoot->getName() == 'mapped-superclass') {
$metadata->isMappedSuperclass = true;
} else {
@@ -49,6 +49,9 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
$metadata->setCustomRepositoryClass(
isset($element['repositoryClass']) ? $element['repositoryClass'] : null
);
+ if (isset($element['readOnly']) && $element['readOnly'] == true) {
+ $metadata->markReadOnly();
+ }
} else if ($element['type'] == 'mappedSuperclass') {
$metadata->isMappedSuperclass = true;
} else {
@@ -59,6 +59,7 @@ public static function suite()
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\PostgreSQLIdentityStrategyTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ExtraLazyCollectionTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ClearEventTest');
+ $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ReadOnlyTest');
$suite->addTest(Locking\AllTests::suite());
$suite->addTest(Ticket\AllTests::suite());
@@ -0,0 +1,61 @@
+<?php
+
+namespace Doctrine\Tests\ORM\Functional;
+
+require_once __DIR__ . '/../../TestInit.php';
+
+/**
+ * Functional Query tests.
+ *
+ * @group DDC-692
+ */
+class ReadOnlyTest extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->_schemaTool->createSchema(array(
+ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ReadOnlyEntity'),
+ ));
+ }
+
+ public function testReadOnlyEntityNeverChangeTracked()
+ {
+ $readOnly = new ReadOnlyEntity("Test1", 1234);
+ $this->_em->persist($readOnly);
+ $this->_em->flush();
+
+ $readOnly->name = "Test2";
+ $readOnly->number = 4321;
+
+ $this->_em->flush();
+ $this->_em->clear();
+
+ $dbReadOnly = $this->_em->find('Doctrine\Tests\ORM\Functional\ReadOnlyEntity', $readOnly->id);
+ $this->assertEquals("Test1", $dbReadOnly->name);
+ $this->assertEquals(1234, $dbReadOnly->number);
+ }
+}
+
+/**
+ * @Entity(readOnly=true)
+ */
+class ReadOnlyEntity
+{
+ /**
+ * @Id @GeneratedValue @Column(type="integer")
+ * @var int
+ */
+ public $id;
+ /** @column(type="string") */
+ public $name;
+ /** @Column(type="integer") */
+ public $number;
+
+ public function __construct($name, $number)
+ {
+ $this->name = $name;
+ $this->number = $number;
+ }
+}

0 comments on commit 34ad308

Please sign in to comment.