Java Code Examples for org.apache.ibatis.executor.Executor

The following are top voted examples for showing how to use org.apache.ibatis.executor.Executor. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: mybatis-plus-mini   File: SqlExplainInterceptor.java   View source code 7 votes vote down vote up
public Object intercept(Invocation invocation) throws Throwable {
    /**
     * 处理 DELETE UPDATE 语句
     */
    MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
    if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
        Executor executor = (Executor) invocation.getTarget();
        Configuration configuration = ms.getConfiguration();
        Object parameter = invocation.getArgs()[1];
        BoundSql boundSql = ms.getBoundSql(parameter);
        Connection connection = executor.getTransaction().getConnection();
        String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
        if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
                && VersionUtils.compare(minMySQLVersion, databaseVersion)) {
            logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
            return invocation.proceed();
        }
        /**
         * 执行 SQL 分析
         */
        sqlExplain(configuration, ms, boundSql, connection, parameter);
    }
    return invocation.proceed();
}
 
Example 2
Project: azeroth   File: PaginationHandler.java   View source code 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private Long executeQueryCount(Executor executor, MappedStatement countMs, Object parameter,
                               BoundSql boundSql, RowBounds rowBounds,
                               ResultHandler resultHandler) throws IllegalAccessException,
        SQLException {
    CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT,
            boundSql);

    String orignSql = boundSql.getSql().replaceAll(";$", "");
    // count sql
    String countSql = PageSqlUtils.getCountSql(orignSql);

    BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql,
            boundSql.getParameterMappings(), parameter);
    // 执行 count 查询
    Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT,
            resultHandler, countKey, countBoundSql);
    Long count = (Long) ((List) countResultList).get(0);
    return count;
}
 
Example 3
Project: MybatisCode   File: RoutingStatementHandler.java   View source code 6 votes vote down vote up
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {

    switch (ms.getStatementType()) {
      case STATEMENT:
        delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case PREPARED:
        delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case CALLABLE:
        delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      default:
        throw new ExecutorException("Unknown statement type: " + ms.getStatementType());
    }

  }
 
Example 4
Project: MybatisCode   File: BaseStatementHandler.java   View source code 6 votes vote down vote up
protected BaseStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
  this.configuration = mappedStatement.getConfiguration();
  this.executor = executor;
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;

  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();

  if (boundSql == null) { // issue #435, get the key before calculating the statement
    generateKeys(parameterObject);
    boundSql = mappedStatement.getBoundSql(parameterObject);
  }

  this.boundSql = boundSql;

  this.parameterHandler = configuration.newParameterHandler(mappedStatement, parameterObject, boundSql);
  this.resultSetHandler = configuration.newResultSetHandler(executor, mappedStatement, rowBounds, parameterHandler, resultHandler, boundSql);
}
 
Example 5
Project: hsweb-framework   File: DynamicSqlSessionFactory.java   View source code 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 6
Project: MyBatis-batch   File: BatchStatementHandler.java   View source code 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected void preGenerateKey(PreparedStatement ps,
		PreparedStatementHandler preparedStatementHandler,
		Object parameterObject, MappedStatement mappedStatement,
		KeyGeneratorType keyGeneratorType)
				throws NoSuchFieldException, IllegalAccessException {
	Executor executor = (Executor) ReflectHelper
			.getValueByFieldName(preparedStatementHandler,
					"executor");

	KeyGenerator keyGenerator = mappedStatement
			.getKeyGenerator();
	for (Object oneParam : ((BatchParameter) parameterObject)
			.getData()) {
		((SelectKeyGenerator) keyGenerator)
				.processBefore(executor,
						mappedStatement, ps,
						oneParam);
	}
}
 
Example 7
Project: mybatis   File: DefaultSqlSessionFactory.java   View source code 6 votes vote down vote up
/**
   * 源码解析: 从数据源创建会话
   *
   * @param execType 执行类型
   * @param level 数据库隔离级别
   * @param autoCommit 是否自动提交
   * @return
   */
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);
    // 源码解析: 创建一个新的sql会话
    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 8
Project: mybatis   File: RoutingStatementHandler.java   View source code 6 votes vote down vote up
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {

    switch (ms.getStatementType()) {
      case STATEMENT:
        delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case PREPARED:
        delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case CALLABLE:
        delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      default:
        throw new ExecutorException("Unknown statement type: " + ms.getStatementType());
    }

  }
 
Example 9
Project: mybatis   File: BaseStatementHandler.java   View source code 6 votes vote down vote up
protected BaseStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
  this.configuration = mappedStatement.getConfiguration();
  this.executor = executor;
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;

  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();

  if (boundSql == null) { // issue #435, get the key before calculating the statement
    generateKeys(parameterObject);
    boundSql = mappedStatement.getBoundSql(parameterObject);
  }

  this.boundSql = boundSql;

  this.parameterHandler = configuration.newParameterHandler(mappedStatement, parameterObject, boundSql);
  this.resultSetHandler = configuration.newResultSetHandler(executor, mappedStatement, rowBounds, parameterHandler, resultHandler, boundSql);
}
 
Example 10
Project: shardy   File: ShardSqlSessionFactoryBean.java   View source code 6 votes vote down vote up
@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;
}
 
Example 11
Project: mybatis-plus   File: SqlExplainInterceptor.java   View source code 6 votes vote down vote up
@Override
public Object intercept(Invocation invocation) throws Throwable {
    /**
     * 处理 DELETE UPDATE 语句
     */
    MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
    if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
        Executor executor = (Executor) invocation.getTarget();
        Configuration configuration = ms.getConfiguration();
        Object parameter = invocation.getArgs()[1];
        BoundSql boundSql = ms.getBoundSql(parameter);
        Connection connection = executor.getTransaction().getConnection();
        String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
        if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
                && VersionUtils.compare(minMySQLVersion, databaseVersion)) {
            logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
            return invocation.proceed();
        }
        /**
         * 执行 SQL 分析
         */
        sqlExplain(configuration, ms, boundSql, connection, parameter);
    }
    return invocation.proceed();
}
 
Example 12
Project: jeesuite-libs   File: PaginationHandler.java   View source code 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private Long executeQueryCount(Executor executor, MappedStatement countMs,
           Object parameter, BoundSql boundSql,
		RowBounds rowBounds, ResultHandler resultHandler) throws IllegalAccessException, SQLException {
	CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql);
	
	String orignSql = boundSql.getSql().replaceAll(";$", "");
	// count sql
	String countSql = PageSqlUtils.getCountSql(orignSql);
	
	BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(),
			parameter);
	// 执行 count 查询
	Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey,
			countBoundSql);
	Long count = (Long) ((List) countResultList).get(0);
	return count;
}
 
Example 13
Project: mybaties   File: DefaultSqlSessionFactory.java   View source code 6 votes vote down vote up
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 14
Project: mybaties   File: RoutingStatementHandler.java   View source code 6 votes vote down vote up
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {

    //根据语句类型,委派到不同的语句处理器(STATEMENT|PREPARED|CALLABLE)
    switch (ms.getStatementType()) {
      case STATEMENT:
        delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case PREPARED:
        delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case CALLABLE:
        delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      default:
        throw new ExecutorException("Unknown statement type: " + ms.getStatementType());
    }

  }
 
Example 15
Project: mybaties   File: BaseStatementHandler.java   View source code 6 votes vote down vote up
protected BaseStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
  this.configuration = mappedStatement.getConfiguration();
  this.executor = executor;
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;

  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();

  if (boundSql == null) { // issue #435, get the key before calculating the statement
    generateKeys(parameterObject);
    boundSql = mappedStatement.getBoundSql(parameterObject);
  }

  this.boundSql = boundSql;

  //生成parameterHandler
  this.parameterHandler = configuration.newParameterHandler(mappedStatement, parameterObject, boundSql);
  //生成resultSetHandler
  this.resultSetHandler = configuration.newResultSetHandler(executor, mappedStatement, rowBounds, parameterHandler, resultHandler, boundSql);
}
 
Example 16
Project: mybatis-spring-support   File: PaginationAutoMapInterceptor.java   View source code 6 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Object intercept(Invocation invocation) throws Throwable {
  final String name = invocation.getMethod().getName();
  final Object target = invocation.getTarget();
  if (target instanceof StatementHandler) {
    pagination(invocation, (StatementHandler) target);
  } else if (target instanceof Executor) {
    autoMap(invocation, name);
  } else if (target instanceof ResultSetHandler) {
    Object result = invocation.proceed();
    if (result instanceof List) {
      Page page = PAGE_THREAD_LOCAL.get();
      if (page != null) {
        page.addAll((List) result);
        PAGE_THREAD_LOCAL.remove();
        return page;
      }
    }
    return result;
  }

  return invocation.proceed();
}
 
Example 17
Project: play   File: RoutingStatementHandler.java   View source code 6 votes vote down vote up
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {

    switch (ms.getStatementType()) {
      case STATEMENT:
        delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case PREPARED:
        delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case CALLABLE:
        delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      default:
        throw new ExecutorException("Unknown statement type: " + ms.getStatementType());
    }

  }
 
Example 18
Project: play   File: BaseStatementHandler.java   View source code 6 votes vote down vote up
protected BaseStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
  this.configuration = mappedStatement.getConfiguration();
  this.executor = executor;
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;

  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();

  if (boundSql == null) { // issue #435, get the key before calculating the statement
    generateKeys(parameterObject);
    boundSql = mappedStatement.getBoundSql(parameterObject);
  }

  this.boundSql = boundSql;

  this.parameterHandler = configuration.newParameterHandler(mappedStatement, parameterObject, boundSql);
  this.resultSetHandler = configuration.newResultSetHandler(executor, mappedStatement, rowBounds, parameterHandler, resultHandler, boundSql);
}
 
Example 19
Project: mybatis-metrics   File: InstrumentingInterceptorTest.java   View source code 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.metricRegistry = new MetricRegistry();
    this.interceptor = new InstrumentingInterceptor( metricRegistry );
    this.fakeExecutor = mock( Executor.class );
    this.fakeStatement = new MappedStatement.Builder( mock( Configuration.class ),
                                                      "statement id",
                                                      mock( SqlSource.class ),
                                                      SqlCommandType.SELECT ).lang( mock( LanguageDriver.class ) )
                                                                             .build();
    this.invocation = new Invocation( fakeExecutor,
                                      Executor.class.getDeclaredMethod( "query",
                                                                        MappedStatement.class,
                                                                        Object.class,
                                                                        RowBounds.class,
                                                                        ResultHandler.class,
                                                                        CacheKey.class,
                                                                        BoundSql.class ),
                                      new Object[] { fakeStatement, null, null, null, null, null } );
}
 
Example 20
Project: QuickProject   File: SortListInterceptor.java   View source code 6 votes vote down vote up
@Override
public Object intercept(Invocation invocation) throws Throwable {
       List<Sort> sortList = getSortList();
       if (sortList == null || sortList.size() == 0) {
           return invocation.proceed();
       }

       Executor executor = (Executor) invocation.getTarget();
       Object[] args = invocation.getArgs();
       MappedStatement ms = (MappedStatement) args[0];
       Object parameter = args[1];
       RowBounds rowBounds = (RowBounds) args[2];
       ResultHandler resultHandler = (ResultHandler) args[3];

       // 计算修改BoundSql
       BoundSql boundSql = ms.getBoundSql(parameter);
       MetaObject boundSqlHandler = MetaObject.forObject(boundSql, new DefaultObjectFactory(), new DefaultObjectWrapperFactory());
       Dialect dialect = DialectParser.parse(ms.getConfiguration());
       String sql = (String) boundSqlHandler.getValue("sql");
       sql = dialect.addSortString(sql, sortList);
       boundSqlHandler.setValue("sql", sql);

       // 继续执行原来的代码
       CacheKey key = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
       return executor.query(ms, parameter, rowBounds, resultHandler, key, boundSql);
}
 
Example 21
Project: Mybatis-PageHelper   File: PageInterceptor.java   View source code 6 votes vote down vote up
/**
 * 执行自动生成的 count 查询
 *
 * @param executor
 * @param countMs
 * @param parameter
 * @param boundSql
 * @param rowBounds
 * @param resultHandler
 * @return
 * @throws IllegalAccessException
 * @throws SQLException
 */
private Long executeAutoCount(Executor executor, MappedStatement countMs,
                               Object parameter, BoundSql boundSql,
                               RowBounds rowBounds, ResultHandler resultHandler) throws IllegalAccessException, SQLException {
    Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField.get(boundSql);
    //创建 count 查询的缓存 key
    CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql);
    //调用方言获取 count sql
    String countSql = dialect.getCountSql(countMs, boundSql, parameter, rowBounds, countKey);
    //countKey.update(countSql);
    BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(), parameter);
    //当使用动态 SQL 时,可能会产生临时的参数,这些参数需要手动设置到新的 BoundSql 中
    for (String key : additionalParameters.keySet()) {
        countBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
    }
    //执行 count 查询
    Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql);
    Long count = (Long) ((List) countResultList).get(0);
    return count;
}
 
Example 22
Project: mybatis-3   File: RoutingStatementHandler.java   View source code 6 votes vote down vote up
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {

    switch (ms.getStatementType()) {
      case STATEMENT:
        delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case PREPARED:
        delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      case CALLABLE:
        delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
        break;
      default:
        throw new ExecutorException("Unknown statement type: " + ms.getStatementType());
    }

  }
 
Example 23
Project: mybatis-3   File: BaseStatementHandler.java   View source code 6 votes vote down vote up
protected BaseStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
  this.configuration = mappedStatement.getConfiguration();
  this.executor = executor;
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;

  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();

  if (boundSql == null) { // issue #435, get the key before calculating the statement
    generateKeys(parameterObject);
    boundSql = mappedStatement.getBoundSql(parameterObject);
  }

  this.boundSql = boundSql;

  this.parameterHandler = configuration.newParameterHandler(mappedStatement, parameterObject, boundSql);
  this.resultSetHandler = configuration.newResultSetHandler(executor, mappedStatement, rowBounds, parameterHandler, resultHandler, boundSql);
}
 
Example 24
Project: tasfe-framework   File: DynamicDataSourcePlugin.java   View source code 5 votes vote down vote up
@Override
public Object plugin(Object target) {
    if (target instanceof Executor) {
        return Plugin.wrap(target, this);
    }
    return target;
}
 
Example 25
Project: tasfe-framework   File: PageInterceptor.java   View source code 5 votes vote down vote up
/**
 * 只拦截Executor
 *
 * @param target
 * @return
 */
public Object plugin(Object target) {
    if (target instanceof Executor) {
        return Plugin.wrap(target, this);
    } else {
        return target;
    }
}
 
Example 26
Project: aaden-pay   File: PagePluging.java   View source code 5 votes vote down vote up
public Object plugin(Object target) {
	if (target instanceof Executor) {
		return Plugin.wrap(target, this);
	} else {
		return target;
	}
}
 
Example 27
Project: mybatis-dao   File: PagePlugin.java   View source code 5 votes vote down vote up
@Override
public Object plugin(Object target) {
	// TODO Auto-generated method stub
	if (target instanceof Executor) {
		return Plugin.wrap(target, this);
	} else {
		return target;
	}
}
 
Example 28
Project: spring-boot-starter-dao   File: CustomPageInterceptor.java   View source code 5 votes vote down vote up
@Override
public Object plugin(Object target) {  
	if (target instanceof Executor) {
        return Plugin.wrap(target, this);
    } else {
        return target;
    }
}
 
Example 29
Project: azeroth   File: MybatisInterceptor.java   View source code 5 votes vote down vote up
@Override
public Object plugin(Object target) {
    if (target instanceof Executor) {
        return Plugin.wrap(target, this);
    } else {
        return target;
    }

}
 
Example 30
Project: angit   File: DynamicPlugin.java   View source code 5 votes vote down vote up
@Override
public Object plugin(Object target) {
    if (target instanceof Executor) {
        return Plugin.wrap(target, this);
    } else {
        return target;
    }
}
 
Example 31
Project: ipayquery   File: PageHelper.java   View source code 5 votes vote down vote up
/**
 * 只拦截Executor
 *
 * @param target
 * @return
 */
/* @Override */
public Object plugin(Object target) {
    if (target instanceof Executor) {
        return Plugin.wrap(target, this);
    } else {
        return target;
    }
}
 
Example 32
Project: mumu-core   File: MultipleMybatisInteInterceptor.java   View source code 5 votes vote down vote up
@Override
public Object plugin(Object target) {
    if (target instanceof Executor) {
        return Plugin.wrap(target, this);
    } else {
        return target;
    }
}
 
Example 33
Project: MybatisCode   File: DefaultSqlSessionFactory.java   View source code 5 votes vote down vote up
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);
    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 34
Project: MybatisCode   File: DefaultSqlSession.java   View source code 5 votes vote down vote up
@Override
public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) {
  try {
    MappedStatement ms = configuration.getMappedStatement(statement);
    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 35
Project: MybatisCode   File: DefaultResultSetHandler.java   View source code 5 votes vote down vote up
public DefaultResultSetHandler(Executor executor, MappedStatement mappedStatement, ParameterHandler parameterHandler, ResultHandler<?> resultHandler, BoundSql boundSql,
    RowBounds rowBounds) {
  this.executor = executor;
  this.configuration = mappedStatement.getConfiguration();
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;
  this.parameterHandler = parameterHandler;
  this.boundSql = boundSql;
  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();
  this.reflectorFactory = configuration.getReflectorFactory();
  this.resultHandler = resultHandler;
}
 
Example 36
Project: MybatisCode   File: ResultLoader.java   View source code 5 votes vote down vote up
public ResultLoader(Configuration config, Executor executor, MappedStatement mappedStatement, Object parameterObject, Class<?> targetType, CacheKey cacheKey, BoundSql boundSql) {
  this.configuration = config;
  this.executor = executor;
  this.mappedStatement = mappedStatement;
  this.parameterObject = parameterObject;
  this.targetType = targetType;
  this.objectFactory = configuration.getObjectFactory();
  this.cacheKey = cacheKey;
  this.boundSql = boundSql;
  this.resultExtractor = new ResultExtractor(configuration, objectFactory);
  this.creatorThreadId = Thread.currentThread().getId();
}
 
Example 37
Project: MybatisCode   File: ResultLoader.java   View source code 5 votes vote down vote up
private <E> List<E> selectList() throws SQLException {
  Executor localExecutor = executor;
  if (Thread.currentThread().getId() != this.creatorThreadId || localExecutor.isClosed()) {
    localExecutor = newExecutor();
  }
  try {
    return localExecutor.<E> query(mappedStatement, parameterObject, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER, cacheKey, boundSql);
  } finally {
    if (localExecutor != executor) {
      localExecutor.close(false);
    }
  }
}
 
Example 38
Project: MybatisCode   File: ResultLoader.java   View source code 5 votes vote down vote up
private Executor newExecutor() {
  final Environment environment = configuration.getEnvironment();
  if (environment == null) {
    throw new ExecutorException("ResultLoader could not load lazily.  Environment was not configured.");
  }
  final DataSource ds = environment.getDataSource();
  if (ds == null) {
    throw new ExecutorException("ResultLoader could not load lazily.  DataSource was not configured.");
  }
  final TransactionFactory transactionFactory = environment.getTransactionFactory();
  final Transaction tx = transactionFactory.newTransaction(ds, null, false);
  return configuration.newExecutor(tx, ExecutorType.SIMPLE);
}
 
Example 39
Project: MybatisCode   File: DefaultResultSetHandlerTest.java   View source code 5 votes vote down vote up
/**
 * Contrary to the spec, some drivers require case-sensitive column names when getting result.
 * 
 * @see <a href="http://code.google.com/p/mybatis/issues/detail?id=557">Issue 557</a>
 */
@Test
public void shouldRetainColumnNameCase() throws Exception {

  final MappedStatement ms = getMappedStatement();

  final Executor executor = null;
  final ParameterHandler parameterHandler = null;
  final ResultHandler resultHandler = null;
  final BoundSql boundSql = null;
  final RowBounds rowBounds = new RowBounds(0, 100);
  final DefaultResultSetHandler fastResultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds);

  when(stmt.getResultSet()).thenReturn(rs);
  when(rs.getMetaData()).thenReturn(rsmd);
  when(rs.getType()).thenReturn(ResultSet.TYPE_FORWARD_ONLY);
  when(rs.next()).thenReturn(true).thenReturn(false);
  when(rs.getInt("CoLuMn1")).thenReturn(100);
  when(rs.wasNull()).thenReturn(false);
  when(rsmd.getColumnCount()).thenReturn(1);
  when(rsmd.getColumnLabel(1)).thenReturn("CoLuMn1");
  when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER);
  when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName());
  when(stmt.getConnection()).thenReturn(conn);
  when(conn.getMetaData()).thenReturn(dbmd);
  when(dbmd.supportsMultipleResultSets()).thenReturn(false); // for simplicity.

  final List<Object> results = fastResultSetHandler.handleResultSets(stmt);
  assertEquals(1, results.size());
  assertEquals(Integer.valueOf(100), ((HashMap) results.get(0)).get("cOlUmN1"));
}
 
Example 40
Project: easy-mybatis   File: PageInterceptor.java   View source code 5 votes vote down vote up
/**
 * 只拦截Executor
 *
 * @param target
 * @return
 */
@Override
public Object plugin(Object target) {
    if (target instanceof Executor) {
        return Plugin.wrap(target, this);
    } else {
        return target;
    }
}