View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Db_Document
{zone-data}

{zone-data:proposer-list}
[Rostislav Mykhajliw|mailto:necromant2005@gmail.com]
{zone-data}

{zone-data:liaison}
http://github.com/necromant2005/zeus
{zone-data}

{zone-data:revision}
1.2 - 31 December 2010: Beta.
{zone-data}

{zone-data:overview}
Zend_Db_Document implements abstract interface to nosql storages.
{zone-data}

{zone-data:references}
* [MongoDB|http://www.mongodb.org/display/DOCS/Home]
* [CouchDB|http://couchdb.apache.org/]
* [Riak|http://riak.basho.com/]
* [ProjectVoldemort|http://project-voldemort.com/]

* [NoSQL patterns|http://horicky.blogspot.com/2009/11/nosql-patterns.html]
* [NoSQL application development|http://blogs.forrester.com/application_development/2010/02/nosql.html]
* [Google Map-Reduce|http://code.google.com/edu/submissions/mapreduce-minilecture/listing.html]
{zone-data}

{zone-data:requirements}
Currently Zend haven't got any adapters to NOSQL storages, but a lot of real application is needed this. Cause NOSQL stoges is more flexible than SQL RDMS, and provide to build a most powerful and performance application.

* This component *will* provide adapters to NOSQL stores
* This component *will* provide get/set operation
* This component *will* provide update/save document operation
* This component *will* provide MapRecude query interface
* This component *will* provide Document object (similar to Zend_Db_Table_Row_Abstract)

* This component *will* provide transformation adapters to support Zend_Db_Table
{zone-data}

{zone-data:dependencies}
* Zend_Json
* Zend_Http_Client
* Zend_Protobuff

{zone-data}

{zone-data:operation}
The primary goal of this component is provide abstract interface to NoSQL storages, witch provide functional by get/set, search, map-reduce queries and very easy interface to update/save/validate document to storage. To do this, we must take several factors into account:

* Transform output result set to array
* Query languages are usually JavaScript, and How exactly build queries the most interesting is map-reduce queries. Cause for simple queries we can develop interface similar to Zend_Db_Select , witch current Adapter will transform into himself query language.
* It must provide full interface to direct queries
* In the first step adapter will provide simple interface get/set by key and direct interface for query.
* Version of documents (in general storages return system field _rev for revision and _id for UID of document)

* Integration with exist Zend\Db\Table
* Integration validation document structure

{zone-data}

{zone-data:milestones}
The first implement most popular nosql storages MongoDB/CouchDB and later all exists.

* Milestone 1: [DONE] create abstract classes storages and document
* Milestone 2: [DONE] build base functionality get/set by key
* Milestone 3: [DONE] integrate query builder
* Milestone 4: integrate query builder for map reduce
* Milestone 5: do new adapters and go to Milestone 1 :).

{zone-data}

{zone-data:class-list}
* Zend\Db\Document (factory class)
* Zend\Db\Document\AbtractAdapter
* Zend\Db\Document\AbstractDocument
* Zend\Db\Document\AbstractCollection

* Zend\Db\Document\Adapter\Mongo
* Zend\Db\Document\Adapter\Couch
* Zend\Db\Document\Adapter\Riak
* Zend\Db\Document\Adapter\Voldemort

* Zend\Db\Document\Document\Mongo
* Zend\Db\Document\Document\Couch
* Zend\Db\Document\Document\Riak
* Zend\Db\Document\Document\Voldemort

* Zend\Db\Document\Collection\Mongo
* Zend\Db\Document\Collection\Couch
* Zend\Db\Document\Collection\Riak
* Zend\Db\Document\Collection\Voldemort

{zone-data}

{zone-data:use-cases}
||UC-01||

Factory
{code}
$adapter = Zend\Db\Document::factory('MongoDb', array(
'host' => '127.0.0.1',
'dbname' => 'dbtest',
));
{code}

||UC-02||
Use adapter for get object and store
{code}
// as array It's not very beautiful cause for revistion you must store technical information "_rev", "_id" for document
$adapter = Zend\Db\Document::factory('Couch', array( ... ));
$user = $adapater->getCollection('test')->get('peter');
$user['age'] = 24;
$adapter->save($user);

// OO, user know all about itself.
$adapter = Zend_Db_Document::factory('Couch', array( ... ));
$user = $adapater->getCollection('test')->get('peter');
$user->age = 24;
// or ArrayAccess interface
$user['age'] = 24;
$adapter->save($user);


// OO
$adapter = Zend_Db_Document::factory('CouchDb', array( ... ));
$user = $adapater->getCollection('test')->get('peter');
$user->age = 24;
$user->save();
{code}






||UC-07||
Create new document with document id
{code}
$adapter->put('user1234', array(
'name' => 'bob',
'age' => 37,
));
{code}

||UC-08||
Create new document with auto generated document id
{code}
$adapter->put(array(
'name' => 'bob',
'age' => 37,
));
{code}
{zone-data}

{zone-data:skeletons}

Exceptions
{code}
class Zend\Db\Document\Exception extends Zend\Exception {}

class Zend\Db\Document\Adapter\Exception extends Zend\Db\Document\Exception {}
{code}

{code}
class Zend\Db\Document
{
public static function factory($adapterName, $adapterOptions)
{}
}
{code}
Zend\Db\Document\AbstractAdapter
{code}
abstract class Zend\Db\Document\AbstractAdapter
{
protected $_connection = null;

public function __construct()
{}

public function connect()
{}

public function disconnect()
{}

protected abstract function _connect()
{}

protected abstract function _disconnect()
{}

public function delete($collectionName, $name)
{}

public function get($collectionName, $name)
{}

public function put($collectionName, $name, $data)
{}

public function post($collectionName, $data)
{}

public function findOne($collectionName)
{}

public function find($collectionName)
{}
}
{code}



Zend\Db\Document\AsbtractDocument
{code}
class Zend\Db\Document\AbstractDocument
{
public function __construct($data)
{}

public function setCollection()
{}

public function getCollection()
{}

public function save()
{}

public function setFromArray()
{}

public function toArray()
{}

public function getId()
{}

public function __get($name)
{}

public function __set($name, $value)
{}

public function __isset($name)
{}
}
{code}

Zend\Db\Document\AbstractCollection
{code}
class Zend\Db\Document\AbstractCollection
{
public function __construct($adapter, $name)
{}

public function setAdapter()
{}

public function getAdapter()
{}

public function get($name)
{}

public function put($name, $data)
{}

public function post($data)
{}

public function delete($name)
{}

public function save($document)
{}
}
{code}

{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>