Search in sources :

Example 6 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByBooleanAttributeFalse.

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

Example 7 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method wrapsLikeOperatorParameterWithPercentSymbolsForContainingQuery.

// DATAJDBC-318
@Test
public void wrapsLikeOperatorParameterWithPercentSymbolsForContainingQuery() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByFirstNameContaining", 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\" 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 8 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByIntegerAttributeNotIn.

// DATAJDBC-318
@Test
public void createsQueryToFindAllEntitiesByIntegerAttributeNotIn() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByAgeNotIn", Collection.class);
    PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { Collections.singleton(25) });
    ParametrizedQuery query = jdbcQuery.createQuery(accessor, returnedType);
    assertThat(query.getQuery()).isEqualTo(BASE_SELECT + " WHERE " + TABLE + ".\"AGE\" NOT IN (:age)");
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) Test(org.junit.jupiter.api.Test)

Example 9 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByIntegerAttributeWithAscendingOrderingByStringAttribute.

// DATAJDBC-318
@Test
public void createsQueryToFindAllEntitiesByIntegerAttributeWithAscendingOrderingByStringAttribute() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByAgeOrderByLastNameAsc", Integer.class);
    PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { 123 });
    ParametrizedQuery query = jdbcQuery.createQuery(accessor, returnedType);
    assertThat(query.getQuery()).isEqualTo(BASE_SELECT + " WHERE " + TABLE + ".\"AGE\" = :age ORDER BY \"users\".\"LAST_NAME\" ASC");
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) Test(org.junit.jupiter.api.Test)

Example 10 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method prependsLikeOperatorParameterWithPercentSymbolForEndingWithQuery.

// DATAJDBC-318
@Test
public void prependsLikeOperatorParameterWithPercentSymbolForEndingWithQuery() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByFirstNameEndingWith", String.class);
    PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { "hn" });
    ParametrizedQuery query = jdbcQuery.createQuery(accessor, returnedType);
    assertThat(query.getQuery()).isEqualTo(BASE_SELECT + " WHERE " + TABLE + ".\"FIRST_NAME\" LIKE :first_name");
    assertThat(query.getParameterSource().getValue("first_name")).isEqualTo("%hn");
}
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