cn.sylinx.hbatis.ext.AbstractDaoSingleton Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hbatis-core Show documentation
Show all versions of hbatis-core Show documentation
hbatis is a simple orm framework
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);
}