Example usage for org.apache.ibatis.session.defaults DefaultSqlSession DefaultSqlSession

List of usage examples for org.apache.ibatis.session.defaults DefaultSqlSession DefaultSqlSession

Introduction

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

Prototype

public DefaultSqlSession(Configuration configuration, Executor executor, boolean autoCommit) 

Source Link

Usage

From source file:com.baidu.oped.apm.plugin.mybatis.DefaultSqlSessionIT.java

License:Apache License

@Override
protected SqlSession getSqlSession() {
    return new DefaultSqlSession(this.configuration, this.executor, false);
}

From source file:com.raycloud.cobarclient.mybatis.spring.SqlSessionUtils.java

License:Apache License

/**
 * Environment?/* w  w  w . ja v  a  2s. c  om*/
 *
 * @param environment
 * @param sessionFactory
 * @param executorType
 * @return
 */
private static SqlSession openSession(Environment environment, SqlSessionFactory sessionFactory,
        ExecutorType executorType) {
    Transaction tx = null;
    try {
        final TransactionFactory transactionFactory = environment.getTransactionFactory();
        tx = transactionFactory.newTransaction(environment.getDataSource(), null, false);
        final Executor executor = sessionFactory.getConfiguration().newExecutor(tx, executorType);
        return new DefaultSqlSession(sessionFactory.getConfiguration(), executor, false);
    } 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();
    }
}

From source file:org.hsweb.web.mybatis.dynamic.DynamicSqlSessionFactory.java

License:Apache License

private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level,
        boolean autoCommit) {
    Transaction tx = null;/*from   w  w  w .ja va 2s .c om*/
    try {
        final Environment environment = getConfiguration().getEnvironment();
        final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
        DataSource ds = DataSourceHolder.getActiveSource();
        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();
    }
}

From source file:org.hsweb.web.mybatis.dynamic.DynamicSqlSessionFactory.java

License:Apache License

private SqlSession openSessionFromConnection(ExecutorType execType, Connection connection) {
    try {/*from  www . j a  v a 2 s . com*/
        boolean autoCommit;
        try {
            autoCommit = connection.getAutoCommit();
        } catch (SQLException e) {
            // Failover to true, as most poor drivers
            // or databases won't support transactions
            autoCommit = true;
        }
        final Environment environment = configuration.getEnvironment();
        final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
        final Transaction tx = transactionFactory.newTransaction(connection);
        final Executor executor = configuration.newExecutor(tx, execType);
        return new DefaultSqlSession(configuration, executor, autoCommit);
    } catch (Exception e) {
        throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
    } finally {
        ErrorContext.instance().reset();
    }
}

From source file:org.hswebframework.web.dao.mybatis.dynamic.DynamicSqlSessionFactory.java

License:Apache License

@SuppressWarnings("all")
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level,
        boolean autoCommit) {
    Transaction tx = null;/*from ww w  .  j  av  a2 s.  c  o m*/
    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();
    }
}