當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。