Morphia. How to clone query with different collection(kind)

16 views
Skip to first unread message

vacuum

unread,
Feb 29, 2012, 12:20:05 PM2/29/12
to mor...@googlegroups.com

Original questin.

The problem is about searching by query in different collections.

There is a method in AdvancedDatastore interface:

<T> Query<T> createQuery(String kind, Class<T> clazz, DBObject q);

But its only create query with given baseQuery and I need full clone of Query but with different DBCollection field. Any suggestions?

Here is my method to convert query:

public Query<Vacancy> convertQuery(Query<T> query) {
        QueryImpl<T> queryImpl = (QueryImpl<T>) query;
        DBObject dbO = queryImpl.getQueryObject();
        Query<T> our_query = ((AdvancedDatastore)this.getDatastore()).createQuery("AnotherCollectionName", T.class, dbO);           
        return our_query;
    }

Works fine with reflection, but I dont like this dirty way because of perfomance.

Scott Hernandez

unread,
Mar 5, 2012, 2:30:31 PM3/5/12
to mor...@googlegroups.com
I don't think there is an easy way to do this right now. We could add
an override on the query for this kind of thing like on fetch/get so
the query doesn't get changed.
Reply all
Reply to author
Forward
0 new messages