예제 #1
0
  private void closeStatement() {
    if (curStatement != null) {
      for (DBCResultSet resultSet : curResultSets) {
        resultSet.close();
      }
      curResultSets.clear();

      try {
        curStatement.close();
      } catch (Throwable e) {
        log.error("Error closing statement", e);
      }
      curStatement = null;
    }
  }
예제 #2
0
  private boolean fetchQueryData(
      DBCSession session,
      DBCResultSet resultSet,
      SQLQueryResult result,
      DBDDataReceiver dataReceiver,
      boolean updateStatistics)
      throws DBCException {
    if (dataReceiver == null) {
      // No data pump - skip fetching stage
      return false;
    }
    if (resultSet == null) {
      return false;
    }
    boolean keepCursor = keepStatementOpen();

    if (keepCursor) {
      curResultSets.add(resultSet);
    }
    DBRProgressMonitor monitor = session.getProgressMonitor();
    monitor.subTask("Fetch result set");
    long rowCount = 0;

    dataReceiver.fetchStart(session, resultSet, rsOffset, rsMaxRows);

    try {
      // Retrieve source entity
      if (result != null) {
        DBCResultSetMetaData rsMeta = resultSet.getMeta();
        String sourceName = null; // resultSet.getResultSetName();
        for (DBCAttributeMetaData attr : rsMeta.getAttributes()) {
          String entityName = attr.getEntityName();
          if (!CommonUtils.isEmpty(entityName)) {
            if (sourceName == null) {
              sourceName = entityName;
            } else if (!sourceName.equals(entityName)) {
              // Multiple source entities
              sourceName += "(+)";
              break;
            }
          }
        }
        /*
                        if (CommonUtils.isEmpty(sourceName)) {
                            try {
                                sourceName = resultSet.getResultSetName();
                            } catch (DBCException e) {
                                log.debug(e);
                            }
                        }
        */
        if (CommonUtils.isEmpty(sourceName)) {
          sourceName = "Result";
        }
        result.setResultSetName(sourceName);
      }
      long fetchStartTime = System.currentTimeMillis();

      // Fetch all rows
      while ((!hasLimits() || rowCount < rsMaxRows) && resultSet.nextRow()) {
        if (monitor.isCanceled()) {
          break;
        }
        rowCount++;

        if (rowCount > 0 && rowCount % 100 == 0) {
          monitor.subTask(rowCount + " rows fetched");
          monitor.worked(100);
        }

        dataReceiver.fetchRow(session, resultSet);
      }
      if (updateStatistics) {
        statistics.addFetchTime(System.currentTimeMillis() - fetchStartTime);
      }
    } finally {
      if (!keepCursor) {
        try {
          resultSet.close();
        } catch (Throwable e) {
          log.error("Error while closing resultset", e);
        }
      }
      try {
        dataReceiver.fetchEnd(session, resultSet);
      } catch (Throwable e) {
        log.error("Error while handling end of result set fetch", e);
      }
      dataReceiver.close();
    }

    if (result != null) {
      result.setRowCount(rowCount);
    }
    if (updateStatistics) {
      statistics.setRowsFetched(rowCount);
    }
    monitor.subTask(rowCount + " rows fetched");

    return true;
  }