> 2.)
>
> List<Query<Asset>> queries = new ArrayList<Query<Asset>>();
> queries.add(ds.createQuery(AssetState.class).field("name").equal("asset-1"));
> queries.add(ds.createQuery(AssetState.class).field("name").equal("asset-2"));
is my fav, but you´re right saying
> There are options in
> a query you can't use in an "or" (like limit/skip/sort) and you can't
> mix and match different types either.
So what if we had a dedicated class for criteria gained from the query
(so that it has the type info)
Query q = createQuery(Foo.class);
Criteria c = q.crit();
c.and( c.field("deleted").equal(false) );
c.or(
c.field("published").equal(true) ,
c.field("draft").equal(true)
)
one painpoint is that c.field(x).equal(y) is no longer automatically
added to the query. to fail fast we could keep track of orphaned
(created but unused) criteria, and fail/warn.
we could still keep
q.field("foo").equal("bar")
for the 90% usecase, which would then be basically the same than
q.crit().and(q.crit().field("foo").equal("bar"));
i do not think anyone really wants to define a query with or/and groups
in one line.
cu uwe
>> I'm not so keen on 2 since it isn't quite correct
I did not like loading up a Collection either, it's a pretty dirty
hack. It was designed as a proof-of-concept before I started on method
#1, my preferred.
You mentioned that the criteria clauses are dirty, since they support
things like limiting and sorting. These obviously should only be
applicable at the "top-level" query. This applies to both of my
suggested methods:
or.add().limit(12)
... is clearly invalid. This could be solved by applying an interface
(Filterable?) to Query, then having add() return this interface. Under
the covers, you'd still be dealing with a full Query object, but only
given permission to use the filtering methods.
I also like Uwe's suggestion, but am not sure how difficult it would
be to implement. I'd certainly be willing to give it a shot.
Thoughts?
Norman
Hi Norman
> I also like Uwe's suggestion, but am not sure how difficult it would
> be to implement. I'd certainly be willing to give it a shot.
isn´t particularly hard to do. i did similar stuff (a criteria API) for
JPA before, which could serve as an example (which is far more complex
due to supporting aliases and joins)
cu uwe
I like your idea best. If you've got time to take a stab at it, go for
it. Otherwise let me know and I'll see what I can whip up. I would
just need to research how the validation stuff works to make sure
everything places nicely together.
Norman