Search in sources :

Example 1 with SessionScope

use of com.ibatis.sqlmap.engine.scope.SessionScope in project druid by alibaba.

the class IbatisUtils method set.

public static void set(SqlMapSessionImpl session, SqlMapClientImpl client) {
    if (sessionField == null) {
        for (Field field : SqlMapSessionImpl.class.getDeclaredFields()) {
            if (field.getName().equals("session") || field.getName().equals("sessionScope")) {
                sessionField = field;
                sessionField.setAccessible(true);
                break;
            }
        }
    }
    if (sessionField != null) {
        SessionScope sessionScope;
        try {
            sessionScope = (SessionScope) sessionField.get(session);
            if (sessionScope != null) {
                if (sessionScope.getSqlMapClient() != null && sessionScope.getSqlMapClient().getClass() == SqlMapClientImpl.class) {
                    sessionScope.setSqlMapClient(client);
                }
                if (sessionScope.getSqlMapExecutor() != null && sessionScope.getSqlMapExecutor().getClass() == SqlMapClientImpl.class) {
                    sessionScope.setSqlMapExecutor(client);
                }
                if (sessionScope.getSqlMapTxMgr() != null && sessionScope.getSqlMapTxMgr().getClass() == SqlMapClientImpl.class) {
                    sessionScope.setSqlMapTxMgr(client);
                }
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) SqlMapClientImpl(com.ibatis.sqlmap.engine.impl.SqlMapClientImpl) SessionScope(com.ibatis.sqlmap.engine.scope.SessionScope)

Aggregations

SqlMapClientImpl (com.ibatis.sqlmap.engine.impl.SqlMapClientImpl)1 SessionScope (com.ibatis.sqlmap.engine.scope.SessionScope)1 Field (java.lang.reflect.Field)1