Search in sources :

Example 11 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByIntegerAttributeWithDescendingOrderingByStringAttribute.

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

Example 12 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByDateAttributeAfter.

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

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByDateAttributeBetween.

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

Example 14 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByStringAttributeLike.

// DATAJDBC-318
@Test
public void createsQueryToFindAllEntitiesByStringAttributeLike() throws Exception {
    JdbcQueryMethod queryMethod = getQueryMethod("findAllByFirstNameLike", String.class);
    PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { "%John%" });
    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)

Example 15 with RelationalParametersParameterAccessor

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

the class PartTreeJdbcQueryUnitTests method createsQueryToFindAllEntitiesByStringAttributeNotContaining.

// DATAJDBC-318
@Test
public void createsQueryToFindAllEntitiesByStringAttributeNotContaining() 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");
}
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