use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.
the class QueryStringBuilder method build.
public QueryParameters build() {
log.finest("Building query string: " + query);
QueryParameters params = new QueryParameters();
if (paginationEnabled && defaultLimit != null)
params.setLimit(defaultLimit);
if (paginationEnabled && defaultOffset != null)
params.setOffset(defaultOffset);
if (query == null || query.isEmpty())
return params;
for (String pair : query.split("&+(?=([^']*'[^']*')*[^']*$)")) {
int idxOfPair = pair.indexOf("=");
if (idxOfPair == -1) {
buildPair(params, pair, "");
continue;
}
String key, value;
key = pair.substring(0, idxOfPair);
value = pair.substring(idxOfPair + 1);
buildPair(params, key, value);
}
return params;
}
use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.
the class JPAUtilsCriteriaFilterTest method testQueryWithCriteriaFilterAndWithFields.
@Test
public void testQueryWithCriteriaFilterAndWithFields() {
QueryParameters q = new QueryParameters();
q.getFields().add("firstname");
List<User> users = JPAUtils.queryEntities(em, User.class, q, (p, cb, r) -> cb.and(p, cb.equal(r.get("lastname"), "Stewart")));
Assert.assertNotNull(users);
Assert.assertEquals(1, users.size());
Assert.assertNotNull(users.get(0));
Assert.assertNotNull(users.get(0).getFirstname());
Assert.assertNull(users.get(0).getLastname());
Assert.assertEquals("Donald", users.get(0).getFirstname());
}
use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.
the class JPAUtilsCriteriaFilterTest method testQueryCriteriaFilterWithParamsAnd.
@Test
public void testQueryCriteriaFilterWithParamsAnd() {
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.and(p, cb.equal(r.get("firstname"), "Antonio")));
Assert.assertNotNull(users);
Assert.assertEquals(1, users.size());
Assert.assertNotNull(users.get(0));
Assert.assertEquals("Antonio", users.get(0).getFirstname());
Assert.assertEquals("Turner", users.get(0).getLastname());
Long usersCount = JPAUtils.queryEntitiesCount(em, User.class, q, (p, cb, r) -> cb.and(p, cb.equal(r.get("firstname"), "Antonio")));
Assert.assertNotNull(usersCount);
Assert.assertEquals(1, usersCount.longValue());
}
use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.
the class JPAUtilsCriteriaFilterTest method testQueryWithoutCriteriaFilter.
@Test
public void testQueryWithoutCriteriaFilter() {
List<User> users = JPAUtils.queryEntities(em, User.class, new QueryParameters());
Assert.assertNotNull(users);
Assert.assertEquals(100, users.size());
}
use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.
the class JPAUtilsFieldsTest method testIdParameter.
@Test
public void testIdParameter() {
QueryParameters q = new QueryParameters();
q.getFields().add("id");
List<User> users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(100, users.size());
Assert.assertNotNull(users.get(0).getId());
Assert.assertNull(users.get(0).getFirstname());
Assert.assertNotNull(users.get(99).getId());
Assert.assertNull(users.get(99).getFirstname());
}
Aggregations