Created
March 16, 2015 14:36
-
-
Save jotak/54e46b022f6b700a5f91 to your computer and use it in GitHub Desktop.
querydsl-collections with Optional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment