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

com.scudata.common.DBSessionFactory Maven / Gradle / Ivy

Go to download

SPL(Structured Process Language) A programming language specially for structured data computing.

There is a newer version: 20241126
Show newest version
package com.scudata.common;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.util.Properties;

public class DBSessionFactory implements ISessionFactory {
	String url;
	Properties info = new Properties();
	DBConfig cfg;

	public DBSessionFactory(DBConfig cfg) throws Exception {
		this.cfg = cfg;
		this.url = cfg.getUrl();
		if (cfg.getInfo() != null)
				  this.info.putAll(cfg.getInfo());
				//editd by bdl, 2013.11.21, Properties?в??ܼ????value
				if (cfg.getUser() != null)
				  this.info.put("user", cfg.getUser());
				if (cfg.getPassword() != null)
				  this.info.put("password", cfg.getPassword());

		// getTables getColumns????ʾremarks
		if (cfg.getDBType() == DBTypes.ORACLE)
			this.info.put("remarksReporting", "true"); // oracle

		String driverClass = cfg.getDriver();
		if( driverClass != null && driverClass.trim().length() > 0 ) {   //20240801 sjr???Ӵ???????PL/java?в???Ҫ??????????
			try {
				Driver d = (Driver) Class.forName(driverClass).newInstance();
				DriverManager.registerDriver(d);
			}
			catch (Exception e) {
				Logger.error("Database driver " + driverClass + " is not found!");
				throw e;
			}
		}
	}

	public DBSession getSession() throws Exception {
		// edited by bdl, 2008.11.18??Connectionȫ????Ϊ???Զ??ύ??
		//Connection con = DriverManager.getConnection(url, info);
		Driver d = DriverManager.getDriver(url);
		Connection con = d.connect(url, info);
		try{ con.setAutoCommit(false); }catch( Throwable t ) {}
		return new DBSession(con, cfg);
	}

	// sjr add
	public DBConfig getDBConfig() {
		return cfg;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy