use of org.springframework.data.repository.query.parser.PartTree in project spring-data-keyvalue by spring-projects.
the class SpelQueryCreatorUnitTests method createQueryForMethodWithArgs.
private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String methodName, Object... args) throws NoSuchMethodException, SecurityException {
Class<?>[] argTypes = new Class<?>[args.length];
if (!ObjectUtils.isEmpty(args)) {
for (int i = 0; i < args.length; i++) {
argTypes[i] = args[i].getClass();
}
}
Method method = PersonRepository.class.getMethod(methodName, argTypes);
doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(new QueryMethod(method, metadataMock, new SpelAwareProxyProjectionFactory()).getParameters(), args));
KeyValueQuery<SpelExpression> q = creator.createQuery();
q.getCriteria().setEvaluationContext(new StandardEvaluationContext(args));
return q;
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-keyvalue by spring-projects.
the class KeyValuePartTreeQuery method createQuery.
/**
* Create a {@link KeyValueQuery} given {@link ParameterAccessor}.
*
* @param accessor must not be {@literal null}.
* @return the {@link KeyValueQuery}.
*/
public KeyValueQuery<?> createQuery(ParameterAccessor accessor) {
PartTree tree = new PartTree(getQueryMethod().getName(), getQueryMethod().getEntityInformation().getJavaType());
AbstractQueryCreator<? extends KeyValueQuery<?>, ?> queryCreator = queryCreatorFactory.queryCreatorFor(tree, accessor);
KeyValueQuery<?> query = queryCreator.createQuery();
if (tree.isLimiting()) {
query.setRows(tree.getMaxResults());
}
return query;
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method bindsNullValueToContainsClause.
// DATAMONGO-1342
@Test
void bindsNullValueToContainsClause() {
PartTree partTree = new PartTree("emailAddressesContains", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter, new Object[] { null });
Query query = new MongoQueryCreator(partTree, accessor, context).createQuery();
assertThat(query).isEqualTo(query(where("emailAddresses").in((Object) null)));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsLessThanEqualQueryCorrectly.
@Test
void createsLessThanEqualQueryCorrectly() {
PartTree tree = new PartTree("findByAgeLessThanEqual", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, 18), context);
Query reference = query(where("age").lte(18));
assertThat(creator.createQuery()).isEqualTo(reference);
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method betweenShouldAllowSingleRageParameter.
// DATAMONGO-2071
@Test
void betweenShouldAllowSingleRageParameter() {
PartTree tree = new PartTree("findByAgeBetween", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, Range.of(Bound.exclusive(10), Bound.exclusive(11))), context);
assertThat(creator.createQuery()).isEqualTo(query(where("age").gt(10).lt(11)));
}
Aggregations