mybatis源码分析-处理结果集ResultSet

299 阅读1分钟

入口

核心步骤
1.先从数据库查询数据
2.然后处理数据(即结果集ResultSet)

核心步骤

1.先到连接池
2.再到Oralce

连接池druid-DruidPooledResultSet

public final class DruidPooledResultSet extends PoolableWrapper implements ResultSet {
private final ResultSet rs;
private final DruidPooledStatement stmt;
public boolean next() throws SQLException {
  try {
    boolean moreRows = this.rs.next(); //有没有下一行数据,返回值是布尔类型
    if (moreRows) {
      ++this.cursorIndex;
      if (this.cursorIndex > this.fetchRowCount) {
        this.fetchRowCount = this.cursorIndex;
      }
    }

    return moreRows;
  } catch (Throwable var2) {
    throw this.checkException(var2);
  }
}

oracle

public boolean next() throws SQLException {
  synchronized(this.connection) {
    boolean var2 = true; //初始值是true
    this.isServerCursorPeeked = true;
    PhysicalConnection var3 = this.statement.connection;
    SQLException var4;
    if (this.explicitly_closed) {
      var4 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 10, "next");
      var4.fillInStackTrace();
      throw var4;
    } else if (var3 != null && var3.lifecycle == 1) {
      if (this.statement.closed) {
        var4 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 9, "next");
        var4.fillInStackTrace();
        throw var4;
      } else if (this.statement.sqlKind.isPlsqlOrCall()) {
        var4 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 166, "next");
        var4.fillInStackTrace();
        throw var4;
      } else if (this.closed) {
        return false;
      } else {
        ++this.statement.currentRow;
        ++this.statement.totalRowsVisited;
        if (this.statement.maxRows != 0 && this.statement.totalRowsVisited > this.statement.maxRows) {
          this.internal_close(false);
          --this.statement.currentRow;
          this.statement.totalRowsVisited = 0;
          this.sqlWarning = DatabaseError.addSqlWarning(this.sqlWarning, 275);
          return false;
        } else {
          if (this.statement.currentRow >= this.statement.validRows) {
            var2 = this.close_or_fetch_from_next(false);
          }

          if (var2 && var3.useFetchSizeWithLongColumn) {
            this.statement.reopenStreams();
          }

          if (!var2) {
            --this.statement.currentRow;
            this.statement.totalRowsVisited = 0;
          }

          return var2; //true
        }
      }
    } else {
      var4 = DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 8, "next");
      var4.fillInStackTrace();
      throw var4;
    }
  }
}