• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Parameters类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.data.repository.query.Parameters的典型用法代码示例。如果您正苦于以下问题:Java Parameters类的具体用法?Java Parameters怎么用?Java Parameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Parameters类属于org.springframework.data.repository.query包,在下文中一共展示了Parameters类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: NativeEbeanQuery

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
/**
 * Creates a new {@link NativeEbeanQuery} encapsulating the query annotated on the given {@link EbeanQueryMethod}.
 *
 * @param method                    must not be {@literal null}.
 * @param ebeanServer               must not be {@literal null}.
 * @param queryString               must not be {@literal null} or empty.
 * @param evaluationContextProvider
 */
public NativeEbeanQuery(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString,
                        EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) {

  super(method, ebeanServer, queryString, evaluationContextProvider, parser);

  Parameters<?, ?> parameters = method.getParameters();
  boolean hasPagingOrSortingParameter = parameters.hasPageableParameter() || parameters.hasSortParameter();
  boolean containsPageableOrSortInQueryExpression = queryString.contains("#pageable")
      || queryString.contains("#sort");

  if (hasPagingOrSortingParameter && !containsPageableOrSortInQueryExpression) {
    throw new InvalidEbeanQueryMethodException(
        "Cannot use native queries with dynamic sorting and/or pagination in method " + method);
  }
}
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:24,代码来源:NativeEbeanQuery.java


示例2: bindAndPrepare

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
private Object bindAndPrepare(Object query, Parameters<?, ?> parameters) {

        Object result = bind(query);

        if (!parameters.hasPageableParameter()) {
            return result;
        }
        if (query instanceof Query) {
            Query ormQuery = (Query) query;
            ormQuery.setFirstRow((int) getPageable().getOffset());
            ormQuery.setMaxRows(getPageable().getPageSize());
        } else if (query instanceof SqlQuery) {
            SqlQuery sqlQuery = (SqlQuery) query;
            sqlQuery.setFirstRow((int) getPageable().getOffset());
            sqlQuery.setMaxRows(getPageable().getPageSize());
        }

        return result;
    }
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:20,代码来源:ParameterBinder.java


示例3: NativeEbeanUpdate

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
/**
 * Creates a new {@link NativeEbeanUpdate} encapsulating the query annotated on the given {@link EbeanQueryMethod}.
 *
 * @param method                    must not be {@literal null}.
 * @param ebeanServer               must not be {@literal null}.
 * @param queryString               must not be {@literal null} or empty.
 * @param evaluationContextProvider
 */
public NativeEbeanUpdate(EbeanQueryMethod method, EbeanServer ebeanServer, String queryString,
                         EvaluationContextProvider evaluationContextProvider, SpelExpressionParser parser) {

  super(method, ebeanServer, queryString, evaluationContextProvider, parser);

  Parameters<?, ?> parameters = method.getParameters();
  boolean hasPagingOrSortingParameter = parameters.hasPageableParameter() || parameters.hasSortParameter();
  boolean containsPageableOrSortInQueryExpression = queryString.contains("#pageable")
      || queryString.contains("#sort");

  if (hasPagingOrSortingParameter && !containsPageableOrSortInQueryExpression) {
    throw new InvalidEbeanQueryMethodException(
        "Cannot use native queries with dynamic sorting and/or pagination in method " + method);
  }
}
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:24,代码来源:NativeEbeanUpdate.java


示例4: buildQuery

import org.springframework.data.repository.query.Parameters; //导入依赖的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();
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:19,代码来源:QueryUtils.java


示例5: buildQueryConditionsWithParameters_should_work_with_the_same_placeholder_values_as_fieldkeys

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void buildQueryConditionsWithParameters_should_work_with_the_same_placeholder_values_as_fieldkeys()
		throws Exception {
	// @Query(select = {"item_id", "sampleAttribute"}, where =
	// "sampleAttribute<=:sampleAttribute and item_id = :item_id")

	final String expectedQuery = "select item_id, sampleAttribute from `testDB.sampleEntity` where sampleAttribute<='3' and item_id = '5'";

	SimpleDbQueryMethod repositoryMethod = prepareQueryMethodToTest("selectWithEqualPlaceholders",
			SampleEntity.class);
	final String toProcessRawQuery = repositoryMethod.getAnnotatedQuery();

	final Parameters parameters = getMockParameters(new String[]{":sampleAttribute", ":item_id"}, new Class[]{String.class, String.class});

	String resultedQuery = QueryUtils.buildQuery(toProcessRawQuery, parameters, "3", "5");

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:19,代码来源:SimpleDbNamedQueryMethodBindedTest.java


示例6: buildQueryConditionsWithParameters_should_work_with_different_placeholder_values_as_fieldkeys

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void buildQueryConditionsWithParameters_should_work_with_different_placeholder_values_as_fieldkeys()
		throws Exception {
	// @Query(select = {"item_id", "sampleAttribute"}, where = "sampleAttribute<=:attribute and item_id = :item")

	final String expectedQuery = "select item_id, sampleAttribute from `testDB.sampleEntity` where sampleAttribute<='3' and item_id = '5'";

	SimpleDbQueryMethod repositoryMethod = prepareQueryMethodToTest("selectWithDifferentPlaceholders",
			SampleEntity.class);
	final String toProcessRawQuery = repositoryMethod.getAnnotatedQuery();

	final Parameters parameters = getMockParameters(new String[]{":attribute", ":item"}, new Class[]{String.class, String.class});

	String resultedQuery = QueryUtils.buildQuery(toProcessRawQuery, parameters, "3", "5");

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:18,代码来源:SimpleDbNamedQueryMethodBindedTest.java


示例7: buildQueryConditionsWithParameters_should_work_with_primitive_type_parameter_values

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void buildQueryConditionsWithParameters_should_work_with_primitive_type_parameter_values() throws Exception {
	// @Query(select = {"item_id", "sampleAttribute"}, where = "sampleAttribute<=:attribute and item_id = :item")

	final int age = 5;
	final String convertedAge = SimpleDBAttributeConverter.encode(age);

	final String expectedQuery = "select item_id, sampleAttribute from `testDB.sampleEntity` where sampleAttribute<='3' and item_id = '"
			+ convertedAge + "'";

	SimpleDbQueryMethod repositoryMethod = prepareQueryMethodToTest("selectWithDifferentPlaceholders",
			SampleEntity.class);
	final String toProcessRawQuery = repositoryMethod.getAnnotatedQuery();

	final Parameters parameters = getMockParameters(new String[]{":attribute", ":item"}, new Class[]{String.class, int.class});

	String resultedQuery = QueryUtils.buildQuery(toProcessRawQuery, parameters, "3", 5);

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:21,代码来源:SimpleDbNamedQueryMethodBindedTest.java


示例8: buildQueryConditionsWithParameters_should_construct_correct_query_with_converted_parameter_values

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void buildQueryConditionsWithParameters_should_construct_correct_query_with_converted_parameter_values() {
	final String bind_query = "select * from customer_all WHERE age = :age and email = :email and balance = :balance";

	final int age = 23;
	final String email = "[email protected]";
	final float balance = 12.1f;

	final String convertedAge = SimpleDBAttributeConverter.encode(age);
	final String convertedBalance = SimpleDBAttributeConverter.encode(balance);

	String expectedQuery = "select * from customer_all WHERE age = '" + convertedAge + "' and email = '" + email
			+ "' and balance = '" + convertedBalance + "'";

	final Parameters parameters = getMockParameters(new String[]{":age", ":email", ":balance"}, new Class[]{int.class, String.class, float.class});

	String resultedQuery = QueryUtils.buildQuery(bind_query, parameters, age, email,
			balance);

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:22,代码来源:QueryUtilsNamedQueryTest.java


示例9: bindIndexPositionParameters_should_construct_correct_query_from_annotated_query_clauses

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void bindIndexPositionParameters_should_construct_correct_query_from_annotated_query_clauses()
		throws Exception {
	final int age = 23;
	final String email = "[email protected]";
	final String convertedAge = SimpleDBAttributeConverter.encode(age);

	final SimpleDbQueryMethod queryMethod = prepareQueryMethodToTest("selectOrderedParameters", SampleEntity.class);
	final String toProcessParsedQuery = queryMethod.getAnnotatedQuery();

	// @Query(select = {"item_id", "sampleAttribute"}, where = "sampleAttribute<=? and item_id = ? ")
	final String expectedQuery = "select item_id, sampleAttribute from `testDB.sampleEntity` where `sampleAttribute`<='"
			+ convertedAge + "' and item_id = '" + email + "'";

       final Parameters parameters = getMockParameters(new String[]{"?","?"}, new Class[]{int.class, String.class, String.class});
	final String resultedQuery = QueryUtils.buildQuery(toProcessParsedQuery, parameters, age, email);

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:20,代码来源:SimpleDbIndexByQueryMethodBindedTest.java


示例10: bindIndexPositionParameters_should_construct_correct_query_with_converted_parameter_values

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void bindIndexPositionParameters_should_construct_correct_query_with_converted_parameter_values() {
	final int age = 23;
	final String email = "[email protected]";
	final float balance = 12.1f;

	final String convertedAge = SimpleDBAttributeConverter.encode(age);
	final String convertedBalance = SimpleDBAttributeConverter.encode(balance);

	String expectedQuery = "select * from customer_all WHERE age = '" + convertedAge + "' and email = '" + email
			+ "' and balance = '" + convertedBalance + "'";
       final Parameters parameters = getMockParameters(new String[]{"?","?","?"}, new Class[]{int.class, String.class, float.class});

	String resultedQuery = QueryUtils.buildQuery(BIND_QUERY, parameters, age, email, balance);

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:18,代码来源:QueryUtilsIndexByQueryTest.java


示例11: buildQueryConditionsWithParameters_should_construct_correct_bind_query_for_in_operator

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void buildQueryConditionsWithParameters_should_construct_correct_bind_query_for_in_operator() {
	final String bind_query = "select * from customer_all WHERE age in ?";

	final long firstAge = 23;
	final long secondAge = 25;
	final String convertedFirstAge = SimpleDBAttributeConverter.encode(firstAge);
	final String convertedSecondAge = SimpleDBAttributeConverter.encode(secondAge);

	String expectedQuery = "select * from customer_all WHERE age in ('" + convertedFirstAge + "','"
			+ convertedSecondAge + "')";

	final Parameters parameters = getMockParameters(new String[] { "?" }, new Class[] { long[].class });
	String resultedQuery = QueryUtils.buildQuery(bind_query, parameters, new long[] { firstAge, secondAge });

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:18,代码来源:QueryUtilsIndexByQueryTest.java


示例12: buildQueryConditionsWithParameters_should_construct_The_trickiest_query_for_in_operator

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
/**
 * This test shows that if a named param or an index param is used to replace a field name, this will generate an
 * invalid query because quotes are added surrounding the field name
 */
@Ignore
@Test
public void buildQueryConditionsWithParameters_should_construct_The_trickiest_query_for_in_operator() {
	final String bind_query = "select * from customer_all WHERE ?=?";

	final long firstAge = 23;
	final String convertedFirstAge = SimpleDBAttributeConverter.encode(firstAge);

	String expectedQuery = "select * from customer_all WHERE name = '" + convertedFirstAge + "'";

	final Parameters parameters = getMockParameters("?", "?");
	String resultedQuery = QueryUtils.buildQuery(bind_query, parameters, "name", firstAge);

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:20,代码来源:QueryUtilsIndexByQueryTest.java


示例13: buildQueryConditionsWithParameters_should_construct_correct_named_query_for_in_operator

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void buildQueryConditionsWithParameters_should_construct_correct_named_query_for_in_operator() {
	final String bind_query = "select * from customer_all WHERE age in :age and x= :name";

	final int firstAge = 23;
       final int secondAge = 25;
	final String convertedFirstAge = SimpleDBAttributeConverter.encode(firstAge);
       final String convertedSecondAge = SimpleDBAttributeConverter.encode(secondAge);

	String expectedQuery = "select * from customer_all WHERE age in ('" + convertedFirstAge + "','"+convertedSecondAge+"') and x= 'name'";
	final Parameters parameters = getMockParameters(new String[]{":name", ":age"}, new Class[]{String.class, int[].class});

	String resultedQuery = QueryUtils.buildQuery(bind_query, parameters, "name", new int[]{firstAge, secondAge});

	assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:17,代码来源:QueryUtilsArrayTest.java


示例14: buildQueryConditionsWithParameters_should_construct_correct_named_query_for_in_operator_with_no_space

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
@Test
public void buildQueryConditionsWithParameters_should_construct_correct_named_query_for_in_operator_with_no_space() {
    final String bind_query = "select * from customer_all WHERE age in:age";

    final int firstAge = 23;
    final int secondAge = 25;
    final String convertedFirstAge = SimpleDBAttributeConverter.encode(firstAge);
    final String convertedSecondAge = SimpleDBAttributeConverter.encode(secondAge);

    String expectedQuery = "select * from customer_all WHERE age in('" + convertedFirstAge + "','"+convertedSecondAge+"')";
    final Parameters parameters = getMockParameters(new String[]{":age"}, new Class[]{String.class});

    String resultedQuery = QueryUtils.buildQuery(bind_query, parameters, new int[]{firstAge, secondAge});

    assertThat(resultedQuery, is(expectedQuery));
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:17,代码来源:QueryUtilsArrayTest.java


示例15: ParameterMetadataProvider

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
/**
 * Creates a new {@link ParameterMetadataProvider} from the given {@link Iterable} of all
 * bindable parameter values.
 *
 * @param bindableParameterValues may be {@literal null}.
 * @param parameters              must not be {@literal null}.
 */
private ParameterMetadataProvider(Iterator<Object> bindableParameterValues,
                                  Parameters<?, ?> parameters) {
  Assert.notNull(parameters, "Parameters must not be null!");

  this.parameters = parameters.getBindableParameters().iterator();
  this.expressions = new ArrayList<ParameterMetadata<?>>();
  this.bindableParameterValues = bindableParameterValues;
}
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:16,代码来源:ParameterMetadataProvider.java


示例16: GqQueryMethod

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
/**
 * Creates a {@link JpaQueryMethod}.
 * 
 * @param method
 *            must not be {@literal null}
 * @param extractor
 *            must not be {@literal null}
 * @param metadata
 *            must not be {@literal null}
 */
public GqQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory, JefEntityManagerFactory emf) {

	super(method, metadata, factory);

	Assert.notNull(method, "Method must not be null!");

	this.method = method;
	this.emf = emf;
	Assert.isTrue(!(isModifyingQuery() && getParameters().hasSpecialParameter()), String.format("Modifying method must not contain %s!", Parameters.TYPES));
	assertParameterNamesInAnnotatedQuery();
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:22,代码来源:GqQueryMethod.java


示例17: prepareRearrange

import org.springframework.data.repository.query.Parameters; //导入依赖的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;
			}
		}
	}
}
 
开发者ID:hazelcast,项目名称:spring-data-hazelcast,代码行数:52,代码来源:HazelcastPartTreeQuery.java


示例18: bindQueryParameters

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
public static String bindQueryParameters(SimpleDbQueryMethod queryMethod,
		Object... parameterValues) {
	final String rawQuery = queryMethod.getAnnotatedQuery();

	if (hasNamedParameter(queryMethod) || hasBindParameter(rawQuery)) {
		final Parameters parameters = queryMethod.getParameters();
		return buildQuery(rawQuery, parameters, parameterValues);

	}

	return rawQuery;
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:13,代码来源:QueryUtils.java


示例19: validateBindParametersCount

import org.springframework.data.repository.query.Parameters; //导入依赖的package包/类
public static void validateBindParametersCount(Parameters parameters,
		Object... parameterValues) {
	int numOfParameters = parameters.getNumberOfParameters();

	if (numOfParameters != parameterValues.length) {
		throw new MappingException(
				"Wrong Number of Parameters to bind in Query! Parameter Values size="
						+ parameterValues.length
						+ ", Method Bind Parameters size="
						+ numOfParameters);
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:13,代码来源:QueryUtils.java


示例20: validateBindParametersTypes

import org.springframework.data.repository.query.Parameters; //导入依赖的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!"));
		}
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:19,代码来源:QueryUtils.java



注:本文中的org.springframework.data.repository.query.Parameters类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Weathers类代码示例发布时间:2022-05-22
下一篇:
Java DoorSound类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap