Search in sources :

Example 1 with NamedParameterJdbcOperations

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations in project nextprot-api by calipho-sib.

the class JdbcUtilsTest method mockOperation.

private NamedParameterJdbcOperations mockOperation() {
    NamedParameterJdbcOperations operations = Mockito.mock(NamedParameterJdbcOperations.class);
    when(operations.update(anyString(), any(MapSqlParameterSource.class), any(KeyHolder.class), any(String[].class))).thenReturn(1);
    return operations;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) KeyHolder(org.springframework.jdbc.support.KeyHolder) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)

Example 2 with NamedParameterJdbcOperations

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations in project spring-data-jdbc by spring-projects.

the class SimpleJdbcRepositoryEventsUnitTests method createIdGeneratingOperations.

private static NamedParameterJdbcOperations createIdGeneratingOperations() {
    Answer<Integer> setIdInKeyHolder = invocation -> {
        HashMap<String, Object> keys = new HashMap<>();
        keys.put("id", 4711L);
        KeyHolder keyHolder = invocation.getArgument(2);
        keyHolder.getKeyList().add(keys);
        return 1;
    };
    NamedParameterJdbcOperations operations = mock(NamedParameterJdbcOperations.class);
    when(operations.update(anyString(), any(SqlParameterSource.class), any(KeyHolder.class))).thenAnswer(setIdInKeyHolder);
    when(operations.getJdbcOperations()).thenReturn(mock(JdbcOperations.class));
    return operations;
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) DelegatingDataAccessStrategy(org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) SqlGeneratorSource(org.springframework.data.jdbc.core.convert.SqlGeneratorSource) Dialect(org.springframework.data.relational.core.dialect.Dialect) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) RequiredArgsConstructor(lombok.RequiredArgsConstructor) H2Dialect(org.springframework.data.relational.core.dialect.H2Dialect) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) HashMap(java.util.HashMap) KeyHolder(org.springframework.jdbc.support.KeyHolder) JdbcRepositoryFactory(org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory) Value(lombok.Value) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) SimpleJdbcRepository(org.springframework.data.jdbc.repository.support.SimpleJdbcRepository) JdbcCustomConversions(org.springframework.data.jdbc.core.convert.JdbcCustomConversions) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Assertions(org.assertj.core.api.Assertions) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) Nullable(org.springframework.lang.Nullable) DefaultJdbcTypeFactory(org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory) JdbcConverter(org.springframework.data.jdbc.core.convert.JdbcConverter) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) Tuple(org.assertj.core.groups.Tuple) PagingAndSortingRepository(org.springframework.data.repository.PagingAndSortingRepository) With(lombok.With) org.springframework.data.relational.core.mapping.event(org.springframework.data.relational.core.mapping.event) PageRequest(org.springframework.data.domain.PageRequest) HsqlDbDialect(org.springframework.data.relational.core.dialect.HsqlDbDialect) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) Id(org.springframework.data.annotation.Id) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) HashMap(java.util.HashMap) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) KeyHolder(org.springframework.jdbc.support.KeyHolder) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)

Example 3 with NamedParameterJdbcOperations

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations in project spring-data-jdbc by spring-projects.

the class EnableJdbcRepositoriesIntegrationTests method jdbcOperationsRef.

// DATAJDBC-293
@Test
public void jdbcOperationsRef() {
    NamedParameterJdbcOperations operations = (NamedParameterJdbcOperations) ReflectionUtils.getField(OPERATIONS, factoryBean);
    assertThat(operations).isNotSameAs(defaultOperations).isSameAs(qualifierJdbcOperations);
    DataAccessStrategy dataAccessStrategy = (DataAccessStrategy) ReflectionUtils.getField(DATA_ACCESS_STRATEGY, factoryBean);
    assertThat(dataAccessStrategy).isNotSameAs(defaultDataAccessStrategy).isSameAs(qualifierDataAccessStrategy);
}
Also used : DataAccessStrategy(org.springframework.data.jdbc.core.convert.DataAccessStrategy) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) Test(org.junit.jupiter.api.Test)

Example 4 with NamedParameterJdbcOperations

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations in project spring-data-jdbc by spring-projects.

