Skip to content

Instantly share code, notes, and snippets.

@jotak
Created March 16, 2015 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jotak/54e46b022f6b700a5f91 to your computer and use it in GitHub Desktop.
Save jotak/54e46b022f6b700a5f91 to your computer and use it in GitHub Desktop.
querydsl-collections with Optional
package cat;
import static com.mysema.query.alias.Alias.$;
import static com.mysema.query.alias.Alias.alias;
import static com.mysema.query.collections.CollQueryFactory.from;
import java.util.ArrayList;
import java.util.Collection;
import com.google.common.base.Optional;
public class Cat {
private Optional<String> pedigree = Optional.absent();
public Cat() {
}
public Cat(Optional<String> pedigree) {
this.pedigree = pedigree;
}
public Optional<String> getPedigree() {
return pedigree;
}
public static void main(String[] args) {
Collection<Cat> cats = new ArrayList<>();
cats.add(new Cat(Optional.<String>absent()));
cats.add(new Cat(Optional.of("persan")));
Cat c = alias(Cat.class);
for (Cat cat : from(c, cats)
.where($(c.getPedigree()).eq(Optional.of("persan")))
.list($(c))){
System.out.println(cat);
}
}
}
@jotak
Copy link
Author

jotak commented Mar 16, 2015

Exception in thread "main" com.mysema.codegen.CodegenException: Compilation of public class Q_0390602011_1275614662_1275614662_566403833 {

    public static Iterable<cat.Cat> eval(Iterable<cat.Cat> cat_, com.google.common.base.Present a1) {
        java.util.List<cat.Cat> rv = new java.util.ArrayList<cat.Cat>();
        for (cat.Cat cat : cat_) {
            try {
                if (com.mysema.query.collections.CollQueryFunctions.equals(cat.getPedigree(), a1)) {
                    rv.add(cat);
                }
            } catch (NullPointerException npe) { }
        }
        return rv;    }

}

failed.
        /Q_0390602011_1275614662_1275614662_566403833.java:3: error: Present is not public in com.google.common.base; cannot be accessed from outside package
public static Iterable<cat.Cat> eval(Iterable<cat.Cat> cat_, com.google.common.base.Present a1) {
        ^
        1 error

        at com.mysema.codegen.JDKEvaluatorFactory.compile(JDKEvaluatorFactory.java:74)
        at com.mysema.codegen.AbstractEvaluatorFactory.createEvaluator(AbstractEvaluatorFactory.java:128)

@jotak
Copy link
Author

jotak commented Mar 16, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment