Search in sources :

Example 16 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByIntegerAttributeIn.

// DATAJDBC-318
@Test
public void createsQueryToFindAllEntitiesByIntegerAttributeIn() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByAgeIn", 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\" IN (:age)");
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) Test(org.junit.jupiter.api.Test)

Example 17 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByBooleanAttributeTrue.

// DATAJDBC-318
@Test
public void createsQueryToFindAllEntitiesByBooleanAttributeTrue() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByActiveTrue");
    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 18 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByIntegerAttributeLessThan.

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

Example 19 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByStringAttributeNot.

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

Example 20 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryByEmbeddedObject.

// DATAJDBC-318
@Test
public void createsQueryByEmbeddedObject() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findByAddress", Address.class);
    PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { new Address("Hello", "World") });
    ParametrizedQuery query = jdbcQuery.createQuery(accessor, returnedType);
    String actualSql = query.getQuery();
    // 
    assertThat(actualSql).startsWith(// 
    BASE_SELECT + " WHERE (" + TABLE + ".\"USER_").endsWith(// 
    ")").contains(// 
    TABLE + ".\"USER_STREET\" = :user_street", // 
    " AND ", TABLE + ".\"USER_CITY\" = :user_city");
    assertThat(query.getParameterSource().getValue("user_street")).isEqualTo("Hello");
    assertThat(query.getParameterSource().getValue("user_city")).isEqualTo("World");
}
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