the class TestConfiguration method jdbcRepositoryFactory.

@Bean
JdbcRepositoryFactory jdbcRepositoryFactory(DataAccessStrategy dataAccessStrategy) {
    NamedParameterJdbcOperations jdbcTemplate = namedParameterJdbcTemplate();
    final JdbcMappingContext context = new JdbcMappingContext(NamingStrategy.INSTANCE, jdbcTemplate, __ -> {
    });
    return new // 
    JdbcRepositoryFactory(// 
    publisher, // 
    context, // 
    dataAccessStrategy);
}
Also used : JdbcMappingContext(org.springframework.data.jdbc.mapping.model.JdbcMappingContext) JdbcRepositoryFactory(org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) Bean(org.springframework.context.annotation.Bean)

Example 5 with NamedParameterJdbcOperations

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations in project spring-data-jdbc by spring-projects.

the class SimpleJdbcRepositoryEventsUnitTests method before.

@BeforeEach
public void before() {
    RelationalMappingContext context = new JdbcMappingContext();
    NamedParameterJdbcOperations operations = createIdGeneratingOperations();
    DelegatingDataAccessStrategy delegatingDataAccessStrategy = new DelegatingDataAccessStrategy();
    Dialect dialect = HsqlDbDialect.INSTANCE;
    JdbcConverter converter = new BasicJdbcConverter(context, delegatingDataAccessStrategy, new JdbcCustomConversions(), new DefaultJdbcTypeFactory(operations.getJdbcOperations()), dialect.getIdentifierProcessing());
    SqlGeneratorSource generatorSource = new SqlGeneratorSource(context, converter, dialect);
    this.dataAccessStrategy = spy(new DefaultDataAccessStrategy(generatorSource, context, converter, operations));
    delegatingDataAccessStrategy.setDelegate(dataAccessStrategy);
    doReturn(true).when(dataAccessStrategy).update(any(), any());
    JdbcRepositoryFactory factory = new JdbcRepositoryFactory(dataAccessStrategy, context, converter, H2Dialect.INSTANCE, publisher, operations);
    this.repository = factory.getRepository(DummyEntityRepository.class);
}
Also used : BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) JdbcRepositoryFactory(org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) JdbcCustomConversions(org.springframework.data.jdbc.core.convert.JdbcCustomConversions) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) JdbcConverter(org.springframework.data.jdbc.core.convert.JdbcConverter) Dialect(org.springframework.data.relational.core.dialect.Dialect) H2Dialect(org.springframework.data.relational.core.dialect.H2Dialect) HsqlDbDialect(org.springframework.data.relational.core.dialect.HsqlDbDialect) DefaultJdbcTypeFactory(org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory) SqlGeneratorSource(org.springframework.data.jdbc.core.convert.SqlGeneratorSource) DelegatingDataAccessStrategy(org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

NamedParameterJdbcOperations (org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)6 DefaultDataAccessStrategy (org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy)3 JdbcRepositoryFactory (org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory)3 HashMap (java.util.HashMap)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 BasicJdbcConverter (org.springframework.data.jdbc.core.convert.BasicJdbcConverter)2 DefaultJdbcTypeFactory (org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory)2 DelegatingDataAccessStrategy (org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy)2 JdbcConverter (org.springframework.data.jdbc.core.convert.JdbcConverter)2 JdbcCustomConversions (org.springframework.data.jdbc.core.convert.JdbcCustomConversions)2 SqlGeneratorSource (org.springframework.data.jdbc.core.convert.SqlGeneratorSource)2 JdbcMappingContext (org.springframework.data.jdbc.core.mapping.JdbcMappingContext)2 Dialect (org.springframework.data.relational.core.dialect.Dialect)2 H2Dialect (org.springframework.data.relational.core.dialect.H2Dialect)2 HsqlDbDialect (org.springframework.data.relational.core.dialect.HsqlDbDialect)2 RelationalMappingContext (org.springframework.data.relational.core.mapping.RelationalMappingContext)2 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)2 KeyHolder (org.springframework.jdbc.support.KeyHolder)2 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1