use of org.springframework.data.repository.query.Parameter in project spring-data-jdbc by spring-projects.
the class StringBasedJdbcQuery method bindParameters.
private MapSqlParameterSource bindParameters(RelationalParameterAccessor accessor) {
MapSqlParameterSource parameters = new MapSqlParameterSource();
Parameters<?, ?> bindableParameters = accessor.getBindableParameters();
for (Parameter bindableParameter : bindableParameters) {
convertAndAddParameter(parameters, bindableParameter, accessor.getBindableValue(bindableParameter.getIndex()));
}
return parameters;
}
use of org.springframework.data.repository.query.Parameter in project spring-cloud-gcp by spring-cloud.
the class SpannerQueryLookupStrategyTests method resolveSqlQueryTest.
@Test
public void resolveSqlQueryTest() {
String queryName = "fakeNamedQueryName";
String query = "fake query";
when(this.queryMethod.getNamedQueryName()).thenReturn(queryName);
NamedQueries namedQueries = mock(NamedQueries.class);
Parameters parameters = mock(Parameters.class);
// @formatter:off
Mockito.<Parameters>when(this.queryMethod.getParameters()).thenReturn(parameters);
// @formatter:off
when(parameters.getNumberOfParameters()).thenReturn(1);
when(parameters.getParameter(anyInt())).thenAnswer((invocation) -> {
Parameter param = mock(Parameter.class);
when(param.getName()).thenReturn(Optional.of("tag"));
// @formatter:off
Mockito.<Class>when(param.getType()).thenReturn(Object.class);
// @formatter:on
return param;
});
when(namedQueries.hasQuery(eq(queryName))).thenReturn(true);
when(namedQueries.getQuery(eq(queryName))).thenReturn(query);
this.spannerQueryLookupStrategy.resolveQuery(null, null, null, namedQueries);
verify(this.spannerQueryLookupStrategy, times(1)).createSqlSpannerQuery(eq(Object.class), same(this.queryMethod), eq(query), eq(false));
}
use of org.springframework.data.repository.query.Parameter in project spring-cloud-gcp by spring-cloud.
the class GqlDatastoreQueryTests method buildParameters.
private Parameters buildParameters(Object[] params, String[] paramNames) {
Parameters parameters = mock(Parameters.class);
Mockito.<Parameters>when(this.queryMethod.getParameters()).thenReturn(parameters);
when(parameters.getNumberOfParameters()).thenReturn(paramNames.length);
when(parameters.getParameter(anyInt())).thenAnswer((invocation) -> {
int index = invocation.getArgument(0);
Parameter param = mock(Parameter.class);
when(param.getName()).thenReturn(paramNames[index] == null ? Optional.empty() : Optional.of(paramNames[index]));
Mockito.<Class>when(param.getType()).thenReturn(params[index].getClass());
return param;
});
return parameters;
}
use of org.springframework.data.repository.query.Parameter 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