All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jpattern.orm.jdbctemplate.JdbcTemplateSessionProvider Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy