Пример #1
0
  public MeasureMetaData createMeasureForNode(AvailableField selectedField) {

    MeasureMetaData meta =
        new MeasureMetaData(
            selectedField.getName(),
            "",
            selectedField.getDisplayName(),
            workspaceHelper.getLocale()); // $NON-NLS-1$
    ColumnBackedNode node = createColumnBackedNode(selectedField, ModelerPerspective.ANALYSIS);
    meta.setLogicalColumn(node.getLogicalColumn());
    return meta;
  }
Пример #2
0
 public FieldMetaData createFieldForParentWithNode(
     CategoryMetaData parent, AvailableField selectedField) {
   FieldMetaData field =
       new FieldMetaData(
           parent,
           selectedField.getName(),
           "",
           selectedField.getDisplayName(),
           workspaceHelper.getLocale()); // $NON-NLS-1$
   ColumnBackedNode node = createColumnBackedNode(selectedField, ModelerPerspective.REPORTING);
   field.setLogicalColumn(node.getLogicalColumn());
   field.setFieldTypeDesc(node.getLogicalColumn().getDataType().getName());
   return field;
 }
  private CategoryMetaData createCategoryMetaData(String name) {
    CategoryMetaData cat = new CategoryMetaData(name);
    List<AvailableTable> tablesList = workspace.getAvailableTables().getAsAvailableTablesList();

    FieldMetaData field = null;
    AvailableField avaialbleField = null;
    for (AvailableField af : tablesList.get(0).getAvailableFields()) {
      if (af.getPhysicalColumn().getDataType() == DataType.NUMERIC) {
        avaialbleField = af;
        break;
      }
    }
    field = workspace.createFieldForParentWithNode(cat, avaialbleField);
    field.setFormat("$#,###.##");
    field.setDefaultAggregation(AggregationType.SUM);
    cat.add(field);

    return cat;
  }
Пример #4
0
  public ColumnBackedNode createColumnBackedNode(
      AvailableField field, ModelerPerspective perspective) {
    String locale = workspaceHelper.getLocale();
    ColumnBackedNode node = new BaseColumnBackedMetaData(field.getName());
    LogicalTable lTab = findLogicalTable(field.getPhysicalColumn().getPhysicalTable(), perspective);
    LogicalColumn lCol = null;

    if (lCol == null) {
      lCol = new LogicalColumn();
      lCol.setLogicalTable(lTab);
      // lCol.setParentConcept(lTab);
      lCol.setPhysicalColumn(field.getPhysicalColumn());
      lCol.setDataType(field.getPhysicalColumn().getDataType());
      if (field.getPhysicalColumn().getAggregationList() != null) {
        lCol.setAggregationList(field.getPhysicalColumn().getAggregationList());
      }
      if (field.getPhysicalColumn().getAggregationType() != null) {
        lCol.setAggregationType(field.getPhysicalColumn().getAggregationType());
      }
      lCol.setName(new LocalizedString(locale, field.getPhysicalColumn().getName(locale)));
      String colId =
          "LC_"
              + toId(lTab.getPhysicalTable().getName(locale))
              + "_"
              + toId(field.getPhysicalColumn().getId());

      // lCol.setDescription(new LocalizedString(locale,
      // field.getPhysicalColumn().getName(locale)));

      if (perspective == ModelerPerspective.ANALYSIS) {
        colId += BaseModelerWorkspaceHelper.OLAP_SUFFIX;
      }

      colId = BaseModelerWorkspaceHelper.uniquify(colId, lTab.getLogicalColumns());
      lCol.setId(colId);

      lTab.addLogicalColumn(lCol);
    }

    node.setLogicalColumn(lCol);
    return node;
  }
Пример #5
0
  public void refresh(Domain newDomain) throws ModelerException {

    List<IAvailableItem> items = new ArrayList<IAvailableItem>();
    for (IPhysicalTable table : newDomain.getPhysicalModels().get(0).getPhysicalTables()) {
      boolean isFact =
          table.getProperty("FACT_TABLE") != null
              ? (Boolean) table.getProperty("FACT_TABLE")
              : false;
      items.add(new AvailableTable(table, isFact));
    }

    availableTables.setChildren(items);

    setModelIsChanging(true);
    setRelationalModelIsChanging(true);

    // Set the type of modeling session. This will propigate to the UI
    if (supportsOlap(newDomain)) {
      this.setModellingMode(ModelerMode.ANALYSIS_AND_REPORTING);
    } else {
      this.setModellingMode(ModelerMode.REPORTING_ONLY);
      // clear out OLAP side of the existing model
      model.getDimensions().clear();
    }
    List<AvailableTable> tablesList = availableTables.getAsAvailableTablesList();

    fireTablesChanged();

    // replace the domain with the new domain, which
    // makes sure the physical and logical columns are accurate
    domain = newDomain;

    for (MeasureMetaData measure : model.getMeasures()) {
      boolean found = false;
      if (measure.getLogicalColumn() != null) {
        inner:
        for (AvailableTable table : tablesList) {
          for (AvailableField f : table.getAvailableFields()) {
            if (f.getPhysicalColumn()
                    .getId()
                    .equals(measure.getLogicalColumn().getPhysicalColumn().getId())
                && f.getPhysicalColumn()
                    .getPhysicalTable()
                    .getId()
                    .equals(
                        measure
                            .getLogicalColumn()
                            .getPhysicalColumn()
                            .getPhysicalTable()
                            .getId())) {
              // the physical column backing this measure is still available, set it to the new one
              measure.setLogicalColumn(
                  createColumnBackedNode(f, currentModelerPerspective).getLogicalColumn());
              found = true;
              break inner;
            }
          }
        }
        if (!found) {
          // the physical column that backed this measure no longer exists in the model.
          // therefore, we must invalidate it's logical column
          measure.setLogicalColumn(null);
        }
      }
    }

    try {
      for (DimensionMetaData dm : model.getDimensions()) {
        for (HierarchyMetaData hm : dm) {
          for (LevelMetaData lm : hm) {
            boolean found = false;
            if (lm.getLogicalColumn() != null) {
              inner:
              for (AvailableTable table : tablesList) {
                for (AvailableField f : table.getAvailableFields()) {
                  if (f.getPhysicalColumn()
                          .getId()
                          .equals(lm.getLogicalColumn().getPhysicalColumn().getId())
                      && f.getPhysicalColumn()
                          .getPhysicalTable()
                          .getId()
                          .equals(
                              lm.getLogicalColumn()
                                  .getPhysicalColumn()
                                  .getPhysicalTable()
                                  .getId())) {
                    // the physical column backing this level is still available, it is ok

                    lm.setLogicalColumn(
                        createColumnBackedNode(f, currentModelerPerspective).getLogicalColumn());
                    found = true;
                    break inner;
                  }
                }
              }
            }
            if (!found) {
              // the physical column that backed this level no longer exists in the model.
              // therefore, we must invalidate it's logical column
              lm.setLogicalColumn(null);
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    for (CategoryMetaData category : relationalModel.getCategories()) {
      for (FieldMetaData field : category) {
        boolean found = false;
        if (field.getLogicalColumn() != null) {
          inner:
          for (AvailableTable table : tablesList) {
            for (AvailableField f : table.getAvailableFields()) {
              if (f.getPhysicalColumn()
                      .getId()
                      .equals(field.getLogicalColumn().getPhysicalColumn().getId())
                  && f.getPhysicalColumn()
                      .getPhysicalTable()
                      .getId()
                      .equals(
                          field
                              .getLogicalColumn()
                              .getPhysicalColumn()
                              .getPhysicalTable()
                              .getId())) {

                // the physical column backing this field is still available, it is ok
                found = true;
                break inner;
              }
            }
          }
          if (!found) {
            // the physical column that backed this field no longer exists in the model.
            // therefore, we must invalidate it's logical column
            field.setLogicalColumn(null);
          }
        }
      }
    }

    // If the new model was previously "auto-modeled" we need to clean that now
    LogicalModel newLModel = getLogicalModel(ModelerPerspective.ANALYSIS);
    if (newLModel != null) {
      List<OlapDimension> theDimensions =
          (List) newLModel.getProperty("olap_dimensions"); // $NON-NLS-1$
      if (theDimensions != null) {
        theDimensions.clear();
      }
      List<OlapCube> theCubes = (List) newLModel.getProperty("olap_cubes"); // $NON-NLS-1$
      if (theCubes != null) {
        theCubes.clear();
      }
    }

    setModelIsChanging(false);
    setRelationalModelIsChanging(false);
  }