use of org.springframework.data.repository.query.Parameters in project spring-cloud-gcp by spring-cloud.
the class DatastoreRepositoryFactory method delegateContextProvider.
private QueryMethodEvaluationContextProvider delegateContextProvider(QueryMethodEvaluationContextProvider evaluationContextProvider) {
return new QueryMethodEvaluationContextProvider() {
@Override
public <T extends Parameters<?, ?>> EvaluationContext getEvaluationContext(T parameters, Object[] parameterValues) {
StandardEvaluationContext evaluationContext = (StandardEvaluationContext) evaluationContextProvider.getEvaluationContext(parameters, parameterValues);
evaluationContext.setRootObject(DatastoreRepositoryFactory.this.applicationContext);
evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());
evaluationContext.setBeanResolver(new BeanFactoryResolver(DatastoreRepositoryFactory.this.applicationContext));
return evaluationContext;
}
};
}
use of org.springframework.data.repository.query.Parameters in project spring-cloud-gcp by spring-cloud.
the class PartTreeFirestoreQueryTests method setUpPartTreeFirestoreQuery.
private PartTreeFirestoreQuery setUpPartTreeFirestoreQuery(String methodName) {
Parameters parametersMock = mock(Parameters.class);
when(parametersMock.isEmpty()).thenReturn(true);
when(this.queryMethod.getParameters()).thenReturn(parametersMock);
when(this.queryMethod.getName()).thenReturn(methodName);
ReturnedType returnedType = mock(ReturnedType.class);
when(returnedType.getDomainType()).thenAnswer(invocation -> User.class);
ResultProcessor resultProcessor = mock(ResultProcessor.class);
when(resultProcessor.getReturnedType()).thenReturn(returnedType);
when(this.queryMethod.getResultProcessor()).thenReturn(resultProcessor);
return new PartTreeFirestoreQuery(this.queryMethod, this.firestoreTemplate, new FirestoreMappingContext(), this.classMapper);
}
use of org.springframework.data.repository.query.Parameters in project spring-cloud-gcp by spring-cloud.
the class DatastoreQueryLookupStrategyTests method resolveSqlQueryTest.
@Test
public void resolveSqlQueryTest() {
String queryName = "fakeNamedQueryName";
String query = "fake query";
when(this.queryMethod.getNamedQueryName()).thenReturn(queryName);
Query queryAnnotation = mock(Query.class);
when(this.queryMethod.getQueryAnnotation()).thenReturn(queryAnnotation);
NamedQueries namedQueries = mock(NamedQueries.class);
Parameters parameters = mock(Parameters.class);
Mockito.<Parameters>when(this.queryMethod.getParameters()).thenReturn(parameters);
when(parameters.getNumberOfParameters()).thenReturn(1);
when(parameters.getParameter(anyInt())).thenAnswer((invocation) -> {
Parameter param = mock(Parameter.class);
when(param.getName()).thenReturn(Optional.of("tag"));
Mockito.<Class>when(param.getType()).thenReturn(Object.class);
return param;
});
when(namedQueries.hasQuery(eq(queryName))).thenReturn(true);
when(namedQueries.getQuery(eq(queryName))).thenReturn(query);
this.datastoreQueryLookupStrategy.resolveQuery(null, null, null, namedQueries);
verify(this.datastoreQueryLookupStrategy, times(1)).createGqlDatastoreQuery(eq(Object.class), same(this.queryMethod), eq(query));
}
use of org.springframework.data.repository.query.Parameters in project spring-data-jdbc by spring-projects.
the class JdbcRepositoryQueryUnitTests method setup.
@Before
public void setup() throws NoSuchMethodException {
Parameters parameters = new DefaultParameters(JdbcRepositoryQueryUnitTests.class.getDeclaredMethod("dummyMethod"));
queryMethod = mock(JdbcQueryMethod.class);
when(queryMethod.getParameters()).thenReturn(parameters);
context = mock(JdbcMappingContext.class, RETURNS_DEEP_STUBS);
defaultRowMapper = mock(RowMapper.class);
}
use of org.springframework.data.repository.query.Parameters in project spring-cloud-gcp by spring-cloud.
the class GqlDatastoreQuery method setOriginalParamTags.
private void setOriginalParamTags() {
this.originalParamTags = new ArrayList<>();
Set<String> seen = new HashSet<>();
Parameters parameters = getQueryMethod().getParameters();
for (int i = 0; i < parameters.getNumberOfParameters(); i++) {
Parameter param = parameters.getParameter(i);
if (Pageable.class.isAssignableFrom(param.getType()) || Sort.class.isAssignableFrom(param.getType())) {
continue;
}
Optional<String> paramName = param.getName();
if (!paramName.isPresent()) {
throw new DatastoreDataException("Query method has a parameter without a valid name: " + getQueryMethod().getName());
}
String name = paramName.get();
if (seen.contains(name)) {
throw new DatastoreDataException("More than one param has the same name: " + name);
}
seen.add(name);
this.originalParamTags.add(name);
}
}
Aggregations