本文整理汇总了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();
}
示例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;
}
示例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());
}
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
示例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());
}
}
示例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);
}
示例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();
}
示例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 } );
}