本文整理汇总了Java中org.springframework.data.repository.query.Parameter.isNamedParameter方法的典型用法代码示例。如果您正苦于以下问题:Java Parameter.isNamedParameter方法的具体用法?Java Parameter.isNamedParameter怎么用?Java Parameter.isNamedParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.repository.query.Parameter
的用法示例。
在下文中一共展示了Parameter.isNamedParameter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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));
}
}
}
示例3: 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));
}
}
}
示例4: 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;
}
示例5: replaceOneParameterInQuery
import org.springframework.data.repository.query.Parameter; //导入方法依赖的package包/类
static String replaceOneParameterInQuery(String rawQuery,
Parameter parameter, Object parameterValue) {
final String bindEndCharacter = "\\b";
String namedParameter;
if (parameter.isNamedParameter()) {
namedParameter = parameter.getPlaceholder() + bindEndCharacter;
} else {
namedParameter = "\\?";
}
Assert.isTrue(rawQuery.matches("(.*)(" + namedParameter + ")(.*)"));
// String rawQuery = aRawQuery;
// if (isInOperation(rawQuery, namedParameter)) {
// String replacedValue = createInOperatorStatement(parameterValue);
// rawQuery = rawQuery.replaceFirst(namedParameter, replacedValue);
// } else {
// // handle LIKE queries & quoting together
// String encodedValue = SimpleDBAttributeConverter.encode(parameterValue);
// StringBuilder namedParamBuilder = new StringBuilder();
// StringBuilder paramValueBuilder = new StringBuilder();
// Pattern likeOperatorPattern = Pattern.compile("(%?)" + namedParameter + "(%?)");
// Matcher m = likeOperatorPattern.matcher(rawQuery);
// if (m.find()) {
// paramValueBuilder.append(SINGLE_QUOTE);
// if (!m.group(1).isEmpty()) {
// namedParamBuilder.append("%");
// paramValueBuilder.append("%");
// }
// namedParamBuilder.append(namedParameter);
// paramValueBuilder.append(encodedValue);
// if (!m.group(2).isEmpty()) {
// namedParamBuilder.append("%");
// paramValueBuilder.append("%");
// }
// paramValueBuilder.append(SINGLE_QUOTE);
// rawQuery = rawQuery.replaceFirst(namedParamBuilder.toString(), paramValueBuilder.toString());
// }
// }
return replaceOneParameterInQuery(rawQuery, namedParameter, parameterValue);
}