Skip to content

Commit

Permalink
Clarify case where Storage#find() does not find an entry in the stora…
Browse files Browse the repository at this point in the history
…ge layer.
  • Loading branch information
beberlei committed May 12, 2012
1 parent b5cc4ee commit 208936d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
26 changes: 26 additions & 0 deletions lib/Doctrine/KeyValueStore/NotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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;

class NotFoundException extends KeyValueStoreException
{

}

4 changes: 3 additions & 1 deletion lib/Doctrine/KeyValueStore/Storage/DBALStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

namespace Doctrine\KeyValueStore\Storage;

use Doctrine\KeyValueStore\NotFoundException;

/**
* Relational databased backed system.
*
Expand Down Expand Up @@ -130,7 +132,7 @@ public function find($storageName, $key)
$stmt = $this->conn->executeQuery($sql, array($key));
$data = $stmt->fetchColumn();
if (!$data) {
return null;
throw new NotFoundException();
}

return unserialize($data);
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/KeyValueStore/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ function delete($storageName, $key);
*
* Important note: The returned array does contain the identifier (again)!
*
* @throws Doctrine\KeyValueStore\NotFoundException When data with key is not found.
*
* @param string $storageName
* @param array|string $key
* @return array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema;
use Doctrine\KeyValueStore\Query\RangeQuery;
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
use Doctrine\KeyValueStore\NotFoundException;

/**
* Storage implementation for Microsoft Windows Azure Table.
Expand Down Expand Up @@ -231,8 +232,9 @@ public function find($storageName, $key)

$response = $this->request('GET', $url, '', $headers);

if ($response->getStatusCode() != 200) {
// Todo: do stuff
switch ($response->getStatusCode()) {
case 404:
throw new NotFoundException();
}

$dom = new \DomDocument('1.0', 'UTF-8');
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/KeyValueStore/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function reconsititute($className, $key)
$id = $this->idHandler->normalizeId($class, $key);
$data = $this->storageDriver->find($class->storageName, $id);

if (!$data) {
throw new NotFoundException();
}

return $this->createEntity($class, $id, $data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public function testCrud()
$this->assertEquals('baz', $data['bar']);

$storage->delete("test", $key);
$data = $storage->find("test", $key);
$this->assertEquals(array(), $data);

$this->setExpectedException("Doctrine\KeyValueStore\NotFoundException");
$storage->find("test", $key);
}

public function testQueryRange()
Expand Down

0 comments on commit 208936d

Please sign in to comment.