Search in sources :

Example 1 with RelationalParametersParameterAccessor

use of org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor in project spring-data-jdbc by spring-projects.

the class StringBasedJdbcQuery method execute.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
	 */
@Override
public Object execute(Object[] objects) {
    RelationalParameterAccessor accessor = new RelationalParametersParameterAccessor(getQueryMethod(), objects);
    ResultProcessor processor = getQueryMethod().getResultProcessor().withDynamicProjection(accessor);
    ResultProcessingConverter converter = new ResultProcessingConverter(processor, this.converter.getMappingContext(), this.converter.getEntityInstantiators());
    RowMapper<Object> rowMapper = determineRowMapper(rowMapperFactory.create(resolveTypeToRead(processor)), converter, accessor.findDynamicProjection() != null);
    JdbcQueryExecution<?> queryExecution = getQueryExecution(// 
    queryMethod, // 
    determineResultSetExtractor(rowMapper), rowMapper);
    return queryExecution.execute(determineQuery(), this.bindParameters(accessor));
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) RelationalParameterAccessor(org.springframework.data.relational.repository.query.RelationalParameterAccessor) ResultProcessor(org.springframework.data.repository.query.ResultProcessor)

Example 2 with RelationalParametersParameterAccessor

use of org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor in project spring-data-jdbc by spring-projects.

the class PartTreeJdbcQuery method execute.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
	 */
@Override
public Object execute(Object[] values) {
    RelationalParametersParameterAccessor accessor = new RelationalParametersParameterAccessor(getQueryMethod(), values);
    ResultProcessor processor = getQueryMethod().getResultProcessor().withDynamicProjection(accessor);
    ParametrizedQuery query = createQuery(accessor, processor.getReturnedType());
    JdbcQueryExecution<?> execution = getQueryExecution(processor, accessor);
    return execution.execute(query.getQuery(), query.getParameterSource());
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) ResultProcessor(org.springframework.data.repository.query.ResultProcessor)

Example 3 with RelationalParametersParameterAccessor

use of org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor in project spring-data-jdbc by spring-projects.

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByDateAttributeBefore.

// DATAJDBC-318
@Test
public void createsQueryToFindAllEntitiesByDateAttributeBefore() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByDateOfBirthBefore", Date.class);
    PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { new Date() });
    ParametrizedQuery query = jdbcQuery.createQuery(accessor, returnedType);
    assertThat(query.getQuery()).isEqualTo(BASE_SELECT + " WHERE " + TABLE + ".\"DATE_OF_BIRTH\" < :date_of_birth");
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with RelationalParametersParameterAccessor

use of org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor in project spring-data-jdbc by spring-projects.

the class PartTreeJdbcQueryUnitTests method wrapsLikeOperatorParameterWithPercentSymbolsForNotContainingQuery.

// DATAJDBC-318
@Test
public void wrapsLikeOperatorParameterWithPercentSymbolsForNotContainingQuery() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByFirstNameNotContaining", String.class);
    PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { "oh" });
    ParametrizedQuery query = jdbcQuery.createQuery(accessor, returnedType);
    assertThat(query.getQuery()).isEqualTo(BASE_SELECT + " WHERE " + TABLE + ".\"FIRST_NAME\" NOT LIKE :first_name");
    assertThat(query.getParameterSource().getValue("first_name")).isEqualTo("%oh%");
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) Test(org.junit.jupiter.api.Test)

Example 5 with RelationalParametersParameterAccessor

use of org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor in project spring-data-jdbc by spring-projects.

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByStringAttributeStartingWith.

// DATAJDBC-318
@Test
public void createsQueryToFindAllEntitiesByStringAttributeStartingWith() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByFirstNameStartingWith", String.class);
    PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { "Jo" });
    ParametrizedQuery query = jdbcQuery.createQuery(accessor, returnedType);
    assertThat(query.getQuery()).isEqualTo(BASE_SELECT + " WHERE " + TABLE + ".\"FIRST_NAME\" LIKE :first_name");
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) Test(org.junit.jupiter.api.Test)

Aggregations

RelationalParametersParameterAccessor (org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor)33 Test (org.junit.jupiter.api.Test)31 Date (java.util.Date)3 ResultProcessor (org.springframework.data.repository.query.ResultProcessor)2 RelationalParameterAccessor (org.springframework.data.relational.repository.query.RelationalParameterAccessor)1