Permalink
Browse files

Add Initial KeyValueStore implementation with DoctrineCacheStorage ba…

…ckend and some functional tests for the lifecycle of objects.
  • Loading branch information...
1 parent 4eb11eb commit 40aa2bf8c5c849ceee825dc0d304e14a6e7f3de0 @beberlei beberlei committed Feb 13, 2012
View
@@ -0,0 +1 @@
+vendor
View
@@ -8,11 +8,11 @@ The Persistence interfaces are rather overkill for many implementations in the N
* Unstructured/schema-less values that are mapped onto objects
* Depending on the implementation embedded values/objects are supported
* No complex mapping necessary, just put @Entity on the class and all properties are automatically mapped unless @Transient is given. At least one property has to be @Id. Depends on the underlying vendor though. Maybe we enforce two ids to enforce interoperability.
+* Properties dont have to exit on the class, public properties are created otherwise.
* No support for references to other objects
* EventListener for ODM/ORM that allows to manage key-value entities and collections of them as properties (postLoad, postUpdate, postPersist, postRemove)
* Stripped down Object Manager Interface
- @@@ php
<?php
namespace Doctrine\KeyValueStore;
@@ -49,4 +49,7 @@ Following vendors are targeted:
* Riak
* PHP In Memory provider
* Doctrine\Common\Cache provider
+* RDBMS (id => serialized blob)
+
+We happly accept contributions for any of the drivers.
@stof

stof Feb 13, 2012

Member

typo here

View
@@ -0,0 +1,11 @@
+{
+ "name": "doctrine/key-value-store",
+ "require": {
@stof

stof Feb 13, 2012

Member

you should add the license, the description and so on...

+ "doctrine/common": "*"
+ },
+ "autoload": {
+ "psr-0": {
+ "Doctrine\\KeyValueStore\\": "lib/"
+ }
+ }
+}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,76 @@
+<?php
+/*
+ * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\KeyValueStore;
+
+use Doctrine\KeyValueStore\Storage\Storage;
+use Doctrine\KeyValueStore\Mapping\ClassMetadataFactory;
+use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
+use Doctrine\Common\Cache\Cache;
+
+/**
+ * EntityManager for KeyValue stored objects.
+ *
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ */
+class EntityManager
@stof

stof Feb 13, 2012

Member

what do you think about splitting the Doctrine\Common\Persistence\ObjectManager interface into 2 interfaces ? A simple one with the method used here and the existing one extending it with additional methods ?

+{
+ private $unitOfWork;
+ private $storgeDriver;
+
+ public function __construct(Storage $storageDriver, Cache $cache, MappingDriver $mappingDriver)
+ {
+ $cmf = new ClassMetadataFactory($mappingDriver);
+ $cmf->setCacheDriver($cache);
+
+ $this->unitOfWork = new UnitOfWork($cmf, $cache, $storageDriver);
+ $this->storgeDriver = $storageDriver;
@stof

stof Feb 13, 2012

Member

typo in the property name

+ }
+
+ public function find($className, $key)
+ {
+ return $this->unitOfWork->reconsititute($className, $key);
+ }
+
+ public function persist($object)
+ {
+ $this->unitOfWork->scheduleForInsert($object);
+ }
+
+ public function remove($object)
+ {
+ $this->unitOfWork->scheduleForDelete($object);
+ }
+
+ public function flush()
+ {
+ $this->unitOfWork->commit();
+ }
+
+ public function unwrap()
+ {
+ return $this->storageDriver;
+ }
+
+ public function getClassMetadata($className)
+ {
+ return $this->unitOfwork->getClassMetadata($className);
+ }
+}
+
@@ -0,0 +1,90 @@
+<?php
+/*
+ * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\KeyValueStore\Mapping;
+
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
+use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
+
+class AnnotationDriver implements MappingDriver
+{
+ private $reader;
+
+ public function __construct($reader)
+ {
+ $this->reader = $reader;
+ }
+
+ /**
+ * Loads the metadata for the specified class into the provided container.
+ *
+ * @param string $className
+ * @param ClassMetadata $metadata
+ */
+ function loadMetadataForClass($className, ClassMetadata $metadata)
@stof

stof Feb 13, 2012

Member

missing public keyword

@stof

stof Feb 13, 2012

Member

same for other methods

+ {
+ $class = $metadata->getReflectionClass();
+ if (!$class) {
+ // this happens when running annotation driver in combination with
+ // static reflection services. This is not the nicest fix
+ $class = new \ReflectionClass($metadata->name);
+ }
+
+ $entityAnnot = $this->reader->getClassAnnotation($class, 'Doctrine\KeyValueStore\Mapping\Annotations\Entity');
+ if (!$entityAnnot) {
+ throw new \InvalidArgumentException($metadata->name . " is not a valid key-value-store entity.");
+ }
+
+ // Evaluate annotations on properties/fields
+ foreach ($class->getProperties() as $property) {
+ $idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\KeyValueStore\Mapping\Annotations\Id');
+ $transientAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\KeyValueStore\Mapping\Annotations\Transient');
+ if ($idAnnot) {
+ $metadata->mapIdentifier($property->getName());
+ } else if ($transientAnnot) {
+ $metdata->skipTransientField($property->getName());
+ } else {
+ $metadata->mapField(array('fieldName' => $property->getName()));
+ }
+ }
+ }
+
+ /**
+ * Gets the names of all mapped classes known to this driver.
+ *
+ * @return array The names of all mapped classes known to this driver.
+ */
+ function getAllClassNames()
+ {
+ }
+
+ /**
+ * Whether the class with the specified name should have its metadata loaded.
+ * This is only the case if it is either mapped as an Entity or a
+ * MappedSuperclass.
+ *
+ * @param string $className
+ * @return boolean
+ */
+ function isTransient($className)
+ {
+ return false;
@stof

stof Feb 13, 2012

Member

this implementation seems wrong

@beberlei

beberlei Feb 13, 2012

Owner

hehe, its a placeholder, otherwise CMF won't work.

@stof

stof Feb 14, 2012

Member

well, shouldn't you implement it properly by checking if the Entity annotation is there ?

+ }
+}
+
@@ -0,0 +1,28 @@
+<?php
+/*
+ * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\KeyValueStore\Mapping\Annotations;
+
+/**
+ * @Annotation
+ */
+class Entity
@stof

stof Feb 13, 2012

Member

shouldn't the annotations be final classes ?

+{
+}
+
@@ -0,0 +1,28 @@
+<?php
+/*
+ * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\KeyValueStore\Mapping\Annotations;
+
+/**
+ * @Annotation
+ */
+class Id
+{
+}
+
@@ -0,0 +1,28 @@
+<?php
+/*
+ * 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
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\KeyValueStore\Mapping\Annotations;
+
+/**
+ * @Annotation
+ */
+class Transient
+{
+}
+
Oops, something went wrong.

0 comments on commit 40aa2bf

Please sign in to comment.