Search in sources :

Example 1 with CascadingDataAccessStrategy

use of org.springframework.data.jdbc.core.convert.CascadingDataAccessStrategy 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
 * uses a {@link DefaultDataAccessStrategy}
 */
public static DataAccessStrategy createCombinedAccessStrategy(RelationalMappingContext context, JdbcConverter converter, NamedParameterJdbcOperations operations, SqlSession sqlSession, NamespaceStrategy namespaceStrategy, Dialect dialect) {
    // 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, dialect.getIdentifierProcessing());
    myBatisDataAccessStrategy.setNamespaceStrategy(namespaceStrategy);
    CascadingDataAccessStrategy cascadingDataAccessStrategy = new CascadingDataAccessStrategy(asList(myBatisDataAccessStrategy, delegatingDataAccessStrategy));
    SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(context, converter, dialect);
    DefaultDataAccessStrategy defaultDataAccessStrategy = new // 
    DefaultDataAccessStrategy(// 
    sqlGeneratorSource, // 
    context, // 
    converter, // 
    operations);
    delegatingDataAccessStrategy.setDelegate(defaultDataAccessStrategy);
    return cascadingDataAccessStrategy;
}
Also used : CascadingDataAccessStrategy(org.springframework.data.jdbc.core.convert.CascadingDataAccessStrategy) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) SqlGeneratorSource(org.springframework.data.jdbc.core.convert.SqlGeneratorSource) DelegatingDataAccessStrategy(org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy)

Aggregations

CascadingDataAccessStrategy (org.springframework.data.jdbc.core.convert.CascadingDataAccessStrategy)1 DefaultDataAccessStrategy (org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy)1 DelegatingDataAccessStrategy (org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy)1 SqlGeneratorSource (org.springframework.data.jdbc.core.convert.SqlGeneratorSource)1