예제 #1
0
 private void rebuildOutputNodesConnections(
     List<? extends TableNode> tableNodes, PigMapData mapData) {
   for (TableNode node : tableNodes) {
     if (node != null) {
       if (!node.getIncomingConnections().isEmpty()) {
         if (!PigMapUtil.isExpressionEditable(node)) {
           node.setExpression("");
           PigMapUtil.detachConnectionsSouce(node, mapData);
         }
       }
     }
   }
 }
예제 #2
0
  public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables, PigMapData mapData) {
    for (IMetadataTable meatadataTable : outputMetadataTables) {
      String name = meatadataTable.getTableName();
      OutputTable outputTable = null;
      for (OutputTable out : mapData.getOutputTables()) {
        if (out.getName() != null && out.getName().equals(name)) {
          outputTable = out;
          break;
        }
      }
      if (outputTable == null) {
        outputTable = PigmapFactory.eINSTANCE.createOutputTable();
        outputTable.setName(name);
        mapData.getOutputTables().add(outputTable);
      }

      List<IMetadataColumn> listColumns = meatadataTable.getListColumns();
      if (listColumns != null) {
        EList<TableNode> nodes = outputTable.getNodes();
        for (int i = 0; i < listColumns.size(); i++) {
          IMetadataColumn column = listColumns.get(i);
          TableNode found = null;
          int j = 0;
          for (; j < nodes.size(); j++) {
            TableNode node = nodes.get(j);
            if (node.getName() != null && node.getName().equals(column.getLabel())) {
              found = node;
              break;
            }
          }
          if (found != null) {
            // set in case talend type changed in metadata
            found.setType(column.getTalendType());
            if (i != j) {
              // do switch to keep the same sequence
              TableNode temp = nodes.get(j);
              nodes.remove(j);
              nodes.add(i, temp);
            }
          } else {
            found = PigmapFactory.eINSTANCE.createTableNode();
            found.setName(column.getLabel());
            found.setType(column.getTalendType());
            found.setNullable(column.isNullable());

            nodes.add(i, found);
          }
        }

        if (nodes.size() > listColumns.size()) {
          List unUsed = new ArrayList();
          for (int i = listColumns.size(); i < nodes.size(); i++) {
            TableNode node = nodes.get(i);
            PigMapUtil.detachConnectionsSouce(node, mapData);
            unUsed.add(node);
          }
          nodes.removeAll(unUsed);
        }
      }
      mapData.getOutputTables().add(outputTable);

      // re-build the connections in case any unnecessary connections are created because of
      // previous bugs and
      // can't be deleted
      rebuildOutputNodesConnections(outputTable.getNodes(), mapData);
    }
  }