org.apache.ibatis.exceptions.ExceptionFactory Java Examples
The following examples show how to use
org.apache.ibatis.exceptions.ExceptionFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSqlSessionFactory.java From mybaties with Apache License 2.0 | 6 votes |
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) { Transaction tx = null; try { final Environment environment = configuration.getEnvironment(); final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); //通过事务工厂来产生一个事务 tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit); //生成一个执行器(事务包含在执行器里) final Executor executor = configuration.newExecutor(tx, execType); //然后产生一个DefaultSqlSession return new DefaultSqlSession(configuration, executor, autoCommit); } catch (Exception e) { //如果打开事务出错,则关闭它 closeTransaction(tx); // may have fetched a connection so lets call close() throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); } finally { //最后清空错误上下文 ErrorContext.instance().reset(); } }
Example #2
Source File: DynamicSqlSessionFactory.java From hsweb-framework with Apache License 2.0 | 6 votes |
@SuppressWarnings("all") private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) { Transaction tx = null; try { final Environment environment = getConfiguration().getEnvironment(); final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); DataSource ds = DataSourceHolder.currentDataSource().getNative(); if (ds == null) { ds = environment.getDataSource(); } tx = transactionFactory.newTransaction(ds, level, autoCommit); final Executor executor = getConfiguration().newExecutor(tx, execType); return new DefaultSqlSession(getConfiguration(), executor, autoCommit); } catch (Exception e) { closeTransaction(tx); // may have fetched a connection so lets call close() throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #3
Source File: DefaultSqlSessionFactory.java From mybatis with Apache License 2.0 | 6 votes |
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) { Transaction tx = null; try { final Environment environment = configuration.getEnvironment(); final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); //通过事务工厂来产生一个事务 tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit); //生成一个执行器(事务包含在执行器里) final Executor executor = configuration.newExecutor(tx, execType); //然后产生一个DefaultSqlSession return new DefaultSqlSession(configuration, executor, autoCommit); } catch (Exception e) { //如果打开事务出错,则关闭它 closeTransaction(tx); // may have fetched a connection so lets call close() throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); } finally { //最后清空错误上下文 ErrorContext.instance().reset(); } }
Example #4
Source File: DefaultSqlSession.java From mybatis with Apache License 2.0 | 5 votes |
@Override public Connection getConnection() { try { return executor.getTransaction().getConnection(); } catch (SQLException e) { throw ExceptionFactory.wrapException("Error getting a new connection. Cause: " + e, e); } }
Example #5
Source File: DefaultSqlSession.java From mybatis with Apache License 2.0 | 5 votes |
@Override public List<BatchResult> flushStatements() { try { //转而用执行器来flushStatements return executor.flushStatements(); } catch (Exception e) { throw ExceptionFactory.wrapException("Error flushing statements. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #6
Source File: DefaultSqlSession.java From mybatis with Apache License 2.0 | 5 votes |
@Override public void rollback(boolean force) { try { //转而用执行器来rollback executor.rollback(isCommitOrRollbackRequired(force)); //每次rollback之后,dirty标志设为false dirty = false; } catch (Exception e) { throw ExceptionFactory.wrapException("Error rolling back transaction. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #7
Source File: DefaultSqlSession.java From mybatis with Apache License 2.0 | 5 votes |
@Override public void commit(boolean force) { try { //转而用执行器来commit executor.commit(isCommitOrRollbackRequired(force)); //每次commit之后,dirty标志设为false dirty = false; } catch (Exception e) { throw ExceptionFactory.wrapException("Error committing transaction. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #8
Source File: DefaultSqlSession.java From mybatis with Apache License 2.0 | 5 votes |
@Override public int update(String statement, Object parameter) { try { //每次要更新之前,dirty标志设为true dirty = true; MappedStatement ms = configuration.getMappedStatement(statement); //转而用执行器来update结果 return executor.update(ms, wrapCollection(parameter)); } catch (Exception e) { throw ExceptionFactory.wrapException("Error updating database. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #9
Source File: DefaultSqlSession.java From mybatis with Apache License 2.0 | 5 votes |
@Override public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) { try { MappedStatement ms = configuration.getMappedStatement(statement); executor.query(ms, wrapCollection(parameter), rowBounds, handler); } catch (Exception e) { throw ExceptionFactory.wrapException("Error querying database. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #10
Source File: DefaultSqlSession.java From mybatis with Apache License 2.0 | 5 votes |
@Override public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) { try { //根据statement id找到对应的MappedStatement MappedStatement ms = configuration.getMappedStatement(statement); //转而用执行器来查询结果,注意这里传入的ResultHandler是null return executor.query(ms, wrapCollection(parameter), rowBounds, Executor.NO_RESULT_HANDLER); } catch (Exception e) { throw ExceptionFactory.wrapException("Error querying database. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #11
Source File: DefaultSqlSession.java From mybaties with Apache License 2.0 | 5 votes |
@Override public Connection getConnection() { try { return executor.getTransaction().getConnection(); } catch (SQLException e) { throw ExceptionFactory.wrapException("Error getting a new connection. Cause: " + e, e); } }
Example #12
Source File: DefaultSqlSession.java From mybaties with Apache License 2.0 | 5 votes |
@Override public List<BatchResult> flushStatements() { try { //转而用执行器来flushStatements return executor.flushStatements(); } catch (Exception e) { throw ExceptionFactory.wrapException("Error flushing statements. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #13
Source File: DefaultSqlSession.java From mybaties with Apache License 2.0 | 5 votes |
@Override public void rollback(boolean force) { try { //转而用执行器来rollback executor.rollback(isCommitOrRollbackRequired(force)); //每次rollback之后,dirty标志设为false dirty = false; } catch (Exception e) { throw ExceptionFactory.wrapException("Error rolling back transaction. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #14
Source File: DefaultSqlSession.java From mybaties with Apache License 2.0 | 5 votes |
@Override public void commit(boolean force) { try { //转而用执行器来commit executor.commit(isCommitOrRollbackRequired(force)); //每次commit之后,dirty标志设为false dirty = false; } catch (Exception e) { throw ExceptionFactory.wrapException("Error committing transaction. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #15
Source File: DefaultSqlSession.java From mybaties with Apache License 2.0 | 5 votes |
@Override public int update(String statement, Object parameter) { try { //每次要更新之前,dirty标志设为true dirty = true; MappedStatement ms = configuration.getMappedStatement(statement); //转而用执行器来update结果 return executor.update(ms, wrapCollection(parameter)); } catch (Exception e) { throw ExceptionFactory.wrapException("Error updating database. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #16
Source File: DefaultSqlSession.java From mybaties with Apache License 2.0 | 5 votes |
@Override public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) { try { MappedStatement ms = configuration.getMappedStatement(statement); executor.query(ms, wrapCollection(parameter), rowBounds, handler); } catch (Exception e) { throw ExceptionFactory.wrapException("Error querying database. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }
Example #17
Source File: DefaultSqlSession.java From mybaties with Apache License 2.0 | 5 votes |
@Override public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) { try { //根据statement id找到对应的MappedStatement MappedStatement ms = configuration.getMappedStatement(statement); //转而用执行器来查询结果,注意这里传入的ResultHandler是null return executor.query(ms, wrapCollection(parameter), rowBounds, Executor.NO_RESULT_HANDLER); } catch (Exception e) { throw ExceptionFactory.wrapException("Error querying database. Cause: " + e, e); } finally { ErrorContext.instance().reset(); } }