Requirements
The requirements for build a query with query builder is an java Object Oriented "Domain" that is an group of persisted objects.
The requirements for build a query with query builder is an java Object Oriented "Domain" that is an group of persisted objects.
public class Dog { private String name; private Person owner; private Home home; ...gets sets... };
public class Person { private String name; private List<Person> friends; private Person mum; private Person dud; private Home home; private Dog dog; ...gets sets... }
public class Home { public enum HomeType {KENNEL,HOUSE}; private String address; private HomeType type; private int weight; private double price; ...gets sets... }
Search All person that live in "rue d'anton" with a mum with name "elisabeth" and order by name.
QueryEngine <?> engine= ... SelectQuery<Person> query = engine.newSelect(Person.class); Person toSearch = query.target(); query.eq(toSearch.getHome().getAddress(),"rue d'anton"); query.eq(toSearch.getMum().getName(),"elisabeth"); query.order(toSearch.getName());
Correspondent Pseudo QL
select from Person where home.address="rue d'anton" and mum.name="elisabeth" order by name
Select name and address of person.
QueryEngine <?> engine= ... SelectQuery<Person> query = engine.newSelect(Person.class); Person toSearch = query.target(); query.prj(toSearch.getName()); query.prj(toSearch.getHome().getAddress());
Correspondent Pseudo QL
select name, home.address from Person
Count all person that live in "rue d'anton"
QueryEngine <?> engine= ... SelectQuery<Person> query = engine.newSelect(Person.class); Person toSearch = query.target(); query.prj(toSearch,ProjectionType.COUNT); query.eq(toSearch.getHome().getAddress(),"rue d'anton");
Correspondent Pseudo QL
select count(*) from Person where home.address="rue d'anton"
Search all person with name elisabeth or jhon.
QueryEngine <?> engine= ... SelectQuery<Person> query = engine.newSelect(Person.class); Person toSearch = query.target(); QueryCondition or = oq.or(); or.eq(toSearch.getName(),"elisabeth"); or.eq(toSearch.getName(),"jhon");
Correspondent Pseudo QL
select from Person where name="elisabeth" or name="jhon"
Primitive type need a different management, for some technical reasons is not possible use primitive type directly
for use it we need to box it
QueryEngine <?> engine= ... SelectQuery<Home> query = engine.newSelect(Home.class); Home toSearch = query.target(); query.eq(query.box(toSearch.getWeight()),2); query.eq(query.box(toSearch.getPrice()),4000.0);
Correspondent Pseudo QL
select from Home where weight=2 and price=4000.0
Search for an House with weight more than 2 an price less than 4000
QueryEngine <?> engine= ... SelectQuery<Home> query = engine.newSelect(Home.class); Home toSearch = query.target(); query.gt(query.box(toSearch.getWeight()),2); query.lt(query.box(toSearch.getPrice()),4000.0);
Correspondent Pseudo QL
select from Home where weight>2 and price<4000.0
Search for Home with "rue" or "Rue" or "RUE" inside the address
QueryEngine <?> engine= ... SelectQuery<Home> query = engine.newSelect(Home.class); Home toSearch = query.target(); query.likeNc(toSearch.getAddress(),"rue");
Correspondent Pseudo QL
select from Home where upper(address) like uppder("rue")