Java Code Examples for org.apache.ibatis.session.defaults.DefaultSqlSession

The following examples show how to use org.apache.ibatis.session.defaults.DefaultSqlSession. These examples are extracted from open source projects. 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 Project: hsweb-framework   Source File: DynamicSqlSessionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@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 2
Source Project: Milkomeda   Source File: HaloInterceptor.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private Object warpIntercept(Invocation invocation, MappedStatement mappedStatement, String sql, Object param) throws Throwable {
    // 如果处理器为空,直接返回
    if (CollectionUtils.isEmpty(HaloContext.getTableNameMap())) {
        return invocation.proceed();
    }
    String tableName = MybatisUtil.getFirstTableName(sql);
    if (StringUtils.isEmpty(tableName)) {
        return invocation.proceed();
    }

    // Mybatis map参数获取不存在时会抛异常,转为普通map
    if (param instanceof DefaultSqlSession.StrictMap) {
        param = new HashMap((Map) param);
    }

    // 匹配所有
    invokeWithTable(tableName,"*", sql, mappedStatement, param, null, HaloType.PRE);
    // 完全匹配
    invokeWithTable(tableName, tableName, sql, mappedStatement, param, null, HaloType.PRE);
    Object result = invocation.proceed();
    // 匹配所有
    invokeWithTable(tableName, "*", sql, mappedStatement, param, result, HaloType.POST);
    // 完全匹配
    invokeWithTable(tableName, tableName, sql, mappedStatement, param, result, HaloType.POST);
    return result;
}
 
Example 3
Source Project: sinavi-jfw   Source File: JxSqlSessionFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void SqlSessionをJxSqlSessionに加工して返却する() {
    Configuration config = new Configuration();
    SqlSession session = new DefaultSqlSession(config, null);
    SqlSession wrapped = factory.wrap(session);
    assertThat(wrapped, is(instanceOf(JxSqlSession.class)));
    assertThat(wrapped.getConfiguration(), is(config)); // delegate 確認
}
 
Example 4
Source Project: sumk   Source File: SqlSessionFactory.java    License: Apache License 2.0 4 votes vote down vote up
public SqlSession openSession(Connection conn) {

		Transaction transaction = new ManagedTransaction(conn, false);
		Executor executor = configuration.newExecutor(transaction);
		return new DefaultSqlSession(configuration, executor);
	}
 
Example 5
Source Project: pinpoint   Source File: DefaultSqlSessionIT.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected SqlSession getSqlSession() {
    return new DefaultSqlSession(this.configuration, this.executor, false);
}