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

panda.dao.sql.dbcp.ThreadLocalDataSource Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.dao.sql.dbcp;

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


public class ThreadLocalDataSource extends AbstractDataSource {
	private ThreadLocal local = new ThreadLocal();

	/**
	 * Constructor
	 */
	public ThreadLocalDataSource() {
		super();
	}

	@Override
	protected Connection popConnection() throws SQLException {
		ThreadLocalConnection c = local.get();
		if (c == null || c.isClosed()) {
			c = newConnection();
			local.set(c);
		}
		return c;
	}

	protected ThreadLocalConnection newConnection() throws SQLException {
		ThreadLocalConnection c = new ThreadLocalConnection(DriverManager.getConnection(jdbc.url, prop));
		Connection r = c.getRealConnection();
		if (r.getAutoCommit() != jdbc.autoCommit) {
			r.setAutoCommit(jdbc.autoCommit);
		}
		return c;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy