package com.jqmobile.core.server.db.dao;
import com.jqmobile.core.dao.DAO;
public final class DAOFactory {
private DAOFactory(){
}
@SuppressWarnings("unchecked")
public static <T> T instance(Class<T> c){
DAO annotation = c.getAnnotation(DAO.class);
if(null != annotation){
String name = annotation.impl();
try {
Class<?> cl = Class.forName(name, false, Thread.currentThread().getContextClassLoader());
return (T) cl.newInstance();
} catch (Exception e) {
throw new RuntimeException("构建DAO失败", e);
}
}
throw new RuntimeException("构建DAO失败");
}
}