当前位置: 首页>>代码示例>>Java>>正文


Java Executor类代码示例

本文整理汇总了Java中org.apache.ibatis.executor.Executor的典型用法代码示例。如果您正苦于以下问题:Java Executor类的具体用法?Java Executor怎么用?Java Executor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Executor类属于org.apache.ibatis.executor包,在下文中一共展示了Executor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intercept

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
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();
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:25,代码来源:SqlExplainInterceptor.java

示例2: executeQueryCount

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
@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;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:21,代码来源:PaginationHandler.java

示例3: RoutingStatementHandler

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
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());
    }

  }
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:18,代码来源:RoutingStatementHandler.java

示例4: BaseStatementHandler

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
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);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:BaseStatementHandler.java

示例5: openSessionFromDataSource

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:21,代码来源:DynamicSqlSessionFactory.java

示例6: preGenerateKey

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:wen866595,项目名称:MyBatis-batch,代码行数:21,代码来源:BatchStatementHandler.java

示例7: openSessionFromDataSource

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
/**
   * 源码解析: 从数据源创建会话
   *
   * @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();
  }
}
 
开发者ID:txazo,项目名称:mybatis,代码行数:31,代码来源:DefaultSqlSessionFactory.java

示例8: getObject

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
@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;
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:27,代码来源:ShardSqlSessionFactoryBean.java

示例9: intercept

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
@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();
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:26,代码来源:SqlExplainInterceptor.java

示例10: executeQueryCount

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
@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;
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:19,代码来源:PaginationHandler.java

示例11: openSessionFromDataSource

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
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();
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:21,代码来源:DefaultSqlSessionFactory.java

示例12: RoutingStatementHandler

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
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());
    }

  }
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:19,代码来源:RoutingStatementHandler.java

示例13: BaseStatementHandler

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
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);
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:22,代码来源:BaseStatementHandler.java

示例14: intercept

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
@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();
}
 
开发者ID:colin-lee,项目名称:mybatis-spring-support,代码行数:25,代码来源:PaginationAutoMapInterceptor.java

示例15: setUp

import org.apache.ibatis.executor.Executor; //导入依赖的package包/类
@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 } );
}
 
开发者ID:tguzik,项目名称:mybatis-metrics,代码行数:21,代码来源:InstrumentingInterceptorTest.java


注:本文中的org.apache.ibatis.executor.Executor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。