use of org.springframework.data.repository.query.parser.PartTree in project ignite by apache.
the class IgniteQueryGenerator method generateSql.
/**
* @param mtd Method.
* @param metadata Metadata.
*/
@NotNull
public static IgniteQuery generateSql(Method mtd, RepositoryMetadata metadata) {
PartTree parts = new PartTree(mtd.getName(), metadata.getDomainType());
StringBuilder sql = new StringBuilder();
if (parts.isDelete())
throw new UnsupportedOperationException("DELETE clause is not supported now.");
else {
sql.append("SELECT ");
if (parts.isDistinct())
throw new UnsupportedOperationException("DISTINCT clause in not supported.");
if (parts.isCountProjection())
sql.append("COUNT(1) ");
else
sql.append(" * ");
}
sql.append("FROM ").append(metadata.getDomainType().getSimpleName());
if (parts.iterator().hasNext()) {
sql.append(" WHERE ");
for (PartTree.OrPart orPart : parts) {
sql.append("(");
for (Part part : orPart) {
handleQueryPart(sql, part);
sql.append(" AND ");
}
sql.delete(sql.length() - 5, sql.length());
sql.append(") OR ");
}
sql.delete(sql.length() - 4, sql.length());
}
addSorting(sql, parts.getSort());
if (parts.isLimiting()) {
sql.append(" LIMIT ");
sql.append(parts.getMaxResults().intValue());
}
return new IgniteQuery(sql.toString(), parts.isCountProjection(), getOptions(mtd));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class IndexEnsuringQueryCreationListenerUnitTests method skipsQueryCreationForMethodWithoutPredicate.
// DATAMONGO-1753
@Test
public void skipsQueryCreationForMethodWithoutPredicate() {
PartTree tree = mock(PartTree.class);
when(tree.hasPredicate()).thenReturn(false);
PartTreeMongoQuery query = mock(PartTreeMongoQuery.class, Answers.RETURNS_MOCKS);
when(query.getTree()).thenReturn(tree);
listener.onCreation(query);
verify(provider, times(0)).indexOps(any());
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-keyvalue by spring-projects.
the class SpelQueryEngineUnitTests method createQueryForMethodWithArgs.
private static SpelCriteria createQueryForMethodWithArgs(String methodName, Object... args) throws Exception {
List<Class<?>> types = new ArrayList<>(args.length);
for (Object arg : args) {
types.add(arg.getClass());
}
Method method = PersonRepository.class.getMethod(methodName, types.toArray(new Class<?>[types.size()]));
RepositoryMetadata metadata = mock(RepositoryMetadata.class);
doReturn(method.getReturnType()).when(metadata).getReturnedDomainClass(method);
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(new QueryMethod(method, metadata, new SpelAwareProxyProjectionFactory()).getParameters(), args));
return new SpelCriteria(creator.createQuery().getCriteria(), new StandardEvaluationContext(args));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsTrueClauseCorrectly.
// DATAMONGO-338
@Test
void createsTrueClauseCorrectly() {
PartTree tree = new PartTree("findByActiveTrue", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter), context);
Query query = query(where("active").is(true));
assertThat(creator.createQuery()).isEqualTo(query);
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsAndQueryCorrectly.
// DATAMONGO-469
@Test
void createsAndQueryCorrectly() {
Person person = new Person();
MongoQueryCreator creator = new MongoQueryCreator(new PartTree("findByFirstNameAndFriend", Person.class), getAccessor(converter, "Oliver", person), context);
Query query = creator.createQuery();
assertThat(query).isEqualTo(query(where("firstName").is("Oliver").and("friend").is(person)));
}
Aggregations