本文整理汇总了Java中org.springframework.data.repository.query.Parameter类的典型用法代码示例。如果您正苦于以下问题:Java Parameter类的具体用法?Java Parameter怎么用?Java Parameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parameter类属于org.springframework.data.repository.query包,在下文中一共展示了Parameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
@Override
public Object execute(Object[] parameters) {
NamedParameterJdbcOperations jdbcTemplate = BeanFactoryUtils.getBeanByNameOrType(beanFactory,
configuration.getOperationsBeanName(), NamedParameterJdbcOperations.class);
Map<String, Object> paramMap = new HashMap<>();
for (int i = 0; i < parameters.length; i++) {
Parameter param = queryMethod.getParameters().getParameter(i);
paramMap.put(param.getName(), convertValue(parameters[i], param.getType()));
}
Class<?> resultType = queryMethod.getReturnedObjectType();
if (queryMethod.isModifyingQuery()) {
return jdbcTemplate.update(getQuery(), paramMap);
} else {
return jdbcTemplate.query(getQuery(), paramMap, getRowMapper(this.queryMethod, resultType));
}
}
示例2: canBindParameter
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
@Override
protected boolean canBindParameter(Parameter parameter) {
List<StringQuery.ParameterBinding> parameterBindings = query.getParameterBindings();
// if no parameter bindings are present, we simply rely on the check in super.
if (parameterBindings.isEmpty()) {
return super.canBindParameter(parameter);
}
// otherwise determine whether there are any non expression parameters left to be bound.
int expressionParameterCount = 0;
for (StringQuery.ParameterBinding binding : parameterBindings) {
if (binding.isExpression()) {
expressionParameterCount++;
}
}
boolean allParametersAreUsedInExpressions = parameterBindings.size() - expressionParameterCount == 0;
// if all parameters are used in expressions, then we can skip their bindings now, since they'll get bound later.
return !allParametersAreUsedInExpressions && super.canBindParameter(parameter);
}
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:25,代码来源:SpelExpressionStringQueryParameterBinder.java
示例3: getBindingFor
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
/**
* Finds the {@link LikeParameterBinding} to be applied before binding a parameter value to the query.
*
* @param ebeanQuery must not be {@literal null}.
* @param position
* @param parameter must not be {@literal null}.
* @return the {@link ParameterBinding} for the given parameters or {@literal null} if none available.
*/
private ParameterBinding getBindingFor(Object ebeanQuery, int position, Parameter parameter) {
Assert.notNull(ebeanQuery, "Query must not be null!");
Assert.notNull(parameter, "Parameter must not be null!");
if (parameter.isNamedParameter()) {
return query.getBindingFor(
Optional.ofNullable(parameter.getName()).orElseThrow(() -> new IllegalArgumentException("Parameter needs to be named!")).get());
}
try {
return query.getBindingFor(position);
} catch (IllegalArgumentException ex) {
// We should actually reject parameters unavailable, but as EclipseLink doesn't implement ….getParameter(int) for
// native queries correctly we need to fall back to an indexed parameter
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427892
return new ParameterBinding(position);
}
}
示例4: bind
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
/**
* Binds the parameters to the given {@link Query}.
*
* @param query must not be {@literal null}.
* @return
*/
public Object bind(Object query) {
Assert.notNull(query, "Query must not be null!");
int bindableParameterIndex = 0;
int queryParameterPosition = 1;
for (Parameter parameter : parameters) {
if (canBindParameter(parameter)) {
Object value = accessor.getBindableValue(bindableParameterIndex);
bind(query, parameter, value, queryParameterPosition++);
bindableParameterIndex++;
}
}
return query;
}
示例5: getParams
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
private Map<String, Object> getParams(Object[] values) {
JpaParameters parameters = getQueryMethod().getParameters();
//gen model
Map<String, Object> params = new HashMap<String, Object>();
for (int i = 0; i < parameters.getNumberOfParameters(); i++) {
Object value = values[i];
Parameter parameter = parameters.getParameter(i);
if (value != null && canBindParameter(parameter)) {
if (!QueryBuilder.isValidValue(value)) {
continue;
}
Class<?> clz = value.getClass();
if (clz.isPrimitive() || String.class.isAssignableFrom(clz) || Number.class.isAssignableFrom(clz)
|| clz.isArray() || Collection.class.isAssignableFrom(clz) || clz.isEnum()) {
params.put(parameter.getName(), value);
} else {
params = QueryBuilder.toParams(value);
}
}
}
return params;
}
示例6: buildQuery
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
static String buildQuery(final String rawQuery, Parameters parameters,
Object... parameterValues) {
String replacedRawQuery = rawQuery;
for (Iterator<Parameter> iterator = parameters.iterator(); iterator
.hasNext();) {
Parameter eachParameter = iterator.next();
if (Pageable.class.isAssignableFrom(eachParameter.getType())
|| Sort.class.isAssignableFrom(eachParameter.getType())) {
continue;
}
replacedRawQuery = replaceOneParameterInQuery(replacedRawQuery,
eachParameter, parameterValues[eachParameter.getIndex()]);
}
return replacedRawQuery.trim();
}
示例7: assertParameterNamesInAnnotatedQuery
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
private void assertParameterNamesInAnnotatedQuery(String annotatedQuery) {
if(!StringUtils.hasText(annotatedQuery)) {
return;
}
for(Parameter parameter : getParameters()) {
if(!parameter.isNamedParameter()) {
continue;
}
if(!annotatedQuery.contains(String.format(":%s", parameter.getName()))) {
throw new IllegalStateException(String.format(
"Using named parameters for method %s but parameter '%s' not found in annotated query '%s'!",
method, parameter.getName(), annotatedQuery));
}
}
}
示例8: isPagedQuery
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
/**
* @return whether or not the query method contains a {@link Pageable} parameter in its signature.
*/
public boolean isPagedQuery() {
boolean isPaged = false;
final Iterator<Parameter> it = getParameters().iterator();
while(it.hasNext()) {
final Parameter param = it.next();
if(Pageable.class.isAssignableFrom(param.getType())) {
isPaged = true;
break;
}
}
return isPaged;
}
示例9: next
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
/**
* Builds a new {@link ParameterMetadata} for the given type and name.
*
* @param <T>
* @param part must not be {@literal null}.
* @param type parameter type, must not be {@literal null}.
* @param parameter
* @return
*/
private <T> ParameterMetadata<T> next(Part part, Class<T> type, Parameter parameter) {
Assert.notNull(type, "Type must not be null!");
ParameterMetadata<T> value = new ParameterMetadata<T>(type, parameter.getName().get(), part.getType(),
bindableParameterValues == null ? ParameterMetadata.PLACEHOLDER : bindableParameterValues.next());
expressions.add(value);
return value;
}
示例10: getParameterValues
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
public List<Object> getParameterValues(Method method, MongoParameterAccessor mongoParameterAccessor,
ConvertingParameterAccessor convertingParameterAccessor) {
List<Object> retval = new ArrayList<>();
int numArgs = method.getParameterCount();
for (int i = 0; i < numArgs; i++) {
Parameter param = ((MongoParametersParameterAccessor) mongoParameterAccessor).getParameters().getParameter(i);
if (param.isBindable()) {
retval.add(convertingParameterAccessor.getBindableValue(i));
} else {
LOGGER.debug("{} was unbindable, adding it as an unbindable object", param.getName());
retval.add(new UnbindableObject(param.getName()));
}
}
return retval;
}
示例11: assertParameterNamesInAnnotatedQuery
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
private void assertParameterNamesInAnnotatedQuery() {
String annotatedQuery = getAnnotatedQuery();
if (!QueryUtils.hasNamedParameter(annotatedQuery)) {
return;
}
for (Parameter parameter : getParameters()) {
if (!parameter.isNamedParameter()) {
continue;
}
String paramName=parameter.getName().orElse(null);
if (!annotatedQuery.contains(String.format(":%s", paramName)) && !annotatedQuery.contains(String.format("#%s", paramName))) {
throw new IllegalStateException(String.format("Using named parameters for method %s but parameter '%s' not found in annotated query '%s'!", method, parameter.getName(), annotatedQuery));
}
}
}
示例12: prepareRearrange
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
/**
* <P>
* Determine if the arguments to the method need reordered.
* </P>
* <P>
* For searches such as {@code findBySomethingNotNull} there may be more parts than parameters needed to be bound to
* them.
* </P>
*
* @param partTree Query parts
* @param bindableParameters Parameters expected
*/
@SuppressWarnings("unchecked")
private void prepareRearrange(final PartTree partTree, final Parameters<?, ?> bindableParameters) {
this.isRearrangeRequired = false;
if (partTree == null || bindableParameters == null) {
return;
}
List<String> queryParams = new ArrayList<>();
List<String> methodParams = new ArrayList<>();
Iterator<Part> partTreeIterator = partTree.getParts().iterator();
while (partTreeIterator.hasNext()) {
Part part = partTreeIterator.next();
queryParams.add(part.getProperty().getSegment());
}
Iterator<Parameter> bindableParameterIterator = (Iterator<Parameter>) bindableParameters.iterator();
while (bindableParameterIterator.hasNext()) {
Parameter parameter = bindableParameterIterator.next();
methodParams.add(parameter.getName());
}
this.rearrangeIndex = new int[queryParams.size()];
String[] paramsExpected = queryParams.toArray(new String[queryParams.size()]);
String[] paramsProvided = methodParams.toArray(new String[methodParams.size()]);
for (int i = 0; i < this.rearrangeIndex.length; i++) {
this.rearrangeIndex[i] = i;
for (int j = 0; j < paramsProvided.length; j++) {
if (paramsProvided[j] != null && paramsProvided[j].equals(paramsExpected[i])) {
this.rearrangeIndex[i] = j;
this.isRearrangeRequired = true;
}
}
}
}
示例13: hasNamedParameter
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
public static boolean hasNamedParameter(SimpleDbQueryMethod queryMethod) {
for (Parameter param : queryMethod.getParameters()) {
if (param.isNamedParameter()) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}
示例14: validateBindParametersTypes
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
/**
* Supported types: primitives & core java types (Date, primitive arrays,
* primitive wrappers)
*/
public static void validateBindParametersTypes(Parameters parameters) {
final Iterator<Parameter> it = parameters.iterator();
while (it.hasNext()) {
final Parameter param = it.next();
final Class<?> paramType = param.getType();
if (!(param.isSpecialParameter() || SupportedCoreTypes
.isSupported(paramType))) {
throw (new IllegalArgumentException("Type " + paramType
+ " not supported as an annotated query parameter!"));
}
}
}
示例15: getMockParameter
import org.springframework.data.repository.query.Parameter; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private Parameter getMockParameter(String placeHolder, Integer idx, Class clazz) {
Parameter mockParameter = Mockito.mock(Parameter.class);
Mockito.when(mockParameter.getPlaceholder()).thenReturn(placeHolder);
Mockito.when(mockParameter.isNamedParameter()).thenReturn(Boolean.TRUE);
Mockito.when(mockParameter.getIndex()).thenReturn(idx);
Mockito.when(mockParameter.getType()).thenReturn(clazz);
Mockito.when(mockParameter.isSpecialParameter()).thenReturn(TYPES.contains(clazz));
return mockParameter;
}