use of com.github.tfaga.lynx.beans.QueryOrder in project lynx by TFaga.
the class QueryStringBuilder method buildOrder.
private QueryOrder buildOrder(String key, String value) {
log.finest("Building order string: " + value);
if (value == null || value.isEmpty())
return null;
QueryOrder o = new QueryOrder();
String[] pair = value.split("(\\s|\\+)");
if (pair[0].isEmpty()) {
String msg = "Value for '" + key + "' is malformed: '" + value + "'";
log.finest(msg);
throw new QueryFormatException(msg, key, QueryFormatError.MALFORMED);
}
o.setField(pair[0]);
if (pair.length > 1) {
try {
o.setOrder(OrderDirection.valueOf(pair[1].toUpperCase()));
} catch (IllegalArgumentException e) {
String msg = "Constant in '" + key + "' does not exist: '" + value + "'";
log.finest(msg);
throw new QueryFormatException(msg, key, QueryFormatError.NO_SUCH_CONSTANT);
}
} else {
o.setOrder(OrderDirection.ASC);
}
return o;
}
use of com.github.tfaga.lynx.beans.QueryOrder in project lynx by TFaga.
the class JPAUtilsOrderTest method testMultipleOrders.
@Test
public void testMultipleOrders() {
QueryParameters q = new QueryParameters();
QueryOrder qo = new QueryOrder();
qo.setField("role");
qo.setOrder(OrderDirection.DESC);
q.getOrder().add(qo);
qo = new QueryOrder();
qo.setField("lastname");
qo.setOrder(OrderDirection.ASC);
q.getOrder().add(qo);
qo = new QueryOrder();
qo.setField("firstname");
qo.setOrder(OrderDirection.DESC);
q.getOrder().add(qo);
List<User> users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(100, users.size());
Assert.assertNotNull(users.get(0).getFirstname());
Assert.assertNotNull(users.get(0).getLastname());
Assert.assertEquals("Larry", users.get(0).getFirstname());
Assert.assertEquals("Bailey", users.get(0).getLastname());
Assert.assertNotNull(users.get(99).getFirstname());
Assert.assertNotNull(users.get(99).getLastname());
Assert.assertEquals("Bonnie", users.get(99).getFirstname());
Assert.assertEquals("Willis", users.get(99).getLastname());
}
use of com.github.tfaga.lynx.beans.QueryOrder in project lynx by TFaga.
the class JPAUtilsOrderTest method testCaseSensitiveField.
@Test
public void testCaseSensitiveField() {
QueryOrder qo = new QueryOrder();
qo.setField("firsTNAmE");
qo.setOrder(OrderDirection.ASC);
QueryParameters q = new QueryParameters();
q.getOrder().add(qo);
try {
JPAUtils.queryEntities(em, User.class, q);
Assert.fail("No exception was thrown");
} catch (NoSuchEntityFieldException e) {
Assert.assertEquals("firsTNAmE", e.getField());
}
}
use of com.github.tfaga.lynx.beans.QueryOrder in project lynx by TFaga.
the class JPAUtilsOrderTest method testOneToMany.
@Test(expected = InvalidEntityFieldException.class)
public void testOneToMany() {
QueryOrder qo = new QueryOrder();
qo.setField("projects.name");
QueryParameters q = new QueryParameters();
q.getOrder().add(qo);
JPAUtils.queryEntities(em, User.class, q);
Assert.fail("No exception was thrown");
}
use of com.github.tfaga.lynx.beans.QueryOrder in project lynx by TFaga.
the class JPAUtilsOrderTest method testSingleOrder.
@Test
public void testSingleOrder() {
QueryOrder qo = new QueryOrder();
qo.setField("firstname");
qo.setOrder(OrderDirection.ASC);
QueryParameters q = new QueryParameters();
q.getOrder().add(qo);
List<User> users = JPAUtils.queryEntities(em, User.class, q);
Assert.assertNotNull(users);
Assert.assertEquals(100, users.size());
Assert.assertNotNull(users.get(0).getFirstname());
Assert.assertEquals("Amanda", users.get(0).getFirstname());
Assert.assertNotNull(users.get(99).getFirstname());
Assert.assertEquals("Victor", users.get(99).getFirstname());
}
Aggregations