Permalink
Browse files

Make storage name confiugrable on Entity.

  • Loading branch information...
1 parent f207bee commit 17f6059926f86b02ce9c76891e1c702b0227978b @beberlei beberlei committed Apr 2, 2012
@@ -50,6 +50,7 @@ function loadMetadataForClass($className, ClassMetadata $metadata)
if (!$entityAnnot) {
throw new \InvalidArgumentException($metadata->name . " is not a valid key-value-store entity.");
}
+ $metadata->storageName = $entityAnnot->storageName;
// Evaluate annotations on properties/fields
foreach ($class->getProperties() as $property) {
@@ -24,5 +24,9 @@
*/
class Entity
{
+ /**
+ * @var string
+ */
+ public $storageName;
}
@@ -24,6 +24,7 @@
class ClassMetadata implements BaseClassMetadata
{
public $name;
+ public $storageName;
public $fields = array();
public $identifier = array();
public $isCompositeKey = false;
@@ -36,6 +37,8 @@ class ClassMetadata implements BaseClassMetadata
public function __construct($className)
{
$this->name = $className;
+ $parts = explode("\\", $className);
+ $this->storageName = end($parts);
}
public function mapIdentifier($fieldName)
@@ -52,7 +52,7 @@ public function reconsititute($className, $key)
{
$class = $this->cmf->getMetadataFor($className);
$id = $this->idHandler->normalizeId($class, $key);
- $data = $this->storageDriver->find($className, $id);
+ $data = $this->storageDriver->find($class->storageName, $id);
$object = $this->tryGetById($id);
if ( ! $object) {
@@ -61,10 +61,6 @@ public function reconsititute($className, $key)
$oid = spl_object_hash($object);
$this->originalData[$oid] = $data;
- if ( ! isset($data['php_class']) || ! ($object instanceof $data['php_class'])) {
- throw new \RuntimeException("Trying to reconstitute " . $data['php_class'] . " but a " . $className . " was requested.");
- }
-
foreach ($data as $property => $value) {
if (isset($class->reflFields[$property])) {
$class->reflFields[$property]->setValue($object, $value);
@@ -154,10 +150,11 @@ private function processIdentityMap()
continue;
}
- $changeSet = $this->computeChangeSet($this->cmf->getMetadataFor(get_class($object)), $object);
+ $metadata = $this->cmf->getMetadataFor(get_class($object));
+ $changeSet = $this->computeChangeSet($metadata, $object);
if ($changeSet) {
- $this->storageDriver->update(get_class($object), $this->identifiers[$hash], $changeSet);
+ $this->storageDriver->update($metadata->storageName, $this->identifiers[$hash], $changeSet);
if ($this->storageDriver->supportsPartialUpdates()) {
$this->originalData[$hash] = array_merge($this->originalData[$hash], $changeSet);
@@ -183,7 +180,7 @@ private function processInsertions()
$oid = spl_object_hash($object);
$idHash = $this->idHandler->hash($id);
- $this->storageDriver->insert(get_class($object), $id, $data);
+ $this->storageDriver->insert($class->storageName, $id, $data);
$this->originalData[$oid] = $data;
$this->identifiers[$oid] = $id;
@@ -194,11 +191,12 @@ private function processInsertions()
private function processDeletions()
{
foreach ($this->scheduledDeletions as $object) {
+ $class = $this->cmf->getMetadataFor(get_class($object));
$oid = spl_object_hash($object);
$id = $this->identifiers[$oid];
$idHash = $this->idHandler->hash($id);
- $this->storageDriver->delete(get_class($object), $id);
+ $this->storageDriver->delete($class->storageName, $id);
unset($this->identifiers[$oid], $this->originalData[$oid], $this->identityMap[$idHash]);
}
View
@@ -13,7 +13,7 @@
</filter>
<php>
- <var name="DOCTRINE_KEYVALUE_AZURE_AUTHSCHEMA" value="shared" />
+ <var name="DOCTRINE_KEYVALUE_AZURE_AUTHSCHEMA" value="sharedlite" />
<var name="DOCTRINE_KEYVALUE_AZURE_NAME" value="" />
<var name="DOCTRINE_KEYVALUE_AZURE_KEY" value="" />
</php>
@@ -70,7 +70,7 @@ public function testPersistAndRetrieveItem()
public function testRetrieveItem()
{
- $this->populate(1, array('id' => 1, 'headline' => 'test', 'body' => 'tset', 'foo' => 'bar', 'php_class' => __NAMESPACE__ . '\\Post'));
+ $this->populate(1, array('id' => 1, 'headline' => 'test', 'body' => 'tset', 'foo' => 'bar', 'php_class' => 'post'));
$post = $this->manager->find(__NAMESPACE__ . '\\Post', 1);
@@ -82,14 +82,6 @@ public function testRetrieveItem()
$this->assertSame($post, $post2);
}
- public function testRetrieveWrongClass()
- {
- $this->populate(1, array('id' => 1, 'headline' => 'test', 'body' => 'tset', 'foo' => 'bar', 'php_class' => 'stdClass'));
-
- $this->setExpectedException("RuntimeException", "Trying to reconstitute");
- $post = $this->manager->find(__NAMESPACE__ . '\\Post', 1);
- }
-
public function testUpdateClass()
{
$post = new Post();
@@ -105,7 +97,7 @@ public function testUpdateClass()
$this->manager->flush();
- $this->assertEquals(array('id' => 1, 'headline' => 'asdf', 'body' => 'bar', 'text' => 'baz', 'php_class' => __NAMESPACE__ . '\\Post'), $this->find(1));
+ $this->assertEquals(array('id' => 1, 'headline' => 'asdf', 'body' => 'bar', 'text' => 'baz', 'php_class' => 'post'), $this->find(1));
}
public function testRemoveClass()
@@ -128,7 +120,7 @@ public function testRemoveClass()
}
/**
- * @KVS\Entity
+ * @KVS\Entity(storageName="post")
*/
class Post
{
@@ -15,7 +15,7 @@ public function testCrud()
}
switch ($GLOBALS['DOCTRINE_KEYVALUE_AZURE_AUTHSCHEMA']) {
- case 'shared':
+ case 'sharedlite':
$auth = new SharedKeyLiteAuthorization(
$GLOBALS['DOCTRINE_KEYVALUE_AZURE_NAME'],
$GLOBALS['DOCTRINE_KEYVALUE_AZURE_KEY']

0 comments on commit 17f6059

Please sign in to comment.