- Notifications
You must be signed in to change notification settings - Fork 10
ajermakovics edited this page Nov 15, 2014
·
7 revisions
Welcome to the lambda2sql wiki!
Example using Hazelcast distributed map.
Here we build and run a distributed query using a lambda. The query is checked at compile time and it's quite readable as well!
publicstaticvoidmain( String[] args )
{
Lambda2Sql.init();
HazelcastInstancehz = Hazelcast.newHazelcastInstance();
IMap<Integer, Employee> map = hz.getMap("employees");
putData(map);
Collection<Employee> vals;
// run the queryvals = values(map, e -> e.isActive() && e.getAge() > 30 );
System.out.println(vals.size());
}
static <T> Collection<T> values(IMap<?, T> map, java.util.function.Predicate<T> p) {
returnmap.values( toSqlPred(p) );
}
static <T> Predicate<?, T> toSqlPred(java.util.function.Predicate<T> p) {
returnnewSqlPredicate( Lambda2Sql.toSql( p ) );
}
staticvoidputData(IMap<Integer, Employee> map) {
map.put(1, newEmployee("alice", 30, true, 100));
map.put(2, newEmployee("bob", 40, true, 200));
}