Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Riak #6

Merged
merged 6 commits into from Jul 3, 2012
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -26,7 +26,7 @@ Following vendors are targeted:
* Amazon DynamoDB
* CouchDB
* MongoDB
* Riak
* Riak (Implemented)

We happily accept contributions for any of the drivers.

Expand Down
6 changes: 6 additions & 0 deletions composer.json
Expand Up @@ -3,6 +3,12 @@
"require": {
"doctrine/common": "*"
},
"suggest": {
"riak/riak-client": "dev-master"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest does not expect a version constraint but a string displayed to the user. so you could make it better by using "riak/riak-client": "to use the Riak storage". This will output "doctrine/key-value-store" suggest installing "riak/riak-client" (to use the Riak storage)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah awesome!
Thank you ;)

},
"require-dev": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add riak to the "suggest" key aswell, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes sense. I will add riak to the suggest section.

"riak/riak-client": "dev-master"
},
"description": "Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.",
"license": "MIT",
"autoload": {
Expand Down
19 changes: 14 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions lib/Doctrine/KeyValueStore/Storage/RiakStorage.php
@@ -0,0 +1,137 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/


namespace Doctrine\KeyValueStore\Storage;

use Doctrine\KeyValueStore\NotFoundException;

use Riak\Client;

/**
* @author Markus Bachmann <markus.bachmann@bachi.biz>
*/
class RiakStorage implements Storage
{
/**
* @var \Riak\Client
*/
protected $client;

/**
* Constructor
*
* @param \Riak\Client $riak
* @param string $bucketName
*/
public function __construct(Client $riak)
{
$this->client = $riak;
}

/**
* {@inheritDoc}
*/
public function supportsPartialUpdates()
{
return false;
}

/**
* {@inheritDoc}
*/
public function supportsCompositePrimaryKeys()
{
return false;
}

/**
* {@inheritDoc}
*/
public function requiresCompositePrimaryKeys()
{
return false;
}

/**
* {@inheritDoc}
*/
public function insert($storageName, $key, array $data)
{
$bucket = $this->client->bucket($storageName);
$object = $bucket->newObject($key, $data);
$object->store();
}

/**
* {@inheritDoc}
*/
public function update($storageName, $key, array $data)
{
$bucket = $this->client->bucket($storageName);
/** @var $object \Riak\Object */
$object = $bucket->get($key);

$object->setData($data);
$object->store();
}

/**
* {@inheritDoc}
*/
public function delete($storageName, $key)
{
$bucket = $this->client->bucket($storageName);

/** @var $object \Riak\Object */
$object = $bucket->get($key);

if (!$object->exists()) {
// object does not exist, do nothing
return;
}

$object->delete();
}

/**
* {@inheritDoc}
*/
public function find($storageName, $key)
{
$bucket = $this->client->bucket($storageName);

/** @var $object \Riak\Object */
$object = $bucket->get($key);

if (!$object->exists()) {
throw new NotFoundException;
}

return $object->getData();
}

/**
* {@inheritDoc}
*/
public function getName()
{
return 'riak';
}
}