Search in sources :

Example 1 with SessionMgr

use of org.jessma.dao.SessionMgr in project JessMA by ldcsaa.

the class DaoInjectFilter method parseSessionMgr.

@SuppressWarnings("rawtypes")
private void parseSessionMgr(ActionExecutor executor, String mgrName, DaoAttr daoAttr) throws Exception {
    if (GeneralHelper.isStrEmpty(mgrName))
        daoAttr.mgr = null;
    else {
        SessionMgr mgr = AppConfig.getSessionManager(mgrName);
        if (mgr != null)
            daoAttr.mgr = mgr;
        else
            throwParseException(executor, daoAttr.name, String.format("Session Manager named '%s' not found", mgrName));
    }
    if (daoAttr.mgr != null) {
        Class<?> clazz = daoAttr.daoClass;
        while (clazz.getSuperclass() != AbstractFacade.class) clazz = clazz.getSuperclass();
        Type type = clazz.getGenericSuperclass();
        if (type instanceof ParameterizedType) {
            Class<?> paramClazz = (Class<?>) (((ParameterizedType) type).getActualTypeArguments()[0]);
            if (!paramClazz.isAssignableFrom(daoAttr.mgr.getClass())) {
                String cause = String.format("DAO class (%s) does not match SessionMgr '%s' (%s)", daoAttr.daoClass.getName(), mgrName, daoAttr.mgr.getClass().getName());
                throwParseException(executor, daoAttr.name, cause);
            }
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) SessionMgr(org.jessma.dao.SessionMgr)

Example 2 with SessionMgr

use of org.jessma.dao.SessionMgr in project JessMA by ldcsaa.

the class AppConfig method loadSessionMgrs.

// 注册数据库 Session 管理器
@SuppressWarnings("unchecked")
private void loadSessionMgrs(Element sys) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    Element sms = sys.element("database-session-managers");
    if (sms == null)
        jessMALogger.warn("'database-session-managers' element not found");
    else {
        List<Element> mgrs = sms.elements("manager");
        if (mgrs.size() == 0)
            jessMALogger.warn("none of DATABASE SESSION MANAGER found");
        else {
            for (Element e : mgrs) {
                String name = e.attributeValue("name");
                String clazz = e.attributeValue("class");
                if (GeneralHelper.isStrEmpty(name) || GeneralHelper.isStrEmpty(clazz))
                    throw new RuntimeException("manager's 'name' or 'class' attribute not valid");
                String[] params;
                Element iniargs = e.element("initialize-args");
                if (iniargs == null)
                    params = new String[0];
                else {
                    List<Element> args = iniargs.elements("arg");
                    params = new String[args.size()];
                    for (int i = 0; i < args.size(); i++) params[i] = args.get(i).getTextTrim();
                }
                jessMALogger.info(String.format("register DATABASE SESSION MANAGER '%s (%s)'", name, clazz));
                SessionMgr mgr = (SessionMgr) (Class.forName(clazz).newInstance());
                mgr.initialize(params);
                sessionMgrs.put(name, mgr);
            }
        }
    }
}
Also used : Element(org.dom4j.Element) SessionMgr(org.jessma.dao.SessionMgr)

Aggregations

SessionMgr (org.jessma.dao.SessionMgr)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Element (org.dom4j.Element)1