Search in sources :

Example 1 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.

the class SqlFilterConverterTest method checkMultivaluedGeFilters.

@Test
public void checkMultivaluedGeFilters() throws SearchException {
    // GE -- String
    Filter filterGe1 = Filter.createGreaterOrEqualFilter("uid", "test").multiValued();
    ConvertedExpression expressionGe1 = simpleConverter.convertToSqlFilter(filterGe1, null, null);
    String queryGe1 = toSelectSQL(expressionGe1);
    assertEquals(queryGe1, "select doc.`*` from `table` as doc where doc.uid->'$.v[0]' >= '[\"test\"]'");
    // GE -- Integer
    Filter filterGe2 = Filter.createGreaterOrEqualFilter("age", 23).multiValued();
    ConvertedExpression expressionGe2 = simpleConverter.convertToSqlFilter(filterGe2, null, null);
    String queryGe2 = toSelectSQL(expressionGe2);
    assertEquals(queryGe2, "select doc.`*` from `table` as doc where doc.age->'$.v[0]' >= '[23]'");
    // GE -- Long
    Filter filterGe3 = Filter.createGreaterOrEqualFilter("age", 23L).multiValued();
    ConvertedExpression expressionGe3 = simpleConverter.convertToSqlFilter(filterGe3, null, null);
    String queryGe3 = toSelectSQL(expressionGe3);
    assertEquals(queryGe3, "select doc.`*` from `table` as doc where doc.age->'$.v[0]' >= '[23]'");
    // GE -- Date
    Filter filterGe4 = Filter.createGreaterOrEqualFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued();
    ConvertedExpression expressionGe4 = simpleConverter.convertToSqlFilter(filterGe4, null, null);
    String queryGe4 = toSelectSQL(expressionGe4);
    assertEquals(queryGe4, "select doc.`*` from `table` as doc where doc.added->'$.v[0]' >= '[\"2020-12-16T14:58:18.398\"]'");
    // GE -- Date
    Filter filterGe5 = Filter.createGreaterOrEqualFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued(3);
    ConvertedExpression expressionGe5 = simpleConverter.convertToSqlFilter(filterGe5, null, null);
    String queryGe5 = toSelectSQL(expressionGe5);
    assertEquals(queryGe5, "select doc.`*` from `table` as doc where doc.added->'$.v[0]' >= '[\"2020-12-16T14:58:18.398\"]' or doc.added->'$.v[1]' >= '[\"2020-12-16T14:58:18.398\"]' or doc.added->'$.v[2]' >= '[\"2020-12-16T14:58:18.398\"]'");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 2 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.

the class SqlFilterConverterTest method checkAndFilters.

@Test
public void checkAndFilters() throws SearchException {
    Filter filterEq1 = Filter.createEqualityFilter("uid", "test");
    Filter filterPresence1 = Filter.createPresenceFilter("mail");
    Filter filterLe1 = Filter.createLessOrEqualFilter("age", 23);
    Filter filterAnd1 = Filter.createANDFilter(filterPresence1, filterEq1, filterLe1);
    ConvertedExpression expressionAnd1 = simpleConverter.convertToSqlFilter(filterAnd1, null, null);
    String queryAnd1 = toSelectSQL(expressionAnd1);
    assertEquals(queryAnd1, "select doc.`*` from `table` as doc where doc.mail is not null and doc.uid = 'test' and doc.age <= 23");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 3 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.

the class SqlFilterConverterTest method checkMultivaluedSubFilters.

@Test
public void checkMultivaluedSubFilters() throws SearchException {
    Filter filterSub1 = Filter.createSubstringFilter("uid", null, new String[] { "test" }, null).multiValued();
    ConvertedExpression expressionSub1 = simpleConverter.convertToSqlFilter(filterSub1, null, null);
    String querySub1 = toSelectSQL(expressionSub1);
    assertEquals(querySub1, "select doc.`*` from `table` as doc where doc.uid->'$.v[0]' like '%test%'");
    Filter filterSub2 = Filter.createSubstringFilter("uid", "a", new String[] { "test" }, null).multiValued();
    ConvertedExpression expressionSub2 = simpleConverter.convertToSqlFilter(filterSub2, null, null);
    String querySub2 = toSelectSQL(expressionSub2);
    assertEquals(querySub2, "select doc.`*` from `table` as doc where doc.uid->'$.v[0]' like 'a%test%'");
    Filter filterSub3 = Filter.createSubstringFilter("uid", null, new String[] { "test" }, "z").multiValued();
    ConvertedExpression expressionSub3 = simpleConverter.convertToSqlFilter(filterSub3, null, null);
    String querySub3 = toSelectSQL(expressionSub3);
    assertEquals(querySub3, "select doc.`*` from `table` as doc where doc.uid->'$.v[0]' like '%test%z'");
    Filter filterSub4 = Filter.createSubstringFilter("uid", null, new String[] { "test" }, "z").multiValued(3);
    ConvertedExpression expressionSub4 = simpleConverter.convertToSqlFilter(filterSub4, null, null);
    String querySub4 = toSelectSQL(expressionSub4);
    assertEquals(querySub4, "select doc.`*` from `table` as doc where doc.uid->'$.v[0]' like '%test%z' or doc.uid->'$.v[1]' like '%test%z' or doc.uid->'$.v[2]' like '%test%z'");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 4 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.

the class SqlFilterConverterTest method checkMultivaluedEqFilters.

@Test
public void checkMultivaluedEqFilters() throws SearchException {
    // EQ -- String
    Filter filterEq1 = Filter.createEqualityFilter("uid", "test").multiValued();
    ConvertedExpression expressionEq1 = simpleConverter.convertToSqlFilter(filterEq1, null, null);
    String queryEq1 = toSelectSQL(expressionEq1);
    assertEquals(queryEq1, "select doc.`*` from `table` as doc where JSON_CONTAINS(doc.uid->'$.v', CAST('[\"test\"]' AS JSON))");
    // EQ -- Integer
    Filter filterEq2 = Filter.createEqualityFilter("age", 23).multiValued();
    ConvertedExpression expressionEq2 = simpleConverter.convertToSqlFilter(filterEq2, null, null);
    String queryEq2 = toSelectSQL(expressionEq2);
    assertEquals(queryEq2, "select doc.`*` from `table` as doc where JSON_CONTAINS(doc.age->'$.v', CAST('[23]' AS JSON))");
    // EQ -- Long
    Filter filterEq3 = Filter.createEqualityFilter("age", 23L).multiValued();
    ConvertedExpression expressionEq3 = simpleConverter.convertToSqlFilter(filterEq3, null, null);
    String queryEq3 = toSelectSQL(expressionEq3);
    assertEquals(queryEq3, "select doc.`*` from `table` as doc where JSON_CONTAINS(doc.age->'$.v', CAST('[23]' AS JSON))");
    // EQ -- Date
    Filter filterEq4 = Filter.createEqualityFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued();
    ConvertedExpression expressionEq4 = simpleConverter.convertToSqlFilter(filterEq4, null, null);
    String queryEq4 = toSelectSQL(expressionEq4);
    assertEquals(queryEq4, "select doc.`*` from `table` as doc where JSON_CONTAINS(doc.added->'$.v', CAST('[\"2020-12-16T14:58:18.398\"]' AS JSON))");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 5 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.

the class SqlFilterConverterTest method checkLowerFilters.

@Test
public void checkLowerFilters() throws SearchException {
    Filter userUidFilter1 = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), "test");
    ConvertedExpression expressionUserUid1 = simpleConverter.convertToSqlFilter(userUidFilter1, null, null);
    String queryUserUid1 = toSelectSQL(expressionUserUid1);
    assertEquals(queryUserUid1, "select doc.`*` from `table` as doc where lower(doc.uid) = 'test'");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Aggregations

ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)25 Filter (io.jans.orm.search.filter.Filter)24 Test (org.testng.annotations.Test)19 SearchException (io.jans.orm.exception.operation.SearchException)5 AuthenticationException (io.jans.orm.exception.AuthenticationException)4 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)4 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)4 MappingException (io.jans.orm.exception.MappingException)4 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)4 DateTimeParseException (java.time.format.DateTimeParseException)4 ParsedKey (io.jans.orm.impl.model.ParsedKey)3 EntryData (io.jans.orm.model.EntryData)3 Expression (com.querydsl.core.types.Expression)1 OrderSpecifier (com.querydsl.core.types.OrderSpecifier)1 Predicate (com.querydsl.core.types.Predicate)1 AttributeEnum (io.jans.orm.annotation.AttributeEnum)1 FilterType (io.jans.orm.search.filter.FilterType)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1