Search in sources :

Example 1 with SqlSessionException

use of org.apache.ibatis.session.SqlSessionException in project JessMA by ldcsaa.

the class MyBatisSessionMgr method setSessionTransIsoLevel.

/** 参考:{@link SessionMgr#setSessionTransIsoLevel(TransIsoLevel)} */
@Override
public void setSessionTransIsoLevel(TransIsoLevel level) {
    try {
        SqlSession session = getSession();
        Connection conn = session.getConnection();
        conn.setTransactionIsolation(level.toInt());
    } catch (SQLException e) {
        throw new SqlSessionException(e);
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SqlSessionException(org.apache.ibatis.session.SqlSessionException)

Example 2 with SqlSessionException

use of org.apache.ibatis.session.SqlSessionException in project JessMA by ldcsaa.

the class MyBatisSessionMgr method loadDefalutTransIsoLevel.

/** 参考:{@link AbstractSessionMgr#loadDefalutTransIsoLevel()} */
@Override
protected void loadDefalutTransIsoLevel() {
    try {
        SqlSession session = getSession();
        Connection conn = session.getConnection();
        int level = conn.getTransactionIsolation();
        defaultTransIsoLevel = TransIsoLevel.fromInt(level);
    } catch (SQLException e) {
        throw new SqlSessionException(e);
    } finally {
        closeSession();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SqlSessionException(org.apache.ibatis.session.SqlSessionException)

Example 3 with SqlSessionException

use of org.apache.ibatis.session.SqlSessionException in project JessMA by ldcsaa.

the class MyBatisSessionMgr method buildSessionFactory.

/** 创建 {@link SqlSessionFactory} */
private void buildSessionFactory() {
    synchronized (this) {
        if (sessionFactory == null) {
            try {
                Reader reader = Resources.getResourceAsReader(configFile);
                sessionFactory = new SqlSessionFactoryBuilder().build(reader, environment);
                if (GeneralHelper.isStrNotEmpty(pattern)) {
                    Set<String> packages = PackageHelper.getPackages(pattern);
                    for (String pkg : packages) {
                        Set<Class<?>> entities = PackageHelper.getClasses(pkg, false, new ClassFilter() {

                            @Override
                            public boolean accept(Class<?> clazz) {
                                if (!BeanHelper.isPublicInterface(clazz))
                                    return false;
                                return true;
                            }
                        });
                        Configuration cfg = sessionFactory.getConfiguration();
                        for (Class<?> clazz : entities) {
                            if (!cfg.hasMapper(clazz))
                                cfg.addMapper(clazz);
                        }
                    }
                }
            } catch (IOException e) {
                throw new SqlSessionException(e);
            }
        }
    }
}
Also used : Configuration(org.apache.ibatis.session.Configuration) ClassFilter(org.jessma.util.PackageHelper.ClassFilter) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) IOException(java.io.IOException) SqlSessionException(org.apache.ibatis.session.SqlSessionException)

Aggregations

SqlSessionException (org.apache.ibatis.session.SqlSessionException)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 SqlSession (org.apache.ibatis.session.SqlSession)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 Configuration (org.apache.ibatis.session.Configuration)1 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)1 ClassFilter (org.jessma.util.PackageHelper.ClassFilter)1