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

cn.sylinx.hbatis.ext.AbstractDaoSingleton Maven / Gradle / Ivy

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

import java.util.HashMap;
import java.util.Map;

public abstract class AbstractDaoSingleton implements DaoSupport {

	protected Map daoServiceMap = new HashMap();

	public T getDaoService() {
		return getDaoService(getDefaultDatasourceName());
	}

	public T getDaoService(String datasourceName) {

		T daoService = daoServiceMap.get(datasourceName);
		if (daoService == null) {

			synchronized (datasourceName.intern()) {
				init(datasourceName);
			}

			daoService = daoServiceMap.get(datasourceName);
		}

		return daoService;
	}

	protected void init(String datasourceName) {
		T daoService = daoServiceMap.get(datasourceName);
		if (daoService == null) {
			daoService = createDaoService(datasourceName);
			daoServiceMap.put(datasourceName, daoService);
		}
	}

	protected abstract String getDefaultDatasourceName();

	protected abstract T createDaoService(String datasourceName);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy