コード例 #1
0
ファイル: DataSourceQuery.java プロジェクト: lukehan/birt
  private IResultClass mergeResultHint(List modelResultHints, IResultClass meta) {
    if (modelResultHints == null || modelResultHints.isEmpty()) return meta;
    IResultClass newResultClass;
    try {
      newResultClass = copyResultClass(meta);
    } catch (Exception ex) {
      return meta;
    }
    boolean changed = false;
    int count = newResultClass.getFieldCount();
    try {
      for (int i = 1; i <= count; i++) {
        String fieldName = newResultClass.getFieldName(i);
        Class odaType = newResultClass.getFieldMetaData(i).getDataType();
        for (int j = 0; j < modelResultHints.size(); j++) {
          if (((IColumnDefinition) modelResultHints.get(j)).getColumnName().equals(fieldName)) {
            int apiType = ((IColumnDefinition) modelResultHints.get(j)).getDataType();
            if (apiType > 0 && DataTypeUtil.toApiDataType(odaType) != apiType) {
              newResultClass.getFieldMetaData(i).setDataType(DataType.getClass(apiType));
              changed = true;
            }
            break;
          }
        }
      }
    } catch (Exception ex) {
    }

    if (changed) return newResultClass;
    else return meta;
  }
コード例 #2
0
ファイル: DataSourceQuery.java プロジェクト: lukehan/birt
  /**
   * @param design
   * @param odaStatement
   * @return
   * @throws DataException
   */
  private IResultClass getMetaData(IOdaDataSetDesign design, PreparedStatement odaStatement)
      throws DataException {
    IResultClass result = null;
    if (design != null) {
      if (canAccessResultSetByName(design)) {
        try {
          result = odaStatement.getMetaData(design.getPrimaryResultSetName());
        } catch (DataException e) {
          throw new DataException(
              ResourceConstants.ERROR_HAPPEN_WHEN_RETRIEVE_RESULTSET,
              design.getPrimaryResultSetName());
        }

      } else if (canAccessResultSetByNumber(design)) {
        try {
          result = odaStatement.getMetaData(design.getPrimaryResultSetNumber());
        } catch (DataException e) {
          throw new DataException(
              ResourceConstants.ERROR_HAPPEN_WHEN_RETRIEVE_RESULTSET,
              design.getPrimaryResultSetNumber());
        }
      }
    }
    if (result == null) result = odaStatement.getMetaData();

    if (design != null) {
      List hintList = design.getResultSetHints();
      for (int i = 0; i < hintList.size(); i++) {
        IColumnDefinition columnDefinition = (IColumnDefinition) hintList.get(i);
        for (int j = 1; j <= result.getFieldCount(); j++) {
          ResultFieldMetadata resultFieldMetadata = result.getFieldMetaData(j);
          if (columnDefinition.getColumnName().equals(resultFieldMetadata.getName())) {
            resultFieldMetadata.setAlias(columnDefinition.getAlias());
            resultFieldMetadata.setAnalysisType(columnDefinition.getAnalysisType());
            resultFieldMetadata.setAnalysisColumn(columnDefinition.getAnalysisColumn());
            resultFieldMetadata.setIndexColumn(columnDefinition.isIndexColumn());
            resultFieldMetadata.setCompressedColumn(columnDefinition.isCompressedColumn());
            break;
          }
        }
      }
    }
    return result;
  }
コード例 #3
0
ファイル: DataSourceQuery.java プロジェクト: lukehan/birt
  private IResultClass copyResultClass(IResultClass meta) throws DataException {
    List<ResultFieldMetadata> list = new ArrayList<ResultFieldMetadata>();
    for (int i = 1; i <= meta.getFieldCount(); i++) {
      if (!meta.getFieldName(i).equals(ExprMetaUtil.POS_NAME)) {
        int m_driverPosition = meta.getFieldMetaData(i).getDriverPosition();
        String m_name = meta.getFieldMetaData(i).getName();
        String m_label = meta.getFieldMetaData(i).getLabel();
        Class m_dataType = meta.getFieldMetaData(i).getDataType();
        String m_nativeTypeName = meta.getFieldMetaData(i).getNativeTypeName();
        boolean m_isCustom = meta.getFieldMetaData(i).isCustom();
        Class m_driverProvidedDataType = meta.getFieldMetaData(i).getDriverProvidedDataType();
        int m_analysisType = meta.getFieldMetaData(i).getAnalysisType();
        String m_analysisColumn = meta.getFieldMetaData(i).getAnalysisColumn();
        boolean m_indexColumn = meta.getFieldMetaData(i).isIndexColumn();
        boolean m_compressedColumn = meta.getFieldMetaData(i).isCompressedColumn();

        ResultFieldMetadata metadata =
            new ResultFieldMetadata(
                m_driverPosition,
                m_name,
                m_label,
                m_dataType,
                m_nativeTypeName,
                m_isCustom,
                m_analysisType,
                m_analysisColumn,
                m_indexColumn,
                m_compressedColumn);
        metadata.setDriverProvidedDataType(m_driverProvidedDataType);
        metadata.setAlias(meta.getFieldMetaData(i).getAlias());

        list.add(metadata);
      }
    }
    IResultClass resultClass = new ResultClass(list);

    return resultClass;
  }
コード例 #4
0
  /**
   * Remove old temp computed column metadatas from cache file and add new metadatas.
   *
   * @throws DataException
   */
  private void processResultClass() throws DataException {
    List metadataList = new ArrayList();
    this.realColumnCount = 0;

    ResultFieldMetadata metadata = null;
    int i = 0;
    for (i = 0; i < rsMeta.getFieldCount(); i++) {
      if (!isTempComputedColumn(rsMeta.getFieldName(i + 1))) {
        metadata =
            new ResultFieldMetadata(
                0,
                rsMeta.getFieldName(i + 1),
                rsMeta.getFieldLabel(i + 1),
                rsMeta.getFieldValueClass(i + 1),
                rsMeta.getFieldNativeTypeName(i + 1),
                rsMeta.isCustomField(i + 1),
                rsMeta.getAnalysisType(i + 1),
                rsMeta.getAnalysisColumn(i + 1),
                rsMeta.isIndexColumn(i + 1),
                rsMeta.isCompressedColumn(i + 1));
        metadata.setAlias(rsMeta.getFieldAlias(i + 1));
        metadataList.add(metadata);
        realColumnCount++;
      }
    }

    ComputedColumn tempComputedColumn = null;
    for (i = 0; i < addedTempComputedColumn.size(); i++) {
      tempComputedColumn = (ComputedColumn) (addedTempComputedColumn.get(i));
      metadata =
          new ResultFieldMetadata(
              0,
              tempComputedColumn.getName(),
              null,
              DataType.getClass(tempComputedColumn.getDataType()),
              null,
              true,
              -1);
      metadataList.add(metadata);
    }

    rsMeta = new ResultClass(metadataList);
  }