use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.
the class JPAUtilsCriteriaFilterTest method testQueryCriteriaFilterWithParamsOr.
@Test
public void testQueryCriteriaFilterWithParamsOr() {
QueryFilter qf = new QueryFilter();
qf.setField("lastname");
qf.setOperation(FilterOperation.EQ);
qf.setValue("Turner");
QueryParameters q = new QueryParameters();
q.getFilters().add(qf);
List<User> users = JPAUtils.queryEntities(em, User.class, q, (p, cb, r) -> cb.or(p, cb.equal(r.get("firstname"), "Antonio")));
Assert.assertNotNull(users);
Assert.assertEquals(4, users.size());
Assert.assertNotNull(users.get(0));
Assert.assertEquals("Antonio", users.get(0).getFirstname());
Assert.assertEquals("Mills", users.get(0).getLastname());
Assert.assertNotNull(users.get(1));
Assert.assertEquals("Antonio", users.get(1).getFirstname());
Assert.assertEquals("Carroll", users.get(1).getLastname());
Assert.assertNotNull(users.get(2));
Assert.assertEquals("Antonio", users.get(2).getFirstname());
Assert.assertEquals("Turner", users.get(2).getLastname());
Assert.assertNotNull(users.get(3));
Assert.assertEquals("Bonnie", users.get(3).getFirstname());
Assert.assertEquals("Turner", users.get(3).getLastname());
Long usersCount = JPAUtils.queryEntitiesCount(em, User.class, q, (p, cb, r) -> cb.or(p, cb.equal(r.get("firstname"), "Antonio")));
Assert.assertNotNull(usersCount);
Assert.assertEquals(4, usersCount.longValue());
}
use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.
the class JPAUtilsFiltersTest method testInic.
@Test
public void testInic() {
QueryFilter qf = new QueryFilter();
qf.setField("firstname");
qf.setOperation(FilterOperation.INIC);
qf.getValues().add("sArAH");
qf.getValues().add("ricHArd");
qf.getValues().add("jACk");
QueryParameters q = new QueryParameters();
q.getFilters().add(qf);
List<User> users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(4, users.size());
}
use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.
the class JPAUtilsFiltersTest method testSingleFilter.
@Test
public void testSingleFilter() {
QueryFilter qf = new QueryFilter();
qf.setField("firstname");
qf.setOperation(FilterOperation.EQ);
qf.setValue("Sandra");
QueryParameters q = new QueryParameters();
q.getFilters().add(qf);
List<User> users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(1, users.size());
Assert.assertNotNull(users.get(0).getFirstname());
Assert.assertEquals("Sandra", users.get(0).getFirstname());
}
use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.
the class JPAUtilsFiltersTest method testGte.
@Test
public void testGte() {
QueryFilter qf = new QueryFilter();
qf.setField("role");
qf.setOperation(FilterOperation.GTE);
qf.setValue("1");
QueryParameters q = new QueryParameters();
q.getFilters().add(qf);
List<User> users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(47, users.size());
Date d = Date.from(ZonedDateTime.parse("2014-11-26T11:15:08Z").toInstant());
qf = new QueryFilter();
qf.setField("createdAt");
qf.setOperation(FilterOperation.GTE);
qf.setDateValue(d);
q = new QueryParameters();
q.getFilters().add(qf);
users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(40, users.size());
}
use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.
the class JPAUtilsFiltersTest method testLte.
@Test
public void testLte() {
QueryFilter qf = new QueryFilter();
qf.setField("role");
qf.setOperation(FilterOperation.LTE);
qf.setValue("0");
QueryParameters q = new QueryParameters();
q.getFilters().add(qf);
List<User> users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(53, users.size());
Date d = Date.from(ZonedDateTime.parse("2014-11-26T11:15:08Z").toInstant());
qf = new QueryFilter();
qf.setField("createdAt");
qf.setOperation(FilterOperation.LTE);
qf.setDateValue(d);
q = new QueryParameters();
q.getFilters().add(qf);
users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(61, users.size());
}
Aggregations