本文整理匯總了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 } );
}