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

com.googlecode.jpattern.orm.session.datasource.DataSourceSession Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.googlecode.jpattern.orm.session.datasource;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.googlecode.jpattern.orm.IOrmClassToolMap;
import com.googlecode.jpattern.orm.exception.OrmException;
import com.googlecode.jpattern.orm.session.ASession;
import com.googlecode.jpattern.orm.session.ISqlPerformer;
import com.googlecode.jpattern.orm.session.ITransaction;

/**
 * 
 * @author Francesco Cina
 *
 * 21/mag/2011
 */
public class DataSourceSession extends ASession {

	private final Connection conn;

	public DataSourceSession(DataSource dataSource, IOrmClassToolMap ormClassToolMap) {
		super(ormClassToolMap);
		try {
			this.conn = dataSource.getConnection();
		} catch (SQLException e) {
			throw new OrmException(e);
		}
	}

	@Override
	public ITransaction beginTransaction() throws OrmException {
		return new DataSourceTransaction(conn);
	}

	@Override
	public void close() throws OrmException {
		try {
			this.conn.close();
		} catch (SQLException e) {
			throw new OrmException(e);
		}
	}
	
	@Override
	public ISqlPerformer sqlPerformer() throws OrmException {
		return new DataSourceSqlPerformer(conn);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy