cn.sylinx.hbatis.ext.xmapper.spi.XmapperServiceManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hbatis-xmapper Show documentation
Show all versions of hbatis-xmapper Show documentation
hbatis-xmapper is a simple orm framework, extends hbatis-core
package cn.sylinx.hbatis.ext.xmapper.spi;
import java.util.Iterator;
import java.util.ServiceLoader;
import java.util.concurrent.locks.ReentrantLock;
import cn.sylinx.hbatis.ext.xmapper.XmapperService;
public class XmapperServiceManager {
private static XmapperService xmapperService;
private static ReentrantLock lock = new ReentrantLock();
public static XmapperService getXmapperService() {
if (xmapperService != null) {
return xmapperService;
}
// 加載MirageService
loadXmapperService();
return xmapperService;
}
private static void loadXmapperService() {
try {
lock.lock();
if (xmapperService == null) {
ServiceLoader sl = ServiceLoader.load(XmapperService.class);
Iterator it = sl.iterator();
xmapperService = it.hasNext() ? it.next() : null;
}
} finally {
lock.unlock();
}
}
}