com.jpattern.orm.jdbctemplate.JdbcTemplateSessionProvider Maven / Gradle / Ivy
package com.jpattern.orm.jdbctemplate;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import com.jpattern.orm.session.SessionProvider;
import com.jpattern.orm.session.SessionStrategy;
/**
*
* @author Francesco Cina
*
* 15/giu/2011
*/
public class JdbcTemplateSessionProvider extends SessionProvider {
private final JdbcTemplate jdbcTemplate;
private final PlatformTransactionManager platformTransactionManager;
/**
* If the jporm instance has been created with this constructor the programmatic transaction management
* system will be disabled and the only way to manage transaction will be through the standard Spring
* TRANSACTIONAL annotation
* @param dataSource
*/
public JdbcTemplateSessionProvider(final DataSource dataSource) {
this( new JdbcTemplate(dataSource), new NullPlatformTransactionManager() );
}
/**
* If the jporm instance has been created with this constructor the programmatic transaction management
* system will be disabled and the only way to manage transaction will be through the standard Spring
* TRANSACTIONAL annotation
* @param dataSource
*/
public JdbcTemplateSessionProvider(final JdbcTemplate jdbcTemplate) {
this( jdbcTemplate, new NullPlatformTransactionManager() );
}
public JdbcTemplateSessionProvider(final DataSource dataSource, final PlatformTransactionManager platformTransactionManager) {
this( new JdbcTemplate(dataSource), platformTransactionManager );
}
public JdbcTemplateSessionProvider(final JdbcTemplate jdbcTemplate, final PlatformTransactionManager platformTransactionManager) {
this.jdbcTemplate = jdbcTemplate;
this.platformTransactionManager = platformTransactionManager;
}
@Override
public SessionStrategy getSessionStrategy() {
return new JdbcTemplateSessionStrategy(this.jdbcTemplate, this.platformTransactionManager);
}
@Override
public DataSource getDataSource() {
return this.jdbcTemplate.getDataSource();
}
}