[DCOM-28] Extract Common Persistance Interfaces Created: 13/Oct/10  Updated: 21/Apr/14  Resolved: 21/Apr/14

Status: Resolved
Project: Doctrine Common
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Benjamin Eberlei Assignee: Guilherme Blanco
Resolution: Fixed Votes: 0
Labels: None

Attachments: File dcom_persistence.diff    
Issue Links:
Duplicate
is duplicated by DCOM-23 Add interface for ObjectManager Resolved

 Description   

I discussed this with jwage on symfony day cologne and this also came up during discussions with @dzuelke at IPC yesterday. So i hacked up a first patch for discussion that adds a Doctrine\Common\Persistance namespace and extracts the functionality all our 3 layers implement with regards to EntityManager/EntityRepository (and equivalents).

Additionally i think it might make sense to also add an interface "ObjectMetadata" that has several getters-only that allow access to the field, identifier and association mapping information. This stuff is not necessarly compatible across layers when returned as its "array" representation, but for libraries hooking into the metadata (symfony admin generator) this might not even be necessary.



 Comments   
Comment by Jonathan H. Wage [ 15/Feb/11 ]

Added the interfaces here https://github.com/doctrine/common/commit/59e6b8c6edcb271622923035b687a063c2b47ce8

I implemented them here in the mongodb-odm https://github.com/doctrine/mongodb-odm/commit/8d02e8439fb6737de1e23e1953a643858a8a6c68

and the ORM https://github.com/doctrine/doctrine2/commit/68a40996841b1dbec3b8de5c1038809e5db512b7

I think we can add a few more methods to ClassMetadata interface that are always gonna exist between the different persistence layers. Let me know what you think and what you want to add.

Comment by Guilherme Blanco [ 15/Feb/11 ]

Jon is working on this.

Comment by Lukas Kahwe [ 19/Mar/11 ]

CouchDB ODM also has DocumentRepositry::findMany(array $ids)
Should we add that to the interface?

Comment by Benjamin Eberlei [ 19/Mar/11 ]

No, that method is only on the repository because CouchDB doesn't need persisters (yet). Its not part of the interfaceable public methods.

Comment by Lukas Kahwe [ 19/Mar/11 ]

Not sure I understand. The method is used in DocumentRepository::findBy() as well as in PersistentIdsCollection::load. Seems unnecessary for that method to be public just for this. At any rate imho the method seems convenient and also allows for more efficient access in many RDBMS compared to the generic findBy($criteria) method. So it seems worthwhile adding it.

Comment by Benjamin Eberlei [ 20/Mar/11 ]

It doesn't matter what CouchDB uses internally on the DocumentRepository, i don't think this method is particularly useful in another context than CouchDBs use of Collections. In any case the method is just a proxy for findBy(array("id" => array(1, 2, 3, 4, 5, 6))); and i am not sure we need such a method on an interface just for convenience, Repository::find() use-case is much broader.

Comment by Lukas Kahwe [ 20/Mar/11 ]

Actually using findMany($ids) ias clearly more efficient in CouchDB than using findBy(array("id" => $ids));
The same applies to PHPCR, since going by the node path means you can go via the normal node API, rather than the search API.
So this is already 2 out of 3 examples and I do not know MongoDB enough to tell if they also have some specific API advantage.

Comment by Benjamin Eberlei [ 20/Mar/11 ]

Hm, you might be right. Ok, this should be included.

What i am still pondering with is adding array $orderBy and $firstResult, $maxResults to findOneBy() and findBy() and findAll().

@Jon: Would this be possible for MongoDB?

It would not be possible for all use-cases in CouchDB, but for some it can work.

Comment by Lukas Kahwe [ 20/Mar/11 ]

Just a super trivial pull to add this to the interface:
https://github.com/doctrine/common/pull/11

Comment by Lukas Kahwe [ 21/Mar/11 ]

also wondering if we want to include the idgenerator API in the interface?

Comment by Benjamin Eberlei [ 21/Mar/11 ]

Hm yes, i think that is necessary. At least the differentation between assigned and auto-generated ids is relevant for metadata queries.

Comment by Jonathan H. Wage [ 21/Mar/11 ]

Yes, findMany() is possible with MongoDB.

I think it would just be a proxy to:

public function findMany(array $ids)
{
    return $this->findBy(array('_id' => array('$in' => $ids)));
}
Comment by Benjamin Eberlei [ 21/Mar/11 ]

Hm, What is this syntax? This is not conforming to the EntityRepository interface.

The only two allowed methods are:

IN Query:

$ids = array(...);
findBy(array('_id' => $ids)); 

Equals = Query:

$ids = 1234;
findBy(array('_id' => $id)); 

Everything else is not portable accross implementations and should only be able through DocumentManager::CreateQuery* sort of apis.

Comment by Jonathan H. Wage [ 21/Mar/11 ]

To find by things in MongoDB you just give an array of key => value pairs. It gets passed straight through to MongoDB. The $in syntax is just soemthing mongodb supports. It's not anything specific to Doctrine.

Comment by Lukas Kahwe [ 30/Jul/11 ]

i want to heat this topic back up:

  • findMany()
  • id generator API
Comment by Guilherme Blanco [ 21/Apr/14 ]

Closing as this was already done previously.

Generated at Fri Nov 28 03:12:46 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.