java - CQEngine In Clause with MultiValueNullableAttribute -
i have class object1 has list of longs called tags. have list of longs called tagstosearch. how can construct query using cqengine following:
select * object1 tags in (tagstosearch)
if knows how using cqengine please let me know.
this should trick:
package com.googlecode.cqengine; import com.googlecode.cqengine.attribute.*; import com.googlecode.cqengine.query.query; import com.googlecode.cqengine.query.option.queryoptions; import com.googlecode.cqengine.query.parser.sql.sqlparser; import java.util.*; import static com.googlecode.cqengine.codegen.attributebytecodegenerator.*; import static com.googlecode.cqengine.query.queryfactory.*; import static java.util.arrays.aslist; public class tagsexample { static class myobject { final string name; final list<long> tags; public myobject(string name, list<long> tags) { this.name = name; this.tags = tags; } static final attribute<myobject, long> tags = new multivalueattribute<myobject, long>("tags") { public iterable<long> getvalues(myobject object, queryoptions queryoptions) { return object.tags; } }; } public static void main(string[] args) { indexedcollection<myobject> collection = new concurrentindexedcollection<>(); collection.add(new myobject("foo", aslist(1l, 2l, 3l))); collection.add(new myobject("bar", aslist(4l, 5l, 6l))); collection.add(new myobject("baz", aslist(7l, 8l, 9l))); // search via programmatic query... query<myobject> nativequery = in(myobject.tags, aslist(3l, 9l)); collection.retrieve(nativequery) .foreach(object -> system.out.println(object.name)); // ..prints: foo, baz // search via sql query... string sqlquery = "select * collection tags in (3, 9)"; sqlparser<myobject> parser = sqlparser.forpojowithattributes(myobject.class, createattributes(myobject.class)); parser.retrieve(collection, sqlquery) .foreach(object -> system.out.println(object.name)); // ..prints: foo, baz } }
Comments
Post a Comment