Search in sources :

Example 1 with JdbcMappingContext

use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.

the class EntityRowMapperUnitTests method createRowMapper.

private <T> EntityRowMapper<T> createRowMapper(Class<T> type, NamingStrategy namingStrategy) {
    JdbcMappingContext context = new // 
    JdbcMappingContext(// 
    namingStrategy, // 
    mock(NamedParameterJdbcOperations.class), // 
    __ -> {
    });
    DataAccessStrategy accessStrategy = mock(DataAccessStrategy.class);
    // the ID of the entity is used to determine what kind of ResultSet is needed for subsequent selects.
    doReturn(new HashSet<>(asList(new Trivial(), new Trivial()))).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_NOT_REFERENCING_MAP), any(JdbcPersistentProperty.class));
    doReturn(new HashSet<>(asList(// 
    new SimpleEntry("one", new Trivial()), // 
    new SimpleEntry("two", new Trivial())))).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_REFERENCING_MAP), any(JdbcPersistentProperty.class));
    doReturn(new HashSet<>(asList(// 
    new SimpleEntry(1, new Trivial()), // 
    new SimpleEntry(2, new Trivial())))).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_REFERENCING_LIST), any(JdbcPersistentProperty.class));
    GenericConversionService conversionService = new GenericConversionService();
    conversionService.addConverter(new IterableOfEntryToMapConverter());
    DefaultConversionService.addDefaultConverters(conversionService);
    Jsr310Converters.getConvertersToRegister().forEach(conversionService::addConverter);
    return new EntityRowMapper<>((JdbcPersistentEntity<T>) context.getRequiredPersistentEntity(type), context, accessStrategy);
}
Also used : JdbcPersistentProperty(org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty) JdbcMappingContext(org.springframework.data.jdbc.mapping.model.JdbcMappingContext) SimpleEntry(java.util.AbstractMap.SimpleEntry) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)

Example 2 with JdbcMappingContext

use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.

the class SqlGeneratorContextBasedNamingStrategyUnitTests method configureSqlGenerator.

/**
 * Plug in a custom {@link NamingStrategy} for this test case.
 */
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {
    JdbcMappingContext context = new JdbcMappingContext(namingStrategy, mock(NamedParameterJdbcOperations.class), __ -> {
    });
    JdbcPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
    return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
}
Also used : JdbcMappingContext(org.springframework.data.jdbc.mapping.model.JdbcMappingContext) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)

Example 3 with JdbcMappingContext

use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.

the class SqlGeneratorFixedNamingStrategyUnitTests method configureSqlGenerator.

/**
 * Plug in a custom {@link NamingStrategy} for this test case.
 *
 * @param namingStrategy
 */
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {
    JdbcMappingContext context = new JdbcMappingContext(namingStrategy, mock(NamedParameterJdbcOperations.class), __ -> {
    });
    JdbcPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
    return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
}
Also used : JdbcMappingContext(org.springframework.data.jdbc.mapping.model.JdbcMappingContext) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)

Example 4 with JdbcMappingContext

use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.

the class SqlGeneratorUnitTests method setUp.

@Before
public void setUp() {
    NamingStrategy namingStrategy = new PrefixingNamingStrategy();
    JdbcMappingContext context = new JdbcMappingContext(namingStrategy, mock(NamedParameterJdbcOperations.class), __ -> {
    });
    JdbcPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
    this.sqlGenerator = new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
}
Also used : NamingStrategy(org.springframework.data.jdbc.mapping.model.NamingStrategy) JdbcMappingContext(org.springframework.data.jdbc.mapping.model.JdbcMappingContext) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) Before(org.junit.Before)

Example 5 with JdbcMappingContext

use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext 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)

Aggregations

JdbcMappingContext (org.springframework.data.jdbc.mapping.model.JdbcMappingContext)5 NamedParameterJdbcOperations (org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)5 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Before (org.junit.Before)1 Bean (org.springframework.context.annotation.Bean)1 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)1 JdbcPersistentProperty (org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty)1 NamingStrategy (org.springframework.data.jdbc.mapping.model.NamingStrategy)1 JdbcRepositoryFactory (org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory)1