private void creaPopUpMappingTaskTreeTargetDeleteDuplicate() {
   this.popUpMenuTargetDeleteDuplicate = new JPopupMenu();
   MappingTask mappingTask = scenario.getMappingTask();
   if (mappingTask != null) {
     this.popUpMenuTargetDeleteDuplicate.add(
         new ActionDeleteDuplicateSetCloneNode(
             this, targetSchemaTree, mappingTask.getTargetProxy()));
     this.popUpMenuTargetDeleteDuplicate.add(
         new ActionSelectionCondition(this, targetSchemaTree, mappingTask.getTargetProxy()));
   }
 }
Example #2
0
 public String getDeleteTablesScript(MappingTask mappingTask) {
   StringBuilder result = new StringBuilder();
   List<PathExpression> setPaths =
       new GenerateSetVariables().findSetAbsolutePaths(mappingTask.getTargetProxy());
   for (PathExpression pathExpression : setPaths) {
     INode node = new FindNode().findNodeInSchema(pathExpression, mappingTask.getTargetProxy());
     if (!(node instanceof SetCloneNode)) {
       result
           .append("delete from ")
           .append(TARGET_SCHEMA_NAME)
           .append(".")
           .append(pathExpression.getLastStep())
           .append(";\n");
     }
   }
   return result.toString();
 }
Example #3
0
 public static String generateCasting(
     VariablePathExpression attributePath, String columnName, MappingTask mappingTask) {
   INode attributeNode =
       new FindNode()
           .findNodeInSchema(attributePath.getAbsolutePath(), mappingTask.getTargetProxy());
   String value = attributeNode.getChild(0).getLabel();
   String castedColumnName = mappingTask.getDBMSHandler().forceCast(columnName, value);
   return castedColumnName;
 }
Example #4
0
 public static String targetRelationName(
     SetAlias variable, MappingTask mappingTask, int chainingStep) {
   SetNode bindingNode =
       variable.getBindingNode(mappingTask.getTargetProxy().getIntermediateSchema());
   String result = variable.getBindingPathExpression().getLastStep();
   if (bindingNode instanceof SetCloneNode) {
     result = ((SetCloneNode) bindingNode).getOriginalNodePath().getLastStep();
   }
   return getTargetSchemaName(chainingStep) + "." + result;
 }
Example #5
0
 private String generateFinalInsert(MappingTask mappingTask) {
   StringBuilder result = new StringBuilder();
   for (SetAlias targetVariable : mappingTask.getTargetProxy().getMappingData().getVariables()) {
     List<FORule> relevantTgds =
         findRelevantTGDs(targetVariable, mappingTask.getMappingData().getSTTgds());
     if (!relevantTgds.isEmpty()) {
       result.append(generateInsertForRelationAfterExchange(targetVariable, mappingTask));
     }
   }
   return result.toString();
 }
Example #6
0
  @Override
  public void performAction() {
    Properties config = new Properties();
    config.setProperty(
        IComputeQuality.class.getSimpleName(),
        "it.unibas.spicy.findmappings.strategies.computequality.ComputeQualityStructuralAnalysis");
    Application.reset(config);
    executeInjection();
    mappingFinder.cleanUp();
    Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO);
    MappingTask mappingTask = scenario.getMappingTask();
    if (mappingTask.getTargetProxy().getInstances().isEmpty()) {
      NotifyDescriptor nd =
          new NotifyDescriptor.Message(
              NbBundle.getMessage(Costanti.class, Costanti.WARNING_NOT_TARGET_INSTANCES),
              DialogDescriptor.WARNING_MESSAGE);
      DialogDisplayer.getDefault().notify(nd);
      return;
    }
    checkValueCorrespondenceInMappingTask(mappingTask);
    SwingWorker swingWorker =
        new SwingWorker() {

          private Scenario scenario;

          @Override
          protected Object doInBackground() throws Exception {
            scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO);
            MappingTask mappingTask = scenario.getMappingTask();

            List<AnnotatedMappingTask> bestMappingTasks =
                mappingFinder.findBestMappings(mappingTask);
            modello.putBean(Costanti.BEST_MAPPING_TASKS, bestMappingTasks);
            IOProvider.getDefault().getIO(Costanti.FLUSSO_SPICY, false).select();
            return true;
          }

          @Override
          protected void done() {
            try {
              if ((Boolean) get() && !isCancelled()) {
                actionViewSpicy.performActionWithScenario(this.scenario);
                actionViewBestMappings.performActionWithScenario(this.scenario);
              }
            } catch (InterruptedException ex) {
              logger.error(ex);
            } catch (ExecutionException ex) {
              logger.error(ex);
            }
          }
        };
    swingWorker.execute();
  }
Example #7
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();
  }
 ///////////////////////////    SKOLEMS   ///////////////////////////////
 private String printSkolems(FORule rule, MappingTask mappingTask) {
   StringBuilder result = new StringBuilder();
   List<FormulaVariable> existentialVariables = rule.getExistentialFormulaVariables(mappingTask);
   for (FormulaVariable variable : existentialVariables) {
     String generatorString = findGeneratorForVariable(variable, rule, mappingTask);
     result.append(variable.toShortString()).append(": ").append(generatorString).append("\n");
   }
   if (mappingTask.getTargetProxy().isNested()) {
     for (SetAlias alias : rule.getTargetView().getGenerators()) {
       VariablePathExpression bindingPath = alias.getBindingPathExpression();
       String generatorString = findGeneratorForPath(bindingPath, rule, mappingTask);
       result.append(alias.toShortString()).append(": ").append(generatorString).append("\n");
     }
   }
   return result.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 #11
0
 private String findGeneratorForVariable(
     FormulaVariable variable, FORule rule, MappingTask mappingTask) {
   List<FormulaVariable> universalVariables =
       rule.getUniversalFormulaVariablesInTarget(mappingTask);
   TGDGeneratorsMap generatorsMap = rule.getGenerators(mappingTask);
   for (VariablePathExpression targetPath : variable.getTargetOccurrencePaths()) {
     IValueGenerator generator =
         generatorsMap.getGeneratorForLeaf(
             targetPath, mappingTask.getTargetProxy().getIntermediateSchema());
     if (generator != null && generator instanceof SkolemFunctionGenerator) {
       SkolemFunctionGenerator skolemGenerator = (SkolemFunctionGenerator) generator;
       return skolemGenerator.toStringWithVariableArguments(universalVariables);
     }
   }
   return NullValueGenerator.getInstance().toString();
   // throw new IllegalArgumentException("Unable to find generator for variable: " +
   // variable.toLongString() + "\nin rule: " + rule + "\n" +
   // SpicyEngineUtility.printVariableList(rule.getExistentialFormulaVariables(mappingTask)) +
   // "\nGenerators: " + generatorsMap);
 }
 ////////////////////////////    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();
 }
Example #13
0
  ////////////////////////////////   CONCLUSION   ////////////////////////////////////////////////
  public String conclusionString(FORule tgd, MappingTask mappingTask, String indent) {
    // giannisk
    // find target paths that have a constant value correspondence
    List<VariablePathExpression> constantTargetPaths = new ArrayList<VariablePathExpression>();
    HashMap<VariablePathExpression, ISourceValue> constantValueMap =
        new HashMap<VariablePathExpression, ISourceValue>();
    for (VariableCorrespondence varCor : tgd.getCoveredCorrespondences()) {
      if (varCor.isConstant()) {
        constantTargetPaths.add(varCor.getTargetPath());
        constantValueMap.put(varCor.getTargetPath(), varCor.getSourceValue());
      }
    }

    StringBuilder result = new StringBuilder();
    List<FormulaVariable> universalVariables = tgd.getUniversalFormulaVariables(mappingTask);
    List<FormulaVariable> existentialVariables = tgd.getExistentialFormulaVariables(mappingTask);
    if (!useSaveFormat
        && (!existentialVariables.isEmpty() || mappingTask.getTargetProxy().isNested())) {
      result.append("exist ");
      if (mappingTask.getTargetProxy().isNested()) {
        utility.printOIDVariables(tgd.getTargetView());
      }
      if (!existentialVariables.isEmpty()) {
        result.append(utility.printVariables(existentialVariables));
      }
    }
    result.append("\n");
    for (int i = 0; i < tgd.getTargetView().getGenerators().size(); i++) {
      SetAlias targetVariable = tgd.getTargetView().getGenerators().get(i);
      result.append(indent).append(utility.INDENT);
      if (!useSaveFormat) {
        result.append(
            utility.printAtomName(targetVariable, mappingTask.getTargetProxy().isNested()));
      } else {
        result.append(
            utility.printAtomNameForSaveFormat(
                targetVariable, mappingTask.getTargetProxy().isNested()));
      }
      List<VariablePathExpression> attributePaths =
          targetVariable.getFirstLevelAttributes(
              mappingTask.getTargetProxy().getIntermediateSchema());
      for (int j = 0; j < attributePaths.size(); j++) {
        VariablePathExpression attributePath = attributePaths.get(j);
        result.append(attributePath.getLastStep()).append(": ");
        FormulaVariable attributeVariable =
            findUniversalVariableForTargetPath(attributePath, universalVariables);
        Expression transformation = null;
        if (!constantTargetPaths.contains(attributePath)) {
          if (attributeVariable == null) {
            attributeVariable =
                findExistentialVariable(
                    attributePath, tgd.getExistentialFormulaVariables(mappingTask));
          }
          transformation = attributeVariable.getTransformationFunction(attributePath);
        }
        if (transformation == null) {
          if (!constantTargetPaths.contains(attributePath)) {
            if (useSaveFormat) {
              result.append("$");
            }
            result.append(attributeVariable.toShortString());
          } else { // constant
            result.append(constantValueMap.get(attributePath));
          }
        } else { // function
          List<List<FormulaVariable>> variables = new ArrayList<List<FormulaVariable>>();
          variables.add(tgd.getUniversalFormulaVariables(mappingTask));
          utility.setVariableDescriptions(transformation, variables);
          result.append(transformation);
        }
        if (j != attributePaths.size() - 1) {
          result.append(", ");
        }
      }
      result.append(")");
      if (i != tgd.getTargetView().getGenerators().size() - 1) {
        result.append(", \n");
      }
    }
    return result.toString();
  }