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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations