@NotNull
 @Override
 public String getColumnId() {
   DBCExecutionContext context = getExecutionContext();
   DBCAttributeMetaData metaAttribute = binding.getMetaAttribute();
   return DBUtils.getSimpleQualifiedName(
       context == null ? null : context.getDataSource().getContainer().getName(),
       metaAttribute.getEntityName(),
       metaAttribute.getName());
 }
 /**
  * Attribute index in result set
  *
  * @return attribute index (zero based)
  */
 @Override
 public int getOrdinalPosition() {
   return metaAttribute.getOrdinalPosition();
 }
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof DBDAttributeBindingMeta) {
     DBCAttributeMetaData cmpMeta = ((DBDAttributeBindingMeta) obj).metaAttribute;
     return CommonUtils.equalObjects(metaAttribute.getName(), cmpMeta.getName())
         && CommonUtils.equalObjects(metaAttribute.getLabel(), cmpMeta.getLabel())
         && CommonUtils.equalObjects(metaAttribute.getEntityName(), cmpMeta.getEntityName())
         && metaAttribute.getOrdinalPosition() == cmpMeta.getOrdinalPosition()
         && metaAttribute.getTypeID() == cmpMeta.getTypeID()
         && CommonUtils.equalObjects(metaAttribute.getTypeName(), cmpMeta.getTypeName());
   }
   return false;
 }
 /** Attribute name */
 @NotNull
 public String getName() {
   return metaAttribute.getName();
 }
 /** Attribute label */
 @NotNull
 public String getLabel() {
   return metaAttribute.getLabel();
 }
Ejemplo n.º 6
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;
  }