Ejemplo n.º 1
0
  /**
   * @param dataSetHandle
   * @param useCache
   * @return
   * @throws BirtException
   */
  IResultMetaData getDataSetMetaData(DataSetHandle dataSetHandle, boolean useCache)
      throws BirtException {
    if (dataSetHandle == null) {
      throw new AdapterException(ResourceConstants.DATASETHANDLE_NULL_ERROR);
    }

    if (useCache) {
      return getCachedMetaData(dataSetHandle.getCachedMetaDataHandle());
    } else {
      return getRealMetaData(dataSetHandle);
    }
  }
Ejemplo n.º 2
0
  /**
   * @param dataSetHandle
   * @param rsMeta
   * @return
   * @throws BirtException
   */
  private boolean needsSetCachedMetaData(DataSetHandle dataSetHandle, IResultMetaData rsMeta)
      throws BirtException {
    if (dataSetHandle.getCachedMetaDataHandle() == null
        || rsMeta == null
        || rsMeta.getColumnCount() == 0) return true;

    List list = getResultSetColumnHandles(dataSetHandle.getCachedMetaDataHandle());

    if (list.size() != rsMeta.getColumnCount()) return true;

    for (int i = 1; i <= rsMeta.getColumnCount(); i++) {
      ResultSetColumnHandle handle = (ResultSetColumnHandle) list.get(i - 1);

      if (handle.getColumnName() == null
          || !handle.getColumnName().equals(getColumnName(rsMeta, i))
          || !handle
              .getDataType()
              .equals(DataAdapterUtil.adapterToModelDataType(rsMeta.getColumnType(i)))) return true;
    }

    return false;
  }
Ejemplo n.º 3
0
  /**
   * @param dataSetHandle
   * @return
   * @throws BirtException
   */
  IResultMetaData refreshMetaData(DataSetHandle dataSetHandle, boolean holdEvent)
      throws BirtException {
    IResultMetaData rsMeta = null;
    try {
      rsMeta = this.getDataSetMetaData(dataSetHandle, false);
    } catch (BirtException e1) {
      // clear cache meta data
      if (holdEvent || !dataSetHandle.canEdit()) {
        CompatibilityUtil.updateResultSetinCachedMetaData(dataSetHandle, new ArrayList());
      } else {
        if (dataSetHandle.getCachedMetaDataHandle() != null)
          dataSetHandle.getCachedMetaDataHandle().getResultSet().clearValue();
        else dataSetHandle.setCachedMetaData(StructureFactory.createCachedMetaData());
      }
      throw e1;
    }

    if (needsSetCachedMetaData(dataSetHandle, rsMeta)) {
      List columnList = new ArrayList();
      if (rsMeta != null && rsMeta.getColumnCount() != 0) {
        for (int i = 1; i <= rsMeta.getColumnCount(); i++) {
          ResultSetColumn rsc = StructureFactory.createResultSetColumn();
          String columnName = getColumnName(rsMeta, i);
          if (columnName == null || columnName.trim().length() == 0) {
            // in some store procedure cases, column name is just empty,
            // then, we just use column name already saved in datasetHandle
            List list = dataSetHandle.getListProperty(IDataSetModel.RESULT_SET_PROP);
            ResultSetColumn column = (ResultSetColumn) list.get(i - 1);
            rsc.setColumnName(column.getColumnName());
          } else {
            rsc.setColumnName(columnName);
          }
          if (rsMeta.getColumnType(i) != DataType.ANY_TYPE)
            rsc.setDataType(DataAdapterUtil.adapterToModelDataType(rsMeta.getColumnType(i)));
          rsc.setPosition(Integer.valueOf(i));

          columnList.add(rsc);
        }
      }

      if (holdEvent || !dataSetHandle.canEdit()) {
        CompatibilityUtil.updateResultSetinCachedMetaData(dataSetHandle, columnList);
      } else {
        if (dataSetHandle.getCachedMetaDataHandle() != null) {
          List resultSetColumnHandles =
              getResultSetColumnHandles(dataSetHandle.getCachedMetaDataHandle());
          int i = 0;
          for (; i < columnList.size(); i++) {
            ResultSetColumn rsc = (ResultSetColumn) columnList.get(i);
            if (i < resultSetColumnHandles.size()) {
              // update if needed, avoid writing "any" type to
              // Model if old report contains "any" type
              ResultSetColumnHandle rsh = (ResultSetColumnHandle) resultSetColumnHandles.get(i);
              if (!rsh.getColumnName().equals(rsc.getColumnName())) {
                rsh.setColumnName(rsc.getColumnName());
              }
              if (!rsh.getDataType().equals(rsc.getDataType())) {
                rsh.setDataType(rsc.getDataType());
              }
            } else {
              // some columns are to be added
              dataSetHandle.getCachedMetaDataHandle().getResultSet().addItem(rsc);
            }
          }
          if (i < resultSetColumnHandles.size()) {
            // some columns are to be removed
            List toRemoved = resultSetColumnHandles.subList(i, resultSetColumnHandles.size());
            dataSetHandle.getCachedMetaDataHandle().getResultSet().removeItems(toRemoved);
          }
        } else {
          dataSetHandle.setCachedMetaData(StructureFactory.createCachedMetaData());

          for (int i = 0; i < columnList.size(); i++) {
            dataSetHandle
                .getCachedMetaDataHandle()
                .getResultSet()
                .addItem((ResultSetColumn) columnList.get(i));
          }
        }
      }
    }
    return rsMeta;
  }