public void visitComplexConjunctiveQuery(ComplexConjunctiveQuery complexQuery) {
   stack.add(0, complexQuery);
   //        List<FormulaVariable> universalVariables =
   // variableFinder.getUniversalVariables(variableMaps, stack);
   //        variables.add(0, universalVariables);
   result.append(
       generateConjunctionString(
           complexQuery.getGenerators(),
           variables,
           mappingTask.getSourceProxy().getIntermediateSchema()));
   result.append(generateBuiltinsForSelections(complexQuery));
   List<Expression> equalities = variableFinder.getEqualities(variableMaps, stack);
   if (!equalities.isEmpty()) {
     result.append(generateEqualityString(equalities, variables, false));
   }
   // intersection
   if (complexQuery.hasIntersection()) {
     if (useSaveFormat) {
       result.append(", \n");
     } else {
       result
           .append("\n")
           .append(generateIndent())
           .append(utility.SECONDARY_INDENT)
           .append("and ");
     }
     SimpleConjunctiveQuery intersectionQuery = complexQuery.getConjunctionForIntersection();
     stack.add(0, intersectionQuery);
     List<FormulaVariable> existentialVariables =
         variableFinder.getExistentialVariables(variableMaps, stack);
     variables.add(0, existentialVariables);
     if (!existentialVariables.isEmpty() && !useSaveFormat) {
       result.append("exist ");
       result.append(utility.printVariables(existentialVariables));
     }
     if (!useSaveFormat) {
       result.append(" (// base view ").append(intersectionQuery.getId()).append("\n");
     }
     result.append(
         generateConjunctionString(
             intersectionQuery.getGenerators(),
             variables,
             mappingTask.getSourceProxy().getIntermediateSchema()));
     List<Expression> intersectionEqualities = variableFinder.getEqualities(variableMaps, stack);
     if (!intersectionEqualities.isEmpty()) {
       result.append(generateEqualityString(intersectionEqualities, variables, false));
     }
     variables.remove(0);
     stack.remove(0);
     if (!useSaveFormat) {
       result.append("\n").append(generateIndent()).append(utility.SECONDARY_INDENT).append(")");
     }
   }
   //        variables.remove(0);
   stack.remove(0);
 }
 private void creaPopUpMappingTaskTreeSourceDuplicate() {
   this.popUpMenuSourceDuplicate = new JPopupMenu();
   MappingTask mappingTask = scenario.getMappingTask();
   if (mappingTask != null) {
     this.popUpMenuSourceDuplicate.add(
         new ActionDuplicateSetNode(this, sourceSchemaTree, mappingTask.getSourceProxy()));
     this.popUpMenuSourceDuplicate.add(
         new ActionSelectionCondition(this, sourceSchemaTree, mappingTask.getSourceProxy()));
   }
 }
