How can Query All Entries??

312 views
Skip to first unread message

Marcel Schneider

unread,
Jul 17, 2014, 12:34:49 PM7/17/14
to cqengine...@googlegroups.com
Hello,

how can reteice all object without a special select-statement, but with and queryseletion, like order by.

thanks alot


Niall

unread,
Jul 17, 2014, 1:24:40 PM7/17/14
to cqengine...@googlegroups.com
Hi Marcel,

Currently with the built-in queries, the only way is to use a query which will evaluate true for every object. Like 'has(Car.CAR_ID)' or something like that.

I am planning to add 'all()' and 'none()' to CQEngine in future, but you can add them to your app now with the following class.

To use it:
ResultSet<Car> allCarsOrderedByPrice = retrieve(all(Car.class), queryOptions(orderBy(descending(Car.PRICE))));


package com.googlecode.cqengine.query;

import com.googlecode.cqengine.attribute.Attribute;
import com.googlecode.cqengine.attribute.SelfAttribute;
import com.googlecode.cqengine.attribute.SimpleAttribute;
import com.googlecode.cqengine.query.simple.SimpleQuery;

/**
 * Adds literal queries all() and none() to CQEngine query syntax.
 * <p/>
 * To use these queries, add a static import for {@code LiteralQueryFactory.*}.
 *
 * @author ngallagher
 */

public class LiteralQueryFactory {

   
static class LiteralQuery<O> extends SimpleQuery<O, O> {

       
final boolean literalValue;

       
public LiteralQuery(Class<O> objectType, boolean literalValue) {
           
super(new SelfAttribute<O>(objectType, String.valueOf(literalValue)));
           
this.literalValue = literalValue;
       
}

       
@Override
       
protected boolean matchesSimpleAttribute(SimpleAttribute<O, O> attribute, O object) {
           
return literalValue;
       
}

       
@Override
       
protected boolean matchesNonSimpleAttribute(Attribute<O, O> attribute, O object) {
           
return literalValue;
       
}

       
@Override
       
protected int calcHashCode() {
           
return 1413898556; // chosen randomly
       
}
   
}

   
/**
     * Private constructor, not used.
     */

   
LiteralQueryFactory() {
   
}

   
public static <O> Query<O> all(Class<O> objectType) {
       
return new LiteralQuery<O>(objectType, true);
   
}

   
public static <O> Query<O> none(Class<O> objectType) {
       
return new LiteralQuery<O>(objectType, false);
   
}
}

HTH,
Niall

Marcel Schneider

unread,
Jul 17, 2014, 1:44:30 PM7/17/14
to cqengine...@googlegroups.com
thank you,

i think, i am waiting at least for the all()-subquery, i have used a one-member (true) criteria, it is okay at this time, like this project ;)

ciao
Marcel

Niall

unread,
Nov 25, 2014, 5:41:50 PM11/25/14
to cqengine...@googlegroups.com
This is done, you can find all() in CQEngine 1.3.1 :)
Reply all
Reply to author
Forward
0 new messages