Search in sources :

Example 1 with SqlGeneratorSource

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

the class MyBatisDataAccessStrategy method createCombinedAccessStrategy.

/**
 * Create a {@link DataAccessStrategy} that first checks for queries defined by MyBatis and if it doesn't find one
 * used a {@link DefaultDataAccessStrategy}
 *
 * @param context
 * @param sqlSession
 * @return
 */
public static DataAccessStrategy createCombinedAccessStrategy(JdbcMappingContext context, SqlSession sqlSession) {
    // the DefaultDataAccessStrategy needs a reference to the returned DataAccessStrategy. This creates a dependency
    // cycle. In order to create it, we need something that allows to defer closing the cycle until all the elements are
    // created. That is the purpose of the DelegatingAccessStrategy.
    DelegatingDataAccessStrategy delegatingDataAccessStrategy = new DelegatingDataAccessStrategy();
    MyBatisDataAccessStrategy myBatisDataAccessStrategy = new MyBatisDataAccessStrategy(sqlSession);
    CascadingDataAccessStrategy cascadingDataAccessStrategy = new CascadingDataAccessStrategy(asList(myBatisDataAccessStrategy, delegatingDataAccessStrategy));
    DefaultDataAccessStrategy defaultDataAccessStrategy = new // 
    DefaultDataAccessStrategy(// 
    new SqlGeneratorSource(context), // 
    context, cascadingDataAccessStrategy);
    delegatingDataAccessStrategy.setDelegate(defaultDataAccessStrategy);
    return cascadingDataAccessStrategy;
}
Also used : CascadingDataAccessStrategy(org.springframework.data.jdbc.core.CascadingDataAccessStrategy) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.DefaultDataAccessStrategy) SqlGeneratorSource(org.springframework.data.jdbc.core.SqlGeneratorSource) DelegatingDataAccessStrategy(org.springframework.data.jdbc.core.DelegatingDataAccessStrategy)

Example 2 with SqlGeneratorSource

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

the class SimpleJdbcRepositoryEventsUnitTests method before.

@Before
public void before() {
    final JdbcMappingContext context = new JdbcMappingContext(createIdGeneratingOperations());
    JdbcRepositoryFactory factory = new // 
    JdbcRepositoryFactory(// 
    publisher, // 
    context, new // 
    DefaultDataAccessStrategy(// 
    new SqlGeneratorSource(context), // 
    context));
    repository = factory.getRepository(DummyEntityRepository.class);
}
Also used : JdbcMappingContext(org.springframework.data.jdbc.mapping.model.JdbcMappingContext) SqlGeneratorSource(org.springframework.data.jdbc.core.SqlGeneratorSource) JdbcRepositoryFactory(org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory) Before(org.junit.Before)

Aggregations

SqlGeneratorSource (org.springframework.data.jdbc.core.SqlGeneratorSource)2 Before (org.junit.Before)1 CascadingDataAccessStrategy (org.springframework.data.jdbc.core.CascadingDataAccessStrategy)1 DefaultDataAccessStrategy (org.springframework.data.jdbc.core.DefaultDataAccessStrategy)1 DelegatingDataAccessStrategy (org.springframework.data.jdbc.core.DelegatingDataAccessStrategy)1 JdbcMappingContext (org.springframework.data.jdbc.mapping.model.JdbcMappingContext)1 JdbcRepositoryFactory (org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory)1