Example #3
0
  public String generateSQL(MappingTask mappingTask) {
    if (mappingTask.getSourceProxy().getMappingData().isNested()
        || mappingTask.getTargetProxy().getMappingData().isNested()) {
      throw new IllegalMappingTaskException(
          "Data Sources are nested. SQL can be generated for relational sources only");
    }
    StringBuilder result = new StringBuilder();
    result.append(
        "-- This script was automatically generated by the ++Spicy mapping tool. (http://db.unibas.it/projects/spicy/)\n\n");
    result.append("BEGIN TRANSACTION;\n");
    result.append("SET CONSTRAINTS ALL DEFERRED;\n");
    if (mappingTask.getConfig().useSortInSkolems()) {
      result.append(mappingTask.getDBMSHandler().generateSortArrayFunction());
    }

    // Generate the SQL script for the first step in chaining scenarios

    if (mappingTask.getSourceProxy() instanceof ChainingDataSourceProxy) {
      ChainingDataSourceProxy proxy = (ChainingDataSourceProxy) mappingTask.getSourceProxy();
      GenerateSQLForSourceToTargetExchange stGeneratorFirstStep =
          new GenerateSQLForSourceToTargetExchange();
      result.append(stGeneratorFirstStep.generateSQL(proxy.getMappingTask(), CHAINING_FIRST_STEP));
    }

    result.append(this.getDeleteTablesScript(mappingTask));
    GenerateSQLForSourceToTargetExchange stGenerator = new GenerateSQLForSourceToTargetExchange();

    if (!mappingTask.getConfig().useHashTextForSkolems()
        && mappingTask.getConfig().useSkolemTable()) {
      result.append(generateSQLForSkolemTable(mappingTask));
    }
    if (mappingTask.getSourceProxy() instanceof ChainingDataSourceProxy) {
      result.append(stGenerator.generateSQL(mappingTask, CHAINING_LAST_STEP));
    } else {
      result.append(stGenerator.generateSQL(mappingTask, CHAINING_NO_CHAINING));
    }
    allTablesToDelete.addAll(stGenerator.getAllTablesToDelete());
    if (mappingTask.getConfig().useCreateTableInSTExchange()) {
      allTablesToDelete.addAll(stGenerator.getAllViewsToDelete());
    } else {
      allViewsToDelete.addAll(stGenerator.getAllViewsToDelete());
    }
    result.append(generateFinalInserts(mappingTask));
    result.append("COMMIT;\n");
    if (!mappingTask.getConfig().useDebugMode()) {
      result.append(this.getAllViewsToDeleteScript());
      result.append(this.getAllTablesToDeleteScript());
    }
    return result.toString();
  }
 private String generateConjunctionString(
     List<SetAlias> setVariables, List<List<FormulaVariable>> variables, INode schema) {
   StringBuilder localResult = new StringBuilder();
   List<SetAlias> sortedAliases = new ArrayList<SetAlias>(setVariables);
   Collections.sort(sortedAliases);
   for (int i = 0; i < sortedAliases.size(); i++) {
     SetAlias sourceVariable = sortedAliases.get(i);
     localResult.append(generateIndent());
     if (!useSaveFormat) {
       localResult.append(
           utility.printAtomName(sourceVariable, mappingTask.getSourceProxy().isNested()));
     } else {
       localResult.append(
           utility.printAtomNameForSaveFormat(
               sourceVariable, mappingTask.getSourceProxy().isNested()));
     }
     List<VariablePathExpression> attributePaths = sourceVariable.getFirstLevelAttributes(schema);
     for (int j = 0; j < attributePaths.size(); j++) {
       VariablePathExpression attributePath = attributePaths.get(j);
       FormulaVariable attributeVariable = findVariableForPath(attributePath, variables);
       localResult.append(attributePath.getLastStep()).append(": ");
       if (useSaveFormat) {
         localResult.append("$");
       }
       localResult.append(attributeVariable.toShortString());
       if (j != attributePaths.size() - 1) {
         localResult.append(", ");
       }
     }
     localResult.append(")");
     if (i != sortedAliases.size() - 1) {
       localResult.append(", \n");
     }
   }
   return localResult.toString();
 }
  public void findCorrespondences(String inputFile, String outputFile) throws DAOException {
    DAOMappingTask daoMappingTask = new DAOMappingTask();
    MappingTask mappingTask = daoMappingTask.loadMappingTask(5, inputFile, false);
    INode source = mappingTask.getSourceProxy().getSchema();
    INode target = mappingTask.getTargetProxy().getSchema();

    NodeExtractorVisitor visitorSource = new NodeExtractorVisitor();
    source.accept(visitorSource);
    List<INode> sourceAttributes = visitorSource.getResult();

    NodeExtractorVisitor visitorTarget = new NodeExtractorVisitor();
    target.accept(visitorTarget);
    List<INode> targetAttributes = visitorTarget.getResult();

    generateCorrespondences(sourceAttributes, targetAttributes, mappingTask);
    daoMappingTask.saveMappingTask(mappingTask, outputFile);
  }
  public void createConnectionWidgets(ICreaWidgetCorrespondences correspondenceCreator) {
    this.glassPane.clearConnections();
    this.glassPane.clearConstants();
    this.glassPane.clearFunctions();
    this.glassPane.validate();
    correspondenceCreator.creaWidgetCorrespondences();
    correspondenceCreator.creaWidgetIconForSelectionCondition();

    MappingTask mappingTask = scenario.getMappingTask();
    if (mappingTask != null) {
      IDataSourceProxy source = mappingTask.getSourceProxy();
      IDataSourceProxy target = mappingTask.getTargetProxy();
      correspondenceCreator.creaWidgetFunctionalDependencies(source, true);
      correspondenceCreator.creaWidgetFunctionalDependencies(target, false);
      return;
    }
  }
Example #7
0
 //    private static List<SetAlias> extractDifferentVariables(List<SetAlias> variables) {
 //        List<SetAlias> result = new ArrayList<SetAlias>();
 //        for (SetAlias variable : variables) {
 //            if (!containsVariableWithSameName(variable, result)) {
 //                result.add(variable);
 //            }
 //        }
 //        return result;
 //    }
 //    private static boolean containsVariableWithSameName(SetAlias variable, List<SetAlias>
 // variables) {
 //        for (SetAlias setAlias : variables) {
 //            if (setAlias.hasSameId(variable)) {
 //                return true;
 //            }
 //        }
 //        return false;
 //    }
 private static String generateProjectionOnAllAttributes(
     List<SetAlias> variables, MappingTask mappingTask) {
   StringBuilder result = new StringBuilder();
   for (int i = 0; i < variables.size(); i++) {
     SetAlias variable = variables.get(i);
     List<VariablePathExpression> attributes =
         variable.getAttributes(mappingTask.getSourceProxy().getIntermediateSchema());
     for (int j = 0; j < attributes.size(); j++) {
       VariablePathExpression attribute = attributes.get(j);
       result.append(DOUBLE_INDENT).append(GenerateSQL.attributeNameWithVariable(attribute));
       result.append(" AS ").append(attributeNameInVariable(attribute));
       if (j != attributes.size() - 1) result.append(",\n");
     }
     if (i != variables.size() - 1) result.append(",\n");
   }
   result.append("\n");
   return result.toString();
 }
 ////////////////////////////    ANALISI    ///////////////////////////
 public void drawScene(
     CreaWidgetAlberi widgetCreator, ICreaWidgetCorrespondences correspondenceCreator) {
   MappingTask mappingTask = scenario.getMappingTask();
   if (mappingTask == null) {
     this.analizzato = false;
     return;
   }
   IDataSourceProxy source = mappingTask.getSourceProxy();
   IDataSourceProxy target = mappingTask.getTargetProxy();
   createTrees(source, target);
   createTreeWidgets(source, target, widgetCreator);
   createConnectionWidgets(correspondenceCreator);
   //        updateTree();
   this.analizzato = true;
   this.sourceSchemaTree.updateUI();
   this.targetSchemaTree.updateUI();
   this.moveToFront(this.glassPane);
   this.setVisible(true);
   this.glassPane.getScene().setMaximumBounds(this.glassPane.getScene().getBounds());
   initListener();
 }