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

cn.sylinx.hbatis.plugin.statement.StatementHandlerManager Maven / Gradle / Ivy

There is a newer version: 2.0.0.RELEASE
Show newest version
package cn.sylinx.hbatis.plugin.statement;

import cn.sylinx.hbatis.ext.res.StatementHandler;
import cn.sylinx.hbatis.log.GLog;

public enum StatementHandlerManager {

	ME;

	private StatementHandler statementHandler = null;

	public static StatementHandlerManager get() {
		return ME;
	}

	public synchronized void init(String statementHandlerClass) {

		if (statementHandler != null) {
			GLog.error("statementHandler can only be instantiated once");
			return;
		}

		if (statementHandlerClass == null) {
			GLog.error("statementHandlerClass CAN NOT BE NULL");
			return;
		}

		try {
			Class clz = Class.forName(statementHandlerClass);
			statementHandler = (StatementHandler) clz.newInstance();
		} catch (Exception e) {
			GLog.error("初始化StatementHandler异常", e);
		}

	}

	public StatementHandler getStatementHandler(String ds) {

		if (statementHandler == null) {
			return null;
		}

		if (statementHandler instanceof DatasourceStatementHandler) {
			return ((DatasourceStatementHandler) statementHandler).get(ds);
		}

		return statementHandler;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy