Java 类org.apache.ibatis.session.defaults.DefaultSqlSession 实例源码

项目:hsweb-framework    文件:DynamicSqlSessionFactory.java   
@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();
    }
}
项目:shardy    文件:ShardSqlSessionFactoryBean.java   
@Override
public SqlSessionFactory getObject() throws Exception {
    SqlSessionFactory sqlSessionFactory = super.getObject();
    if (sqlSessionFactory instanceof DefaultSqlSessionFactory)
        return proxy(sqlSessionFactory, methodInvocation -> {
            if (methodInvocation.getMethod().getName().equals("openSession")) {
                SqlSession session = (SqlSession) methodInvocation.proceed();
                if (session instanceof DefaultSqlSession) {
                    DefaultSqlSession defaultSqlSession = (DefaultSqlSession) session;
                    Executor executor = (Executor) ReflectionUtils.getFieldValue(defaultSqlSession, "executor");
                    if (executor instanceof CachingExecutor) {
                        CachingExecutor cachingExecutor = (CachingExecutor) executor;
                        SimpleExecutor ex = (SimpleExecutor) ReflectionUtils.getFieldValue(cachingExecutor, "delegate");
                        System.out.println("ex-> " + ex.getClass().getName());
                        ReflectionUtils.setDeclaredFieldValue(cachingExecutor, "delegate", proxy(ex, invocation -> {
                            System.out.println("method->" + invocation.getMethod());
                            return invocation.proceed();
                        }));
                    }
                }
                return session;
            }
            return methodInvocation.proceed();
        });
    return sqlSessionFactory;
}
项目:sinavi-jfw    文件:JxSqlSessionFactoryTest.java   
@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 確認
}
项目:sumk    文件:SqlSessionFactory.java   
public SqlSession session(Connection conn) {

        Transaction transaction = new ManagedTransaction(conn, false);
        SimpleExecutor excutor = new SimpleExecutor(configuration, transaction);
        return new DefaultSqlSession(configuration, excutor);
    }
项目:apm-agent    文件:DefaultSqlSessionModifierTest.java   
@Override
protected SqlSession getSqlSession() {
    return new DefaultSqlSession(this.configuration, this.executor);
}
项目:pinpoint    文件:DefaultSqlSessionIT.java   
@Override
protected SqlSession getSqlSession() {
    return new DefaultSqlSession(this.configuration, this.executor, false);
}