当前位置: 首页>>代码示例>>Java>>正文


Java Parameters类代码示例

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


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


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