Exemplo n.º 1
1
  protected void onSaveAndClose() {

    String key = inpKey.getText().trim();
    if (key.length() == 0) {
      errInfo.showError("You must specify a key.");
      return;
    }

    String dimKey = lbcDimension.getSelectedKey();
    if (dimKey == null || dimKey.length() == 0) {
      errInfo.showError("You must select a dimension.");
      return;
    }
    DimMappingDef.Action onUnmapped = DimMappingDef.Action.valueOf(chkOnUnmapped.getSelectedKey());

    String unmappedElement =
        elmSelector.getDimensionElement() != null
            ? elmSelector.getDimensionElement().getPath()
            : null;
    if (onUnmapped == DimMappingDef.Action.ASSIGN) {
      if (unmappedElement == null) {
        errInfo.showError("An Unmapped Element must be specified.");
        return;
      } else if (!elmSelector.getDimensionElement().isLeaf()) {
        errInfo.showError("An Unmapped Element must be specified that is NOT a leaf!");
        return;
      }
    }

    // now check the dimension mapping table
    List<DimMappingElementDef> mappingList = mapEditor.getMappingList();
    for (DimMappingElementDef me : mappingList) {
      if (me.getDimensionKey() == null || !me.getDimensionKey().equals(dimKey)) {
        errInfo.showError(
            "The mapping table contains elements for other dimensions then the selected one.");
        return;
      }
      me.setDimMapKey(key);
    }

    dimMapping.setKey(key);
    dimMapping.setDimensionKey(dimKey);
    dimMapping.setDescription(inpDescription.getText());
    dimMapping.setOnUnmapped(onUnmapped);
    dimMapping.setUnmappedPath(unmappedElement);
    dimMapping.setAutoCreateMapping(chkOptions.isKeySelected("autocreate"));

    ServerContext context = ETLgineServer.getInstance().getServerContext();
    String syncTableConnectionName =
        context.getProperty(dpManagerKey + ".datapool.syncTables.connection");
    try {
      Connection connection = JDBCUtil.openConnection(context, syncTableConnectionName);
      try {
        connection.setAutoCommit(false);
        DimMappingDefDAO dao = new DimMappingDefDAO(connection);
        if (isNew) {
          dao.insert(dimMapping);
        } else {
          dao.update(dimMapping);
        }

        // insert dimMappings
        DimMappingElementDefDAO daoME = new DimMappingElementDefDAO(connection);
        daoME.deleteByDimMapKey(key);
        daoME.setOrderIndex(0);
        for (DimMappingElementDef me : mappingList) {
          daoME.insert(me);
        }

        connection.commit();
        connection.setAutoCommit(true);
        close();
      } finally {
        if (!connection.getAutoCommit()) {
          connection.rollback();
        }
        connection.close();
      }
    } catch (Exception e) {
      log.error("Error saving to sync table.", e);
      errInfo.showError(e);
    }
  }
Exemplo n.º 2
0
 private void loadMappingElements() {
   ServerContext context = ETLgineServer.getInstance().getServerContext();
   String syncTableConnectionName =
       context.getProperty(dpManagerKey + ".datapool.syncTables.connection");
   try {
     Connection connection = JDBCUtil.openConnection(context, syncTableConnectionName);
     try {
       DimMappingElementDefDAO dao = new DimMappingElementDefDAO(connection);
       List<DimMappingElementDef> list = dao.listMappings(dimMapping.getKey());
       for (DimMappingElementDef me : list) {
         me.setDimensionKey(dimMapping.getDimensionKey()); // for security...
       }
       mapEditor.setMappingList(list);
     } finally {
       connection.close();
     }
   } catch (Exception e) {
     errInfo.showError(e);
     log.error("Error loading mapping elements", e);
   }
 }