コード例 #1
0
 FunctionCursorResultSet(Session session, ResultSet result) {
   this.session = session;
   this.result = result;
   try {
     this.meta = result.getMetaData();
   } catch (SQLException e) {
     throw DbException.convert(e);
   }
 }
コード例 #2
0
 private int getRedoPos() {
   try {
     byte[] data = ZKUtil.getDataAndWatch(watcher, ZooKeeperAdmin.DDL_REDO_TABLE_NODE);
     if (data != null && data.length > 0) {
       return Bytes.toInt(data);
     }
     return getDefaultStartPos();
   } catch (Exception e) {
     throw DbException.convert(e);
   }
 }
コード例 #3
0
  public synchronized void refresh() {
    int newRedoPos = getRedoPos();
    if (newRedoPos != redoPos) {
      int startPos = redoPos;
      int stopPos = newRedoPos;

      if (newRedoPos < startPos) { // Master重新计数了
        startPos = getDefaultStartPos();
      }
      try {
        table.redoRecords(startPos, stopPos);
        redoPos = newRedoPos;
      } catch (Exception e) {
        throw DbException.convert(e);
      }
    }
  }
コード例 #4
0
  private int execute(Prepared p) {
    beginTransaction(p);

    boolean isTopTransaction = false;
    boolean isNestedTransaction = false;
    Session session = p.getSession();

    try {
      if (!p.isLocal() && p.isBatch()) {
        if (session.isAutoCommit()) {
          session.setAutoCommit(false);
          isTopTransaction = true;
        } else {
          isNestedTransaction = true;
          session.addSavepoint(TransactionCommand.INTERNAL_SAVEPOINT);
        }
      }
      int updateCount = 0;
      switch (p.getType()) {
        case CommandInterface.INSERT:
          updateCount = nestedRouter.executeInsert((Insert) p);
          break;
        case CommandInterface.UPDATE:
          updateCount = nestedRouter.executeUpdate((Update) p);
          break;
        case CommandInterface.DELETE:
          updateCount = nestedRouter.executeDelete((Delete) p);
          break;
        case CommandInterface.MERGE:
          updateCount = nestedRouter.executeMerge((Merge) p);
          break;
      }
      if (isTopTransaction) session.commit(false);
      return updateCount;
    } catch (Exception e) {
      if (isTopTransaction) session.rollback();

      // 嵌套事务出错时提前rollback
      if (isNestedTransaction) session.rollbackToSavepoint(TransactionCommand.INTERNAL_SAVEPOINT);

      throw DbException.convert(e);
    } finally {
      if (isTopTransaction) session.setAutoCommit(true);
    }
  }
コード例 #5
0
 public boolean next() {
   row = null;
   try {
     if (result != null && result.next()) {
       int columnCount = meta.getColumnCount();
       values = new Value[columnCount];
       for (int i = 0; i < columnCount; i++) {
         int type = DataType.convertSQLTypeToValueType(meta.getColumnType(i + 1));
         values[i] = DataType.readValue(session, result, i + 1, type);
       }
     } else {
       values = null;
     }
   } catch (SQLException e) {
     throw DbException.convert(e);
   }
   return values != null;
 }