use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.
the class SqlFilterConverterTest method checkMultivaluedSubWithLowerFilters.
@Test
public void checkMultivaluedSubWithLowerFilters() throws SearchException {
Filter filterSub1 = Filter.createSubstringFilter(Filter.createLowercaseFilter("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 lower(doc.uid)->'$.v[0]' like '%test%'");
Filter filterSub2 = Filter.createSubstringFilter(Filter.createLowercaseFilter("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 lower(doc.uid)->'$.v[0]' like 'a%test%'");
Filter filterSub3 = Filter.createSubstringFilter(Filter.createLowercaseFilter("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 lower(doc.uid)->'$.v[0]' like '%test%z'");
Filter filterSub4 = Filter.createSubstringFilter(Filter.createLowercaseFilter("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 lower(doc.uid)->'$.v[0]' like '%test%z' or lower(doc.uid)->'$.v[1]' like '%test%z' or lower(doc.uid)->'$.v[2]' like '%test%z'");
}
use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.
the class SqlFilterConverterTest method checkSubFilters.
@Test
public void checkSubFilters() throws SearchException {
Filter filterSub1 = Filter.createSubstringFilter("uid", null, new String[] { "test" }, null);
ConvertedExpression expressionSub1 = simpleConverter.convertToSqlFilter(filterSub1, null, null);
String querySub1 = toSelectSQL(expressionSub1);
assertEquals(querySub1, "select doc.`*` from `table` as doc where doc.uid like '%test%'");
Filter filterSub2 = Filter.createSubstringFilter("uid", "a", new String[] { "test" }, null);
ConvertedExpression expressionSub2 = simpleConverter.convertToSqlFilter(filterSub2, null, null);
String querySub2 = toSelectSQL(expressionSub2);
assertEquals(querySub2, "select doc.`*` from `table` as doc where doc.uid like 'a%test%'");
Filter filterSub3 = Filter.createSubstringFilter("uid", null, new String[] { "test" }, "z");
ConvertedExpression expressionSub3 = simpleConverter.convertToSqlFilter(filterSub3, null, null);
String querySub3 = toSelectSQL(expressionSub3);
assertEquals(querySub3, "select doc.`*` from `table` as doc where doc.uid like '%test%z'");
}
use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.
the class SqlFilterConverterTest method checkOrJoinFilters.
@Test
public void checkOrJoinFilters() throws SearchException {
// And with join
Filter filterEq1 = Filter.createEqualityFilter("uid", "test");
Filter filterEq2 = Filter.createEqualityFilter("uid", "test2");
Filter filterEq3 = Filter.createEqualityFilter("uid", "test3");
Filter filterOr1 = Filter.createORFilter(filterEq1, filterEq2, filterEq3).multiValued(false);
ConvertedExpression expressionOr1 = simpleConverter.convertToSqlFilter(filterOr1, null, null);
String queryOr1 = toSelectSQL(expressionOr1);
assertEquals(queryOr1, "select doc.`*` from `table` as doc where doc.uid in ('test', 'test2', 'test3')");
Filter filterOr2 = Filter.createORFilter(filterEq1, filterEq2, filterEq3);
ConvertedExpression expressionOr2 = simpleConverter.convertToSqlFilter(filterOr2, null, null);
String queryOr2 = toSelectSQL(expressionOr2);
assertEquals(queryOr2, "select doc.`*` from `table` as doc where doc.uid = 'test' or doc.uid = 'test2' or doc.uid = 'test3'");
}
use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.
the class SqlFilterConverterTest method checkGeFilters.
@Test
public void checkGeFilters() throws SearchException {
// LE -- String
Filter filterGe1 = Filter.createGreaterOrEqualFilter("uid", "test");
ConvertedExpression expressionGe1 = simpleConverter.convertToSqlFilter(filterGe1, null, null);
String queryGe1 = toSelectSQL(expressionGe1);
assertEquals(queryGe1, "select doc.`*` from `table` as doc where doc.uid >= 'test'");
// LE -- Integer
Filter filterGe2 = Filter.createGreaterOrEqualFilter("age", 23);
ConvertedExpression expressionGe2 = simpleConverter.convertToSqlFilter(filterGe2, null, null);
String queryGe2 = toSelectSQL(expressionGe2);
assertEquals(queryGe2, "select doc.`*` from `table` as doc where doc.age >= 23");
// LE -- Long
Filter filterGe3 = Filter.createGreaterOrEqualFilter("age", 23L);
ConvertedExpression expressionGe3 = simpleConverter.convertToSqlFilter(filterGe3, null, null);
String queryGe3 = toSelectSQL(expressionGe3);
assertEquals(queryGe3, "select doc.`*` from `table` as doc where doc.age >= 23");
// LE -- Date
Filter filterGe4 = Filter.createGreaterOrEqualFilter("added", getUtcDateFromMillis(1608130698398L));
ConvertedExpression expressionGe4 = simpleConverter.convertToSqlFilter(filterGe4, null, null);
String queryGe4 = toSelectSQL(expressionGe4);
assertEquals(queryGe4, "select doc.`*` from `table` as doc where doc.added >= '2020-12-16T14:58:18.398'");
}
use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.
the class SqlEntryManager method countEntries.
@Override
public <T> int countEntries(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to find entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ConvertedExpression convertedExpression;
try {
convertedExpression = toSqlFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter));
}
PagedResult<EntryData> searchResult;
try {
searchResult = searchImpl(toSQLKey(baseDN).getKey(), objectClasses[0], convertedExpression, scope, null, null, null, SearchReturnDataType.COUNT, 0, 0, 0);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to calculate the number of entries with baseDN: '%s', filter: '%s'", baseDN, searchFilter), ex);
}
return searchResult.getTotalEntriesCount();
}
Aggregations