Beispiel #1
0
  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;
  }
Beispiel #2
0
  /**
   * @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;
  }
Beispiel #3
0
  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;
  }