*入口-dubbo业务方法
@Override
public List<AccounttypeBusicode> selectAllAccounttypeBusicode() {
return qrcodeManagerService.selectAllAccounttypeBusicode();
}
*spring-事务拦截器
/**
* CGLIB-based {@link AopProxy} implementation for the Spring AOP framework.
*
* <p>Objects of this type should be obtained through proxy factories,
* configured by an {@link AdvisedSupport} object. This class is internal
* to Spring's AOP framework and need not be used directly by client code.
*
* <p>{@link DefaultAopProxyFactory} will automatically create CGLIB-based
* proxies if necessary, for example in case of proxying a target class
* (see the {@link DefaultAopProxyFactory attendant javadoc} for details).
*
* <p>Proxies created using this class are thread-safe if the underlying
* (target) class is thread-safe.
*
* @author Rod Johnson
* @author Rob Harrop
* @author Juergen Hoeller
* @author Ramnivas Laddad
* @author Chris Beams
* @author Dave Syer
* @see org.springframework.cglib.proxy.Enhancer
* @see AdvisedSupport#setProxyTargetClass
* @see DefaultAopProxyFactory
*/
@SuppressWarnings("serial")
class CglibAopProxy implements AopProxy, Serializable {
@Override
@Nullable
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
Object oldProxy = null;
boolean setProxyContext = false;
Object target = null;
TargetSource targetSource = this.advised.getTargetSource();
try {
if (this.advised.exposeProxy) {
// Make invocation available if necessary.
oldProxy = AopContext.setCurrentProxy(proxy);
setProxyContext = true;
}
// Get as late as possible to minimize the time we "own" the target, in case it comes from a pool...
target = targetSource.getTarget();
Class<?> targetClass = (target != null ? target.getClass() : null);
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);
Object retVal;
// Check whether we only have one InvokerInterceptor: that is,
// no real advice, but just reflective invocation of the target.
if (chain.isEmpty() && Modifier.isPublic(method.getModifiers())) {
// We can skip creating a MethodInvocation: just invoke the target directly.
// Note that the final invoker must be an InvokerInterceptor, so we know
// it does nothing but a reflective operation on the target, and no hot
// swapping or fancy proxying.
Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);
retVal = methodProxy.invoke(target, argsToUse); //
}
else {
// We need to create a method invocation...
retVal = new CglibMethodInvocation(proxy, target, method, args, targetClass, chain, methodProxy).proceed(); //
}
retVal = processReturnType(proxy, target, method, retVal); //
return retVal;
}
finally {
if (target != null && !targetSource.isStatic()) {
targetSource.releaseTarget(target);
}
if (setProxyContext) {
// Restore old proxy.
AopContext.setCurrentProxy(oldProxy);
}
}
}
*service类-方法
@Transactional(propagation = Propagation.SUPPORTS, transactionManager = "managerTransactionManager") //先进入spring事务拦截器
public List<Country> selectAllCountry() {
return countryMapper.selectAll(); //然后才执行业务方法
}
*mybatis
进入mybatis代理类
MapperProxy
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
if (Object.class.equals(method.getDeclaringClass())) {
return method.invoke(this, args);
} else if (isDefaultMethod(method)) {
return invokeDefaultMethod(proxy, method, args);
}
} catch (Throwable t) {
throw ExceptionUtil.unwrapThrowable(t);
}
final MapperMethod mapperMethod = cachedMapperMethod(method);
return mapperMethod.execute(sqlSession, args); //执行查询
}
MapperMethod
public Object execute(SqlSession sqlSession, Object[] args) {
Object result;
switch (command.getType()) { //增删查改类型
case INSERT: {
Object param = method.convertArgsToSqlCommandParam(args);
result = rowCountResult(sqlSession.insert(command.getName(), param));
break;
}
case UPDATE: {
Object param = method.convertArgsToSqlCommandParam(args);
result = rowCountResult(sqlSession.update(command.getName(), param));
break;
}
case DELETE: {
Object param = method.convertArgsToSqlCommandParam(args);
result = rowCountResult(sqlSession.delete(command.getName(), param));
break;
}
case SELECT: //查询
if (method.returnsVoid() && method.hasResultHandler()) {
executeWithResultHandler(sqlSession, args);
result = null;
} else if (method.returnsMany()) { //查询多行数据
result = executeForMany(sqlSession, args);
} else if (method.returnsMap()) {
result = executeForMap(sqlSession, args);
} else if (method.returnsCursor()) {
result = executeForCursor(sqlSession, args);
} else {
Object param = method.convertArgsToSqlCommandParam(args);
result = sqlSession.selectOne(command.getName(), param);
if (method.returnsOptional() &&
(result == null || !method.getReturnType().equals(result.getClass()))) {
result = Optional.ofNullable(result);
}
}
break;
case FLUSH:
result = sqlSession.flushStatements();
break;
default:
throw new BindingException("Unknown execution method for: " + command.getName());
}
if (result == null && method.getReturnType().isPrimitive() && !method.returnsVoid()) {
throw new BindingException("Mapper method '" + command.getName()
+ " attempted to return null from a method with a primitive return type (" + method.getReturnType() + ").");
}
return result;
}
private <E> Object executeForMany(SqlSession sqlSession, Object[] args) {
List<E> result;
Object param = method.convertArgsToSqlCommandParam(args);
if (method.hasRowBounds()) {
RowBounds rowBounds = method.extractRowBounds(args);
result = sqlSession.<E>selectList(command.getName(), param, rowBounds);
} else {
result = sqlSession.<E>selectList(command.getName(), param); //查询
}
// issue #510 Collections & arrays support
if (!method.getReturnType().isAssignableFrom(result.getClass())) {
if (method.getReturnType().isArray()) {
return convertToArray(result);
} else {
return convertToDeclaredCollection(sqlSession.getConfiguration(), result);
}
}
return result;
}
SqlSessionTemplate
/**
* {@inheritDoc}
*/
@Override
public <E> List<E> selectList(String statement, Object parameter) {
return this.sqlSessionProxy.selectList(statement, parameter);
}
SqlSessionTemplate的内部类SqlSessionInterceptor拦截器
/**
* Proxy needed to route MyBatis method calls to the proper SqlSession got
* from Spring's Transaction Manager
* It also unwraps exceptions thrown by {@code Method#invoke(Object, Object...)} to
* pass a {@code PersistenceException} to the {@code PersistenceExceptionTranslator}.
*/
private class SqlSessionInterceptor implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
SqlSession sqlSession = getSqlSession(
SqlSessionTemplate.this.sqlSessionFactory,
SqlSessionTemplate.this.executorType,
SqlSessionTemplate.this.exceptionTranslator);
try {
Object result = method.invoke(sqlSession, args); //调用
if (!isSqlSessionTransactional(sqlSession, SqlSessionTemplate.this.sqlSessionFactory)) {
// force commit even on non-dirty sessions because some databases require
// a commit/rollback before calling close()
sqlSession.commit(true);
}
return result;
} catch (Throwable t) {
Throwable unwrapped = unwrapThrowable(t);
if (SqlSessionTemplate.this.exceptionTranslator != null && unwrapped instanceof PersistenceException) {
// release the connection to avoid a deadlock if the translator is no loaded. See issue #22
closeSqlSession(sqlSession, SqlSessionTemplate.this.sqlSessionFactory);
sqlSession = null;
Throwable translated = SqlSessionTemplate.this.exceptionTranslator.translateExceptionIfPossible((PersistenceException) unwrapped);
if (translated != null) {
unwrapped = translated;
}
}
throw unwrapped;
} finally {
if (sqlSession != null) {
closeSqlSession(sqlSession, SqlSessionTemplate.this.sqlSessionFactory);
}
}
}
}
DefaultSqlSession
@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();
}
}
分页插件Plugin
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
Set<Method> methods = signatureMap.get(method.getDeclaringClass());
if (methods != null && methods.contains(method)) {
return interceptor.intercept(new Invocation(target, method, args)); //
}
return method.invoke(target, args); //调用
} catch (Exception e) {
throw ExceptionUtil.unwrapThrowable(e);
}
}
*第三方分页插件jar-PageInterceptor
用于mybatis分页,基于mybatis plug机制实现。
@Override
public Object intercept(Invocation invocation) throws Throwable {
try {
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement) args[0];
Object parameter = args[1];
RowBounds rowBounds = (RowBounds) args[2];
ResultHandler resultHandler = (ResultHandler) args[3];
Executor executor = (Executor) invocation.getTarget();
CacheKey cacheKey;
BoundSql boundSql;
//由于逻辑关系,只会进入一次
if (args.length == 4) {
//4 个参数时
boundSql = ms.getBoundSql(parameter);
cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
} else {
//6 个参数时
cacheKey = (CacheKey) args[4];
boundSql = (BoundSql) args[5];
}
checkDialectExists();
List resultList;
//调用方法判断是否需要进行分页,如果不需要,直接返回结果
if (!dialect.skip(ms, parameter, rowBounds)) {
//判断是否需要进行 count 查询
if (dialect.beforeCount(ms, parameter, rowBounds)) {
//查询总数
Long count = count(executor, ms, parameter, rowBounds, resultHandler, boundSql);
//处理查询总数,返回 true 时继续分页查询,false 时直接返回
if (!dialect.afterCount(count, parameter, rowBounds)) {
//当查询总数为 0 时,直接返回空的结果
return dialect.afterPage(new ArrayList(), parameter, rowBounds);
}
}
resultList = ExecutorUtil.pageQuery(dialect, executor,
ms, parameter, rowBounds, resultHandler, boundSql, cacheKey);
} else {
//执行查询
//rowBounds用参数值,不使用分页插件处理时,仍然支持默认的内存分页
resultList = executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql);
}
return dialect.afterPage(resultList, parameter, rowBounds);
} finally {
if(dialect != null){
dialect.afterAll();
}
}
}
*公司自定义插件-CatMybatisPlugin
实际上就是cat自带的mybatis监控,直接复制过来的,用于监控。
public Object intercept(Invocation invocation) throws Throwable {
MappedStatement mappedStatement = this.getStatement(invocation);
String methodName = this.getMethodName(mappedStatement);
Transaction t = Cat.newTransaction("SQL", methodName);
String sql = this.getSql(invocation, mappedStatement);
SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
Cat.logEvent("SQL.Method", sqlCommandType.name().toLowerCase(), "0", sql);
String url = this.getSQLDatabaseUrlByStatement(mappedStatement);
Cat.logEvent("SQL.Database", url);
Cat.logEvent("SQL.Type", "mybatis");
return this.doFinish(invocation, t);
}
*mybatis-Invocation
又回到mybatis
public Object proceed() throws InvocationTargetException, IllegalAccessException {
return method.invoke(target, args);
}
CachingExecutor
@Override
public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql)
throws SQLException {
Cache cache = ms.getCache();
if (cache != null) {
flushCacheIfRequired(ms);
if (ms.isUseCache() && resultHandler == null) {
ensureNoOutParams(ms, boundSql);
@SuppressWarnings("unchecked")
List<E> list = (List<E>) tcm.getObject(cache, key);
if (list == null) {
list = delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
tcm.putObject(cache, key, list); // issue #578 and #116
}
return list;
}
}
return delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql); //执行查询
}
BaseExecutor
/**
* @author Clinton Begin
*/
public abstract class BaseExecutor implements Executor {
@SuppressWarnings("unchecked")
@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
if (closed) {
throw new ExecutorException("Executor was closed.");
}
if (queryStack == 0 && ms.isFlushCacheRequired()) {
clearLocalCache();
}
List<E> list;
try {
queryStack++;
list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;
if (list != null) {
handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
} else {
list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql); //执行查询
}
} finally {
queryStack--;
}
if (queryStack == 0) {
for (DeferredLoad deferredLoad : deferredLoads) {
deferredLoad.load();
}
// issue #601
deferredLoads.clear();
if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
// issue #482
clearLocalCache();
}
}
return list;
}
private <E> List<E> queryFromDatabase(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
List<E> list;
localCache.putObject(key, EXECUTION_PLACEHOLDER);
try {
list = doQuery(ms, parameter, rowBounds, resultHandler, boundSql); //执行查询
} finally {
localCache.removeObject(key);
}
localCache.putObject(key, list);
if (ms.getStatementType() == StatementType.CALLABLE) {
localOutputParameterCache.putObject(key, parameter);
}
return list;
}
SimpleExecutor
/**
* @author Clinton Begin
*/
public class SimpleExecutor extends BaseExecutor {
@Override
public <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
Statement stmt = null;
try {
Configuration configuration = ms.getConfiguration();
StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler, boundSql);
stmt = prepareStatement(handler, ms.getStatementLog()); //获取预处理sql语句
return handler.query(stmt, resultHandler); //执行查询
} finally {
closeStatement(stmt);
}
}
RoutingStatementHandler
@Override
public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {
return delegate.<E>query(statement, resultHandler);
}
PreparedStatementHandler
/**
* @author Clinton Begin
*/
public class PreparedStatementHandler extends BaseStatementHandler {
@Override
public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {
PreparedStatement ps = (PreparedStatement) statement;
ps.execute(); //执行查询
return resultSetHandler.handleResultSets(ps);
}
打印日志拦截器PreparedStatementLogger
/**
* PreparedStatement proxy to add logging
*
* @author Clinton Begin
* @author Eduardo Macarron
*
*/
public final class PreparedStatementLogger extends BaseJdbcLogger implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] params) throws Throwable {
try {
if (Object.class.equals(method.getDeclaringClass())) {
return method.invoke(this, params);
}
if (EXECUTE_METHODS.contains(method.getName())) {
if (isDebugEnabled()) {
debug("Parameters: " + getParameterValueString(), true);
}
clearColumnInfo();
if ("executeQuery".equals(method.getName())) {
ResultSet rs = (ResultSet) method.invoke(statement, params);
return rs == null ? null : ResultSetLogger.newInstance(rs, statementLog, queryStack);
} else {
return method.invoke(statement, params); //调用
}
} else if (SET_METHODS.contains(method.getName())) {
if ("setNull".equals(method.getName())) {
setColumn(params[0], null);
} else {
setColumn(params[0], params[1]);
}
return method.invoke(statement, params);
} else if ("getResultSet".equals(method.getName())) {
ResultSet rs = (ResultSet) method.invoke(statement, params);
return rs == null ? null : ResultSetLogger.newInstance(rs, statementLog, queryStack);
} else if ("getUpdateCount".equals(method.getName())) {
int updateCount = (Integer) method.invoke(statement, params);
if (updateCount != -1) {
debug(" Updates: " + updateCount, false);
}
return updateCount;
} else {
return method.invoke(statement, params);
}
} catch (Throwable t) {
throw ExceptionUtil.unwrapThrowable(t);
}
}
*连接池druid-DruidPooledPreparedStatement
public class DruidPooledPreparedStatement extends DruidPooledStatement implements PreparedStatement {
public boolean execute() throws SQLException {
this.checkOpen();
this.incrementExecuteCount();
this.transactionRecord(this.sql);
this.oracleSetRowPrefetch();
this.conn.beforeExecute();
boolean var1;
try {
var1 = this.stmt.execute(); //执行查询
} catch (Throwable var5) {
this.errorCheck(var5);
throw this.checkException(var5);
} finally {
this.conn.afterExecute();
}
return var1;
}
*oracle预处理语句-OraclePreparedStatementWrapper
即oracle的jdbc实现,其实就是oracle服务器的客户端。
class OraclePreparedStatementWrapper extends OracleStatementWrapper implements OraclePreparedStatement {
public boolean execute() throws SQLException {
return this.preparedStatement.execute();
}
abstract class OraclePreparedStatement extends OracleStatement implements oracle.jdbc.internal.OraclePreparedStatement, ScrollRsetStatement {
public boolean execute() throws SQLException {
synchronized(this.connection) {
this.executionType = 3;
this.executeInternal(); //执行查询
return this.sqlKind.isSELECT();
}
}
int executeInternal() throws SQLException {
this.noMoreUpdateCounts = false;
this.checkSum = 0L;
this.checkSumComputationFailure = false;
this.ensureOpen();
if (this.currentRank > 0 && this.m_batchStyle == 2) {
SQLException var3 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 81, "batch must be either executed or cleared");
var3.fillInStackTrace();
throw var3;
} else {
boolean var1 = this.userRsetType == 1;
this.prepareForNewResults(true, false); //
this.processCompletedBindRow(this.sqlKind.isSELECT() ? 1 : this.batch, false); //
if (!var1 && !this.scrollRsetTypeSolved) {
return this.doScrollPstmtExecuteUpdate() + this.prematureBatchCount;
} else {
this.doExecuteWithTimeout(); //执行查询
boolean var2 = this.prematureBatchCount != 0 && this.validRows > 0;
if (!var1) {
this.currentResultSet = new OracleResultSetImpl(this.connection, this);
this.scrollRset = ResultSetUtil.createScrollResultSet(this, this.currentResultSet, this.realRsetType);
if (!this.connection.accumulateBatchResult) {
var2 = false;
}
}
if (var2) {
this.validRows += this.prematureBatchCount;
this.prematureBatchCount = 0;
}
if (this.sqlKind.isOTHER()) {
this.needToParse = true;
}
return this.validRows;
}
}
}
abstract class OracleStatement implements oracle.jdbc.internal.OracleStatement, ScrollRsetStatement {
void doExecuteWithTimeout() throws SQLException {
try {
this.cleanOldTempLobs();
this.connection.registerHeartbeat();
this.rowsProcessed = 0;
SQLException var1;
if (this.sqlKind.isSELECT()) {
if (this.connection.j2ee13Compliant && this.executionType == 2) {
var1 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 129);
var1.fillInStackTrace();
throw var1;
}
this.connection.needLine();
if (!this.isOpen) {
this.connection.open(this);
this.isOpen = true;
}
if (this.queryTimeout != 0) {
try {
this.connection.getTimeout().setTimeout((long)(this.queryTimeout * 1000), this);
this.executeMaybeDescribe();
} finally {
this.connection.getTimeout().cancelTimeout();
}
} else {
this.executeMaybeDescribe(); //执行查询
}
this.checkValidRowsStatus();
if (this.serverCursor) {
this.adjustGotLastBatch();
}
} else {
if (this.connection.j2ee13Compliant && !this.sqlKind.isPlsqlOrCall() && this.executionType == 1) {
var1 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 128);
var1.fillInStackTrace();
throw var1;
}
++this.currentRank;
if (this.currentRank >= this.batch) {
try {
this.connection.needLine();
this.cancelLock.enterExecuting();
if (!this.isOpen) {
this.connection.open(this);
this.isOpen = true;
}
if (this.queryTimeout != 0) {
this.connection.getTimeout().setTimeout((long)(this.queryTimeout * 1000), this);
}
this.executeForRows(false);
} catch (SQLException var14) {
this.needToParse = true;
if (this.batch > 1) {
this.clearBatch();
int[] var2;
int var3;
if (this.numberOfExecutedElementsInBatch != -1 && this.numberOfExecutedElementsInBatch < this.batch) {
var2 = new int[this.numberOfExecutedElementsInBatch];
for(var3 = 0; var3 < var2.length; ++var3) {
var2[var3] = -2;
}
} else {
var2 = new int[this.batch];
for(var3 = 0; var3 < var2.length; ++var3) {
var2[var3] = -3;
}
}
BatchUpdateException var17 = DatabaseError.createBatchUpdateException(var14, var2.length, var2);
var17.fillInStackTrace();
throw var17;
}
this.resetCurrentRowBinders();
throw var14;
} finally {
if (this.queryTimeout != 0) {
this.connection.getTimeout().cancelTimeout();
}
this.currentRank = 0;
this.cancelLock.exitExecuting();
this.checkValidRowsStatus();
}
}
}
} catch (SQLException var16) {
this.resetOnExceptionDuringExecute();
throw var16;
}
this.connection.registerHeartbeat();
}
void executeMaybeDescribe() throws SQLException {
boolean var1 = true;
if (this.rowPrefetchChanged) {
if (this.streamList == null && this.rowPrefetch != this.definesBatchSize) {
this.needToPrepareDefineBuffer = true;
}
this.rowPrefetchChanged = false;
}
if (!this.needToPrepareDefineBuffer) {
if (this.accessors == null) {
this.needToPrepareDefineBuffer = true;
} else if (this.columnsDefinedByUser) {
this.needToPrepareDefineBuffer = !this.checkAccessorsUsable();
}
}
boolean var2 = false;
try {
this.cancelLock.enterExecuting();
if (this.needToPrepareDefineBuffer) {
if (!this.columnsDefinedByUser) {
this.executeForDescribe(); //执行查询
var2 = true;
if (this.aFetchWasDoneDuringDescribe) {
var1 = false;
}
}
if (this.needToPrepareDefineBuffer) {
this.prepareAccessors();
}
}
int var3 = this.accessors.length;
for(int var4 = this.numberOfDefinePositions; var4 < var3; ++var4) {
Accessor var5 = this.accessors[var4];
if (var5 != null) {
var5.rowSpaceIndicator = null;
}
}
if (var1) {
this.executeForRows(var2);
}
} catch (SQLException var9) {
this.needToParse = true;
throw var9;
} finally {
this.cancelLock.exitExecuting();
}
}
T4CPreparedStatement
class T4CPreparedStatement extends OraclePreparedStatement {
void executeForDescribe() throws SQLException {
this.t4Connection.assertLoggedOn("oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe");
try {
if (this.t4Connection.useFetchSizeWithLongColumn) {
this.doOall8(true, true, true, true, false);
} else {
this.doOall8(true, true, false, true, this.definedColumnType != null); //执行查询
}
} catch (SQLException var7) {
throw var7;
} catch (IOException var8) {
((T4CConnection)this.connection).handleIOException(var8);
SQLException var2 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), var8);
var2.fillInStackTrace();
throw var2;
} finally {
this.rowsProcessed = this.t4Connection.all8.rowsProcessed;
this.validRows = this.t4Connection.all8.getNumRows();
}
this.needToParse = false;
if (this.connection.calculateChecksum) {
if (this.validRows > 0) {
this.calculateCheckSum();
} else if (this.rowsProcessed > 0) {
CRC64 var10000 = PhysicalConnection.CHECKSUM;
long var1 = CRC64.updateChecksum(this.checkSum, (long)this.rowsProcessed);
this.checkSum = var1;
}
}
if (this.definedColumnType == null) {
this.implicitDefineForLobPrefetchDone = false;
}
this.aFetchWasDoneDuringDescribe = false;
if (this.t4Connection.all8.aFetchWasDone) {
this.aFetchWasDoneDuringDescribe = true;
this.rowPrefetchInLastFetch = this.rowPrefetch;
}
for(int var10 = 0; var10 < this.numberOfDefinePositions; ++var10) {
this.accessors[var10].initMetadata();
}
this.needToPrepareDefineBuffer = false;
}
void doOall8(boolean var1, boolean var2, boolean var3, boolean var4, boolean var5) throws SQLException, IOException {
if (var1 || var4 || !var2) {
this.oacdefSent = null;
}
this.t4Connection.assertLoggedOn("oracle.jdbc.driver.T4CPreparedStatement.doOall8");
if (this.sqlKind == SqlKind.UNINITIALIZED) {
SQLException var14 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 439, "sqlKind = " + this.sqlKind);
var14.fillInStackTrace();
throw var14;
} else {
if (var3) {
this.rowPrefetchInLastFetch = this.rowPrefetch;
}
int var6 = this.numberOfDefinePositions;
if (this.sqlKind.isDML()) {
var6 = 0;
}
int var7;
if (this.accessors != null) {
for(var7 = 0; var7 < this.accessors.length; ++var7) {
if (this.accessors[var7] != null) {
this.accessors[var7].lastRowProcessed = 0;
}
}
}
if (this.outBindAccessors != null) {
for(var7 = 0; var7 < this.outBindAccessors.length; ++var7) {
if (this.outBindAccessors[var7] != null) {
this.outBindAccessors[var7].lastRowProcessed = 0;
}
}
}
if (this.returnParamAccessors != null) {
for(var7 = 0; var7 < this.returnParamAccessors.length; ++var7) {
if (this.returnParamAccessors[var7] != null) {
this.returnParamAccessors[var7].lastRowProcessed = 0;
}
}
}
int var11;
int var12;
if (this.bindIndicators != null) {
var7 = ((this.bindIndicators[this.bindIndicatorSubRange + 3] & '\uffff') << 16) + (this.bindIndicators[this.bindIndicatorSubRange + 4] & '\uffff');
int var8 = 0;
if (this.ibtBindChars != null) {
var8 = this.ibtBindChars.length * this.connection.conversion.cMaxCharSize;
}
for(int var9 = 0; var9 < this.numberOfBindPositions; ++var9) {
int var10 = this.bindIndicatorSubRange + 5 + 10 * var9;
var11 = this.bindIndicators[var10 + 2] & '\uffff';
if (var11 != 0) {
var12 = this.bindIndicators[var10 + 9] & '\uffff';
if (var12 == 2) {
var8 = Math.max(var11 * this.connection.conversion.maxNCharSize, var8);
} else {
var8 = Math.max(var11 * this.connection.conversion.cMaxCharSize, var8);
}
}
}
if (this.tmpBindsByteArray == null) {
this.tmpBindsByteArray = new byte[var8];
} else if (this.tmpBindsByteArray.length < var8) {
this.tmpBindsByteArray = null;
this.tmpBindsByteArray = new byte[var8];
}
} else {
this.tmpBindsByteArray = null;
}
int[] var15 = this.definedColumnType;
int[] var18 = this.definedColumnSize;
int[] var16 = this.definedColumnFormOfUse;
if (var5 && var4 && this.sqlObject.includeRowid) {
var15 = new int[this.definedColumnType.length + 1];
System.arraycopy(this.definedColumnType, 0, var15, 1, this.definedColumnType.length);
var15[0] = -8;
var18 = new int[this.definedColumnSize.length + 1];
System.arraycopy(this.definedColumnSize, 0, var18, 1, this.definedColumnSize.length);
var16 = new int[this.definedColumnFormOfUse.length + 1];
System.arraycopy(this.definedColumnFormOfUse, 0, var16, 1, this.definedColumnFormOfUse.length);
}
this.allocateTmpByteArray();
T4C8Oall var17 = this.t4Connection.all8;
this.t4Connection.sendPiggyBackedMessages();
try {
//执行查询
var17.doOALL(var1, var2, var3, var4, var5, this.sqlKind, this.cursorId, this.sqlObject.getSqlBytes(this.processEscapes, this.convertNcharLiterals), this.rowPrefetch, this.outBindAccessors, this.numberOfBindPositions, this.accessors, var6, this.bindBytes, this.bindChars, this.bindIndicators, this.bindIndicatorSubRange, this.connection.conversion, this.tmpBindsByteArray, this.parameterStream, this.parameterDatum, this.parameterOtype, this, this.ibtBindBytes, this.ibtBindChars, this.ibtBindIndicators, this.oacdefSent, var15, var18, var16, this.registration);
var11 = var17.getCursorId();
if (var11 != 0) {
this.cursorId = var11;
}
this.oacdefSent = var17.oacdefBindsSent;
} catch (SQLException var13) {
var12 = var17.getCursorId();
if (var12 != 0) {
this.cursorId = var12;
}
if (var13.getErrorCode() != DatabaseError.getVendorCode(110)) {
throw var13;
}
this.sqlWarning = DatabaseError.addSqlWarning(this.sqlWarning, 110);
}
}
}
T4C8Oall
final class T4C8Oall extends T4CTTIfun {
void doOALL(boolean var1, boolean var2, boolean var3, boolean var4, boolean var5, SqlKind var6, int var7, byte[] var8, int var9, Accessor[] var10, int var11, Accessor[] var12, int var13, byte[] var14, char[] var15, short[] var16, int var17, DBConversion var18, byte[] var19, InputStream[][] var20, byte[][][] var21, OracleTypeADT[][] var22, OracleStatement var23, byte[] var24, char[] var25, short[] var26, T4CTTIoac[] var27, int[] var28, int[] var29, int[] var30, NTFDCNRegistration var31) throws SQLException, IOException {
this.typeOfStatement = var6;
this.cursor = var7;
this.sqlStmt = var1 ? var8 : EMPTY_BYTES;
this.rowsToFetch = var9;
this.outBindAccessors = var10;
this.numberOfBindPositions = var11;
this.definesAccessors = var12;
this.definesLength = var13;
this.bindBytes = var14;
this.bindChars = var15;
this.bindIndicators = var16;
this.bindIndicatorSubRange = var17;
this.conversion = var18;
this.tmpBindsByteArray = var19;
this.parameterStream = var20;
this.parameterDatum = var21;
this.parameterOtype = var22;
this.oracleStatement = var23;
this.ibtBindBytes = var24;
this.ibtBindChars = var25;
this.ibtBindIndicators = var26;
this.oacdefBindsSent = var27;
this.definedColumnType = var28;
this.definedColumnSize = var29;
this.definedColumnFormOfUse = var30;
this.registration = var31;
this.dbCharSet = var18.getServerCharSetId();
this.NCharSet = var18.getNCharSetId();
int var32 = 0;
if (this.bindIndicators != null) {
var32 = ((this.bindIndicators[this.bindIndicatorSubRange + 3] & '\uffff') << 16) + (this.bindIndicators[this.bindIndicatorSubRange + 4] & '\uffff');
}
SQLException var40;
if (var8 == null) {
var40 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 431);
var40.fillInStackTrace();
throw var40;
} else if (!this.typeOfStatement.isDML() && var32 > 1) {
var40 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 433);
var40.fillInStackTrace();
throw var40;
} else {
this.rowsProcessed = 0;
this.options = 0L;
this.plsql = this.typeOfStatement.isPlsqlOrCall();
this.sendBindsDefinition = false;
if (this.receiveState != 0) {
this.receiveState = 0;
}
this.rxh.init();
this.rxd.init();
this.oer.init();
if (var5) {
this.initDefinesDefinition();
}
if (this.numberOfBindPositions > 0 && this.bindIndicators != null) {
if (this.oacdefBindsSent == null) {
this.oacdefBindsSent = new T4CTTIoac[this.numberOfBindPositions];
}
this.sendBindsDefinition = this.initBindsDefinition(this.oacdefBindsSent);
}
this.options = this.setOptions(var1, var2, var3, var5);
if ((this.options & 1L) > 0L) {
this.al8i4[0] = 1L;
} else {
this.al8i4[0] = 0L;
}
if (!this.plsql && !this.typeOfStatement.isOTHER()) {
if (var4) {
if (var3 && this.oracleStatement.connection.useFetchSizeWithLongColumn) {
this.al8i4[1] = (long)this.rowsToFetch;
} else {
this.al8i4[1] = 0L;
}
} else if (this.typeOfStatement.isDML()) {
this.al8i4[1] = var32 == 0 ? (long)this.oracleStatement.batch : (long)var32;
} else if (var3 && !var4) {
this.al8i4[1] = (long)this.rowsToFetch;
} else {
this.al8i4[1] = 0L;
}
} else {
this.al8i4[1] = 1L;
}
if (this.typeOfStatement.isSELECT()) {
this.al8i4[7] = 1L;
} else {
this.al8i4[7] = 0L;
}
long var33 = this.oracleStatement.inScn;
int var35 = (int)var33;
int var36 = (int)(var33 >> 32);
this.al8i4[5] = (long)var35;
this.al8i4[6] = (long)var36;
this.rowsProcessed = 0;
this.aFetchWasDone = false;
this.rxd.setNumberOfColumns(this.definesLength);
if ((this.options & 64L) != 0L && (this.options & 32L) == 0L && (this.options & 1L) == 0L && (this.options & 8L) == 0L && (this.options & 16L) == 0L && !this.oracleStatement.needToSendOalToFetch) {
this.setFunCode((short)5);
} else {
this.setFunCode((short)94);
}
this.nonFatalIOExceptions = null;
this.doRPC(); //执行查询
if ((this.options & 32L) != 0L) {
this.oracleStatement.inScn = 0L;
}
this.ibtBindIndicators = null;
this.ibtBindChars = null;
this.ibtBindBytes = null;
this.tmpBindsByteArray = null;
this.outBindAccessors = null;
this.bindBytes = null;
this.bindChars = null;
this.bindIndicators = null;
this.oracleStatement = null;
if (this.nonFatalIOExceptions != null) {
IOException var37 = (IOException)this.nonFatalIOExceptions.get(0);
try {
SQLException var38 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 266);
var38.fillInStackTrace();
throw var38;
} catch (SQLException var39) {
var39.initCause(var37);
throw var39;
}
}
}
}
T4CTTIfun
abstract class T4CTTIfun extends T4CTTIMsg {
final void doRPC() throws IOException, SQLException {
if (this.getTTCCode() == 17) {
SQLException var12 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 401);
var12.fillInStackTrace();
throw var12;
} else {
for(int var1 = 0; var1 < 5; ++var1) {
this.init();
this.marshalFunHeader();
try {
this.connection.pipeState = 1;
this.marshal();
this.connection.pipeState = 2;
this.receive(); //从服务器读数据
break;
} catch (SQLException var10) {
SQLException var2 = var10;
synchronized(this.connection.cancelInProgressLockForThin) {
if (var2.getErrorCode() == 1013 || this.connection.cancelInProgressFlag && var2.getMessage() != null && var2.getMessage().contains("ORA-01013")) {
this.connection.cancelInProgressFlag = false;
this.connection.redoCursorClose();
if ((this.funCode == 15 || this.funCode == 12 || this.funCode == 13 || this.funCode == 14 || this.funCode == 59) && (this.oer.callNumber != this.connection.currentTTCSeqNumber || this.connection.statementCancel)) {
continue;
}
}
}
throw var10;
} finally {
this.connection.pipeState = -1;
}
}
}
}
从服务器读数据
private void receive() throws SQLException, IOException {
this.receiveState = 1;
SQLException var1 = null;
label249:
while(true) {
while(true) {
try {
short var2 = this.meg.unmarshalUB1();
this.ttilist.add(new Short(var2));
switch(var2) {
case 4:
this.processEOCS();
this.oer.init();
this.oer.unmarshal();
try {
this.processError();
} catch (SQLException var14) {
var1 = var14;
}
break label249;
case 5:
case 10:
case 13:
case 17:
case 18:
case 20:
case 22:
default:
SQLException var24 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 401, this.ttilist.toString());
var24.fillInStackTrace();
throw var24;
case 6:
this.readRXH();
this.rxhProcessed = true;
break;
case 7:
this.receiveState = 2;
if (this.readRXD()) {
this.receiveState = 3;
return;
}
this.receiveState = 1;
break;
case 8:
if (this.rpaProcessed) {
SQLException var19 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 401);
var19.fillInStackTrace();
throw var19;
}
this.readRPA();
try {
this.processRPA();
} catch (SQLException var16) {
var1 = var16;
}
this.rpaProcessed = true;
break;
case 9:
this.processEOCS();
if (this.connection.getTTCVersion() >= 3) {
short var23 = (short)this.meg.unmarshalUB2();
this.connection.endToEndECIDSequenceNumber = var23;
}
break label249;
case 11:
this.readIOV();
this.iovProcessed = true;
break;
case 12:
this.processSLG();
break;
case 14:
this.readLOBD();
break;
case 15:
this.oer.init();
this.oer.unmarshalWarning();
try {
this.oer.processWarning();
} catch (SQLWarning var15) {
this.connection.setWarnings(DatabaseError.addSqlWarning(this.connection.getWarnings(), var15));
}
break;
case 16:
this.readDCB();
break;
case 19:
this.meg.marshalUB1((short)19);
break;
case 21:
this.readBVC();
break;
case 23:
byte var3 = (byte)this.meg.unmarshalUB1();
int var4 = this.meg.unmarshalUB2();
byte var5 = (byte)this.meg.unmarshalUB1();
int var6;
if (var3 == 1) {
for(var6 = 0; var6 < var4; ++var6) {
T4CTTIidc var22 = new T4CTTIidc(this.connection);
var22.unmarshal();
}
} else if (var3 == 2) {
for(var6 = 0; var6 < var4; ++var6) {
short var21 = this.meg.unmarshalUB1();
}
} else if (var3 != 3 && var3 != 4) {
if (var3 == 5) {
T4CTTIkvarr var20 = new T4CTTIkvarr(this.connection);
var20.unmarshal();
} else if (var3 == 6) {
for(var6 = 0; var6 < var4; ++var6) {
NTFXSEvent var7 = new NTFXSEvent(this.connection);
this.connection.notify(var7);
}
}
}
}
} catch (BreakNetException var17) {
} finally {
this.connection.sentCancel = false;
}
}
}
this.receiveState = 0;
if (var1 != null) {
throw var1;
}
}
调用栈
invoke:58, MapperProxy (org.apache.ibatis.binding)
selectAll:-1, $Proxy85 (com.sun.proxy)
selectAllCountry:85, QrcodeManagerService (com.yspay.manager.service)
invoke:-1, QrcodeManagerService$$FastClassBySpringCGLIB$$e814fefd (com.xxx.manager.service)
invoke:218, MethodProxy (org.springframework.cglib.proxy)
invokeJoinpoint:749, CglibAopProxy$CglibMethodInvocation (org.springframework.aop.framework)
proceed:163, ReflectiveMethodInvocation (org.springframework.aop.framework)
proceedWithInvocation:-1, 1611632860 (org.springframework.transaction.interceptor.TransactionInterceptor$$Lambda$558)
invokeWithinTransaction:294, TransactionAspectSupport (org.springframework.transaction.interceptor)
invoke:98, TransactionInterceptor (org.springframework.transaction.interceptor)
proceed:186, ReflectiveMethodInvocation (org.springframework.aop.framework)
intercept:688, CglibAopProxy$DynamicAdvisedInterceptor (org.springframework.aop.framework)
selectAllCountry:-1, QrcodeManagerService$$EnhancerBySpringCGLIB$$3e68eaf (com.xxx.manager.service)
selectAllCountry:39, QrcodeManager (com.xxx.manager.remoteserver)
invokeMethod:-1, Wrapper1 (com.alibaba.dubbo.common.bytecode)
doInvoke:47, JavassistProxyFactory$1 (com.alibaba.dubbo.rpc.proxy.javassist)
invoke:76, AbstractProxyInvoker (com.alibaba.dubbo.rpc.proxy)
invoke:52, DelegateProviderMetaDataInvoker (com.alibaba.dubbo.config.invoker)
invoke:56, InvokerWrapper (com.alibaba.dubbo.rpc.protocol)
invoke:62, ExceptionFilter (com.alibaba.dubbo.rpc.filter)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:75, MonitorFilter (com.alibaba.dubbo.monitor.support)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:42, TimeoutFilter (com.alibaba.dubbo.rpc.filter)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:11, AppNameAppendFilter (com.eptok.log.rpc.dubbo)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:78, TraceFilter (com.alibaba.dubbo.rpc.protocol.dubbo.filter)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:84, AccessLogExtFilter (yspay.qrcode.common.filter.dubbo)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:82, CatTransaction (com.eptok.log.rpc.dubbo)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:73, ContextFilter (com.alibaba.dubbo.rpc.filter)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:112, GenericFilter (com.alibaba.dubbo.rpc.filter)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:38, ClassLoaderFilter (com.alibaba.dubbo.rpc.filter)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
invoke:38, EchoFilter (com.alibaba.dubbo.rpc.filter)
invoke:72, ProtocolFilterWrapper$1 (com.alibaba.dubbo.rpc.protocol)
reply:104, DubboProtocol$1 (com.alibaba.dubbo.rpc.protocol.dubbo)
handleRequest:96, HeaderExchangeHandler (com.alibaba.dubbo.remoting.exchange.support.header)
received:173, HeaderExchangeHandler (com.alibaba.dubbo.remoting.exchange.support.header)
received:51, DecodeHandler (com.alibaba.dubbo.remoting.transport)
run:57, ChannelEventRunnable (com.alibaba.dubbo.remoting.transport.dispatcher)
runWorker:1149, ThreadPoolExecutor (java.util.concurrent)
run:624, ThreadPoolExecutor$Worker (java.util.concurrent)
run:748, Thread (java.lang)