use of com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException in project lynx by TFaga.
the class JPAUtils method createEntityFromTuple.
// /// Private helper methods
private static <T> List<T> createEntityFromTuple(List<Tuple> tuples, Class<T> entity) {
List<T> entities = new ArrayList<>();
for (Tuple t : tuples) {
T el;
try {
el = entity.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new AssertionError();
}
for (TupleElement<?> te : t.getElements()) {
Object o = t.get(te);
try {
Field f = getFieldFromEntity(entity, te.getAlias());
f.setAccessible(true);
f.set(el, o);
} catch (NoSuchFieldException | IllegalAccessException e1) {
throw new NoSuchEntityFieldException(e1.getMessage(), te.getAlias(), entity.getSimpleName());
}
}
entities.add(el);
}
return entities;
}
use of com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException 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.exceptions.NoSuchEntityFieldException in project lynx by TFaga.
the class JPAUtilsOrderTest method testNonExistentColumn.
@Test
public void testNonExistentColumn() {
QueryOrder qo = new QueryOrder();
qo.setField("lstnm");
qo.setOrder(OrderDirection.DESC);
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("lstnm", e.getField());
}
}
use of com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException in project lynx by TFaga.
the class JPAUtilsFiltersTest method testNonExistingField.
@Test
public void testNonExistingField() {
QueryFilter qf = new QueryFilter();
qf.setField("asdas");
qf.setOperation(FilterOperation.EQ);
qf.setValue("test");
QueryParameters q = new QueryParameters();
q.getFilters().add(qf);
try {
JPAUtils.queryEntities(em, User.class, q);
Assert.fail("No exception was thrown");
} catch (NoSuchEntityFieldException e) {
Assert.assertEquals("asdas", e.getField());
}
}
use of com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException in project lynx by TFaga.
the class JPAUtilsFiltersTest method testNullField.
@Test
public void testNullField() {
QueryFilter qf = new QueryFilter();
qf.setOperation(FilterOperation.NEQ);
qf.setValue("test");
QueryParameters q = new QueryParameters();
q.getFilters().add(qf);
try {
JPAUtils.queryEntities(em, User.class, q);
Assert.fail("No exception was thrown");
} catch (NoSuchEntityFieldException e) {
Assert.assertEquals(null, e.getField());
}
}
Aggregations