Пример #1
0
  /**
   * @param meta
   * @throws BirtException
   */
  private void addResultSetColumn(DataSetHandle dataSetHandle, IResultMetaData meta)
      throws BirtException {
    if (meta == null || !(dataSetHandle instanceof OdaDataSetHandle)) return;

    Set computedColumnNameSet = new HashSet();
    Iterator computedIter = dataSetHandle.computedColumnsIterator();
    while (computedIter.hasNext()) {
      ComputedColumnHandle handle = (ComputedColumnHandle) computedIter.next();
      computedColumnNameSet.add(handle.getName());
    }

    HashSet orgColumnNameSet = new HashSet();
    HashSet uniqueColumnNameSet = new HashSet();

    PropertyHandle handle = dataSetHandle.getPropertyHandle(DataSetHandle.RESULT_SET_PROP);
    for (int i = 1; i <= meta.getColumnCount(); i++) {
      OdaResultSetColumn rsColumn = new OdaResultSetColumn();

      String uniqueName;

      if (!computedColumnNameSet.contains(meta.getColumnName(i))) {
        uniqueName =
            MetaDataPopulator.getUniqueName(
                orgColumnNameSet, uniqueColumnNameSet, meta.getColumnName(i), i - 1);
        rsColumn.setColumnName(uniqueName);
        if (meta.getColumnType(i) != DataType.ANY_TYPE)
          rsColumn.setDataType(DataAdapterUtil.adapterToModelDataType(meta.getColumnType(i)));
        rsColumn.setNativeName(meta.getColumnName(i));
        rsColumn.setPosition(Integer.valueOf(i));

        handle.addItem(rsColumn);
        uniqueColumnNameSet.add(uniqueName);
      }
    }
  }
Пример #2
0
  /**
   * @param dataSetName
   * @return
   * @throws BirtException
   */
  private IResultMetaData getRealMetaData(DataSetHandle dataSetHandle) throws BirtException {
    IResultMetaData metaData = MetaDataPopulator.retrieveResultMetaData(dataSetHandle);

    if (metaData == null) metaData = getRuntimeMetaData(dataSetHandle);

    if (metaData != null && !(dataSetHandle instanceof ScriptDataSetHandle))
      clearUnusedData(dataSetHandle, metaData);
    return metaData;
  }
Пример #3
0
  private IResultMetaData getRuntimeMetaData(DataSetHandle dataSetHandle) throws BirtException {
    Map dataSetBindingMap = new HashMap();
    Map dataSourceBindingMap = new HashMap();
    DataSetHandle handle = null;
    if (sessionContext.getModuleHandle() != null
        && sessionContext.getModuleHandle().getAllDataSets() != null) {
      for (Object o : sessionContext.getModuleHandle().getAllDataSets()) {
        DataSetHandle dsh = (DataSetHandle) o;
        if (dsh.getQualifiedName().equals(dataSetHandle.getQualifiedName())) {
          handle = dsh;
          break;
        }
      }
    }

    // First clear all property bindings so that the data set can be executed against design time
    // properties
    clearPropertyBindingMap(handle, dataSetBindingMap, dataSourceBindingMap);
    try {
      QueryDefinition query = new QueryDefinition();
      query.setDataSetName(dataSetHandle.getQualifiedName());
      query.setMaxRows(1);
      query.setAutoBinding(true);

      IResultMetaData metaData =
          new QueryExecutionHelper(dataEngine, modelAdaptor, sessionContext, false, this.session)
              .executeQuery(query)
              .getResultMetaData();
      addResultSetColumn(dataSetHandle, metaData);

      if (MetaDataPopulator.needsUseResultHint(dataSetHandle, metaData)) {
        metaData =
            new QueryExecutionHelper(dataEngine, modelAdaptor, sessionContext, true, this.session)
                .executeQuery(query)
                .getResultMetaData();
      }
      return metaData;
    } finally {
      // restore property bindings
      resetPropertyBinding(handle, dataSetBindingMap, dataSourceBindingMap);
    }
  }