Morphia Single dao for multiple collection MongoDB -


can morphia single basicdao handle/query multiple collection, may by overloading function class parameter.

public class genericdao extends basicdao<t, k> {    /* override count impl*/   public long count(class<t> clazz) {      return ds.getcount(clazz);   } } 

is there other way can query 2 different collection using single doa or better make separate dao each collection.

example user , blogentry collections

public class blogentrydao extends basicdao<blogentry, objectid> public class userdao extends basicdao<user, objectid> 

the simple answer no,

the basicdao made made on assumption deal single collection/entity many of doa's function entity/class , _id/primary key type based.

public class basicdoa<t,k> implements doa<t,k> 

t should specific class
k should specific key (can separate different class) e.g objectid, string, long etc

example function

public class<t> getentityclass() public t get(k id) 

if want deal multiple collection in single dao create own generic dao custom methods , use datastore deal different/specific collections.

public class mydao {   protected datastoreimpl ds;    public count(class<t> clazz) {     return ds.getcount(clazz);   }    public t get(class<t> clazz, k id) {      return ds.get(clazz, id);   } } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -