DCOM-28: Extract Common Persistance Interfaces #591

Closed
doctrinebot opened this Issue Oct 13, 2010 · 18 comments

2 participants

@doctrinebot

Jira issue originally created by user @beberlei:

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.

@doctrinebot

Comment created by @jwage:

Added the interfaces here 59e6b8c

I implemented them here in the mongodb-odm doctrine/mongodb-odm@8d02e84

and the ORM doctrine/doctrine2@68a4099

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.

@doctrinebot

Comment created by @guilhermeblanco:

Jon is working on this.

@doctrinebot

Comment created by @lsmith77:

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

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by @lsmith77:

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.

@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Comment created by @lsmith77:

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.

@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Comment created by @lsmith77:

Just a super trivial pull to add this to the interface:
#11

@doctrinebot

Comment created by @lsmith77:

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

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by @jwage:

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)));
}
@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Comment created by @jwage:

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.

@doctrinebot

Comment created by @lsmith77:

i want to heat this topic back up:

  • findMany()
  • id generator API
@doctrinebot

Comment created by @guilhermeblanco:

Closing as this was already done previously.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment