Search in sources :

Example 6 with QueryMappingConfiguration

use of org.springframework.data.jdbc.repository.QueryMappingConfiguration in project spring-data-jdbc by spring-projects.

the class JdbcQueryLookupStrategyUnitTests method prefersDeclaredQuery.

// GH-1061
@Test
void prefersDeclaredQuery() {
    RowMapper<? extends NumberFormat> numberFormatMapper = mock(RowMapper.class);
    QueryMappingConfiguration mappingConfiguration = new DefaultQueryMappingConfiguration().registerRowMapper(NumberFormat.class, numberFormatMapper);
    RepositoryQuery repositoryQuery = getRepositoryQuery("annotatedQueryWithQueryAndQueryName", mappingConfiguration);
    repositoryQuery.execute(new Object[] {});
    verify(operations).queryForObject(eq("some SQL"), any(SqlParameterSource.class), any(RowMapper.class));
}
Also used : RepositoryQuery(org.springframework.data.repository.query.RepositoryQuery) QueryMappingConfiguration(org.springframework.data.jdbc.repository.QueryMappingConfiguration) DefaultQueryMappingConfiguration(org.springframework.data.jdbc.repository.config.DefaultQueryMappingConfiguration) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) DefaultQueryMappingConfiguration(org.springframework.data.jdbc.repository.config.DefaultQueryMappingConfiguration) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.jupiter.api.Test)

Example 7 with QueryMappingConfiguration

use of org.springframework.data.jdbc.repository.QueryMappingConfiguration in project spring-data-jdbc by spring-projects.

the class JdbcQueryLookupStrategyUnitTests method typeBasedRowMapperGetsUsedForQuery.

// DATAJDBC-166
@Test
@SuppressWarnings("unchecked")
void typeBasedRowMapperGetsUsedForQuery() {
    RowMapper<? extends NumberFormat> numberFormatMapper = mock(RowMapper.class);
    QueryMappingConfiguration mappingConfiguration = new DefaultQueryMappingConfiguration().registerRowMapper(NumberFormat.class, numberFormatMapper);
    RepositoryQuery repositoryQuery = getRepositoryQuery("returningNumberFormat", mappingConfiguration);
    repositoryQuery.execute(new Object[] {});
    verify(operations).queryForObject(anyString(), any(SqlParameterSource.class), any(RowMapper.class));
}
Also used : RepositoryQuery(org.springframework.data.repository.query.RepositoryQuery) QueryMappingConfiguration(org.springframework.data.jdbc.repository.QueryMappingConfiguration) DefaultQueryMappingConfiguration(org.springframework.data.jdbc.repository.config.DefaultQueryMappingConfiguration) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) DefaultQueryMappingConfiguration(org.springframework.data.jdbc.repository.config.DefaultQueryMappingConfiguration) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.jupiter.api.Test)

Example 8 with QueryMappingConfiguration

use of org.springframework.data.jdbc.repository.QueryMappingConfiguration in project spring-data-jdbc by spring-projects.

the class ConfigurableRowMapperMapUnitTests method prefersLatestRegistrationForSuperTypeMatch.

// DATAJDBC-166
@Test
public void prefersLatestRegistrationForSuperTypeMatch() {
    RowMapper rowMapper = mock(RowMapper.class);
    QueryMappingConfiguration map = // 
    new DefaultQueryMappingConfiguration().registerRowMapper(Integer.class, // 
    mock(RowMapper.class)).registerRowMapper(Number.class, rowMapper);
    assertThat(map.getRowMapper(Object.class)).isEqualTo(rowMapper);
}
Also used : QueryMappingConfiguration(org.springframework.data.jdbc.repository.QueryMappingConfiguration) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.jupiter.api.Test)

Example 9 with QueryMappingConfiguration

use of org.springframework.data.jdbc.repository.QueryMappingConfiguration in project spring-data-jdbc by spring-projects.

the class ConfigurableRowMapperMapUnitTests method returnsConfiguredInstanceForClass.

// DATAJDBC-166
@Test
public void returnsConfiguredInstanceForClass() {
    RowMapper rowMapper = mock(RowMapper.class);
    QueryMappingConfiguration map = new DefaultQueryMappingConfiguration().registerRowMapper(Object.class, rowMapper);
    assertThat(map.getRowMapper(Object.class)).isEqualTo(rowMapper);
}
Also used : QueryMappingConfiguration(org.springframework.data.jdbc.repository.QueryMappingConfiguration) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 QueryMappingConfiguration (org.springframework.data.jdbc.repository.QueryMappingConfiguration)9 RowMapper (org.springframework.jdbc.core.RowMapper)7 DefaultQueryMappingConfiguration (org.springframework.data.jdbc.repository.config.DefaultQueryMappingConfiguration)2 RepositoryQuery (org.springframework.data.repository.query.RepositoryQuery)2 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)2