Example usage for org.apache.ibatis.session SqlSessionException SqlSessionException

List of usage examples for org.apache.ibatis.session SqlSessionException SqlSessionException

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSessionException SqlSessionException.

Prototype

public SqlSessionException(Throwable cause) 

Source Link

Usage

From source file:org.jessma.dao.mybatis.MyBatisSessionMgr.java

License:Apache License

/** ?{@link AbstractSessionMgr#loadDefalutTransIsoLevel()} */
@Override//from www.j av a 2s  .c  o  m
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();
    }
}

From source file:org.jessma.dao.mybatis.MyBatisSessionMgr.java

License:Apache License

/** ?{@link SessionMgr#setSessionTransIsoLevel(TransIsoLevel)} */
@Override/*from ww w.  j a v a2  s . c  o m*/
public void setSessionTransIsoLevel(TransIsoLevel level) {
    try {
        SqlSession session = getSession();
        Connection conn = session.getConnection();

        conn.setTransactionIsolation(level.toInt());
    } catch (SQLException e) {
        throw new SqlSessionException(e);
    }
}

From source file:org.jessma.dao.mybatis.MyBatisSessionMgr.java

License:Apache License

/**  {@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;
                            }//from   ww  w.  jav a2 s  .  c  o  m
                        });

                        Configuration cfg = sessionFactory.getConfiguration();

                        for (Class<?> clazz : entities) {
                            if (!cfg.hasMapper(clazz))
                                cfg.addMapper(clazz);
                        }
                    }
                }
            } catch (IOException e) {
                throw new SqlSessionException(e);
            }
        }
    }
}

From source file:org.mybatis.guice.session.DbSessionManager.java

License:Apache License

public Connection getConnection() {
    final SqlSession sqlSession = localSqlSession.get();
    if (sqlSession == null)
        throw new SqlSessionException("Error:  Cannot get connection.  No managed session is started.");
    return sqlSession.getConnection();
}

From source file:org.mybatis.guice.session.DbSessionManager.java

License:Apache License

public void clearCache() {
    final SqlSession sqlSession = localSqlSession.get();
    if (sqlSession == null)
        throw new SqlSessionException("Error:  Cannot clear the cache.  No managed session is started.");
    sqlSession.clearCache();/*from w ww.j a v  a  2s .c om*/
}

From source file:org.mybatis.guice.session.DbSessionManager.java

License:Apache License

public void commit() {
    final SqlSession sqlSession = localSqlSession.get();
    if (sqlSession == null)
        throw new SqlSessionException("Error:  Cannot commit.  No managed session is started.");
    sqlSession.commit();/*from   w w w .  j  a  v  a 2  s.co m*/
}

From source file:org.mybatis.guice.session.DbSessionManager.java

License:Apache License

public void commit(boolean force) {
    final SqlSession sqlSession = localSqlSession.get();
    if (sqlSession == null)
        throw new SqlSessionException("Error:  Cannot commit.  No managed session is started.");
    sqlSession.commit(force);//  www. j a  v a2  s .c o m
}

From source file:org.mybatis.guice.session.DbSessionManager.java

License:Apache License

public void rollback() {
    final SqlSession sqlSession = localSqlSession.get();
    if (sqlSession == null)
        throw new SqlSessionException("Error:  Cannot rollback.  No managed session is started.");
    sqlSession.rollback();/*from w w  w .  ja v  a2  s.co m*/
}

From source file:org.mybatis.guice.session.DbSessionManager.java

License:Apache License

public void rollback(boolean force) {
    final SqlSession sqlSession = localSqlSession.get();
    if (sqlSession == null)
        throw new SqlSessionException("Error:  Cannot rollback.  No managed session is started.");
    sqlSession.rollback(force);/*  w  ww. j a  v a 2 s  . c o  m*/
}

From source file:org.mybatis.guice.session.DbSessionManager.java

License:Apache License

public List<BatchResult> flushStatements() {
    final SqlSession sqlSession = localSqlSession.get();
    if (sqlSession == null)
        throw new SqlSessionException("Error:  Cannot rollback.  No managed session is started.");
    return sqlSession.flushStatements();
}