Search in sources :

Example 6 with QueryFilter

use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.

the class JPAUtilsFiltersTest method testOneToManyRelationMultiple.

@Test
public void testOneToManyRelationMultiple() {
    QueryFilter qf = new QueryFilter();
    qf.setField("projects.name");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("Orange");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(3, users.size());
    qf = new QueryFilter();
    qf.setField("projects.name");
    qf.setOperation(FilterOperation.IN);
    qf.getValues().add("Maroon");
    qf.getValues().add("Orange");
    q = new QueryParameters();
    q.getFilters().add(qf);
    users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(9, users.size());
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 7 with QueryFilter

use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.

the class JPAUtilsFiltersTest method testNinFilter.

@Test
public void testNinFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("firstname");
    qf.setOperation(FilterOperation.NIN);
    qf.getValues().add("Bruce");
    qf.getValues().add("Karen");
    qf.getValues().add("Sandra");
    qf.getValues().add("Laura");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(91, users.size());
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 8 with QueryFilter

use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.

the class JPAUtilsFiltersTest method testOneToManyRelation.

@Test
public void testOneToManyRelation() {
    QueryFilter qf = new QueryFilter();
    qf.setField("projects.id");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("10");
    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());
    qf = new QueryFilter();
    qf.setField("projects.name");
    qf.setOperation(FilterOperation.NIN);
    qf.getValues().add("Green");
    qf.getValues().add("Violet");
    q = new QueryParameters();
    q.getFilters().add(qf);
    users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(55, users.size());
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 9 with QueryFilter

use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.

the class JPAUtilsFiltersTest method testBooleanFilter.

@Test
public void testBooleanFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("confirmed");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("true");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(55, users.size());
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 10 with QueryFilter

use of com.github.tfaga.lynx.beans.QueryFilter in project lynx by TFaga.

the class JPAUtilsFiltersTest method testBooleanInFilter.

@Test
public void testBooleanInFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("confirmed");
    qf.setOperation(FilterOperation.IN);
    qf.getValues().add("False");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(45, users.size());
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Aggregations

QueryFilter (com.github.tfaga.lynx.beans.QueryFilter)49 Test (org.junit.Test)47 QueryParameters (com.github.tfaga.lynx.beans.QueryParameters)44 User (com.github.tfaga.lynx.test.entities.User)28 Project (com.github.tfaga.lynx.test.entities.Project)10 Date (java.util.Date)6 NoSuchEntityFieldException (com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException)3 OrderDirection (com.github.tfaga.lynx.enums.OrderDirection)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeParseException (java.time.format.DateTimeParseException)2 java.util (java.util)2 Logger (java.util.logging.Logger)2 Collectors (java.util.stream.Collectors)2 CriteriaField (com.github.tfaga.lynx.beans.CriteriaField)1 CriteriaWhereQuery (com.github.tfaga.lynx.beans.CriteriaWhereQuery)1 QueryOrder (com.github.tfaga.lynx.beans.QueryOrder)1 FilterOperation (com.github.tfaga.lynx.enums.FilterOperation)1 QueryFormatError (com.github.tfaga.lynx.enums.QueryFormatError)1 InvalidEntityFieldException (com.github.tfaga.lynx.exceptions.InvalidEntityFieldException)1 InvalidFieldValueException (com.github.tfaga.lynx.exceptions.InvalidFieldValueException)1