Package org.apache.cayenne.merge

Examples of org.apache.cayenne.merge.MergerContext


        Out.info(SchemaValidator.class, "Database rebuild complete");
      } else {
        // Valid schema; check if merge is needed
        Out.debug(SchemaValidator.class, "The database schema is valid; checking if upgrade is needed");

        MergerContext mc = new ExecutingMergerContext(dataMap, dataNode);
        List<MergerToken> allMergeTokens = new DbMerger().createMergeTokens(dataNode, dataMap);

        List<MergerToken> nonAutoMergeTokens = new ArrayList<MergerToken>();
        for(MergerToken mt : allMergeTokens) {
          if(mt instanceof DropTableToDb) {
            // Why would you want to drop AUTO_PK_SUPPORT?
            DropTableToDb drop = (DropTableToDb)mt;
            if(drop.getEntity().getName().equals("AUTO_PK_SUPPORT"))
              continue;
          }

          if((mt instanceof AddRelationshipToDb)
          || (mt instanceof CreateTableToDb)
          || (mt instanceof AddColumnToDb)
          || (mt instanceof SetAllowNullToDb)) {
            // These non-destructive types are allowed to merge in automatically
            Out.info(SchemaValidator.class, mt.toString());
            mt.execute(mc);
          } else {
            // All other types require user approval
            nonAutoMergeTokens.add(mt);
          }
        }

        if(nonAutoMergeTokens.size() == 0) {
          Out.debug(SchemaValidator.class, "No upgrade necessary");
          checkRunWizard(schemaValid);
          return true;
        }

        try {
          String msg = "BNU-Bot must perform the following action(s) to upgrade your database:\n";
          for(MergerToken mt : nonAutoMergeTokens)
            msg += mt.toString() + "\n";
          msg += "\n" +
            "It is strongly recommended to backup your database before continuing!\n" +
            "Okay to continue?";
          if(JOptionPane.showConfirmDialog(
              null,
              msg,
              "Database schema update required",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE)
            != JOptionPane.YES_OPTION) {
            throw new RuntimeException("User rejected schema update");
          }
        } catch(HeadlessException e) {
          // GUI is probably broken
          throw new Exception("A schema merge is required, but was unable to display " +
              "a window to query user if schema upgrade is acceptable.");
        }

        for(MergerToken mt : nonAutoMergeTokens) {
          Out.info(SchemaValidator.class, mt.toString());
          mt.execute(mc);
        }

        vr = mc.getValidationResult();
      }

      if(vr != null) {
        for(ValidationFailure vf : vr.getFailures()) {
          // Don't bother the user with these
View Full Code Here


        try {
            DataSource dataSource = connectionInfo.makeDataSource(getApplication()
                    .getClassLoadingService());
            // generator.runGenerator(dataSource);

            MergerContext mergerContext = new ExecutingMergerContext(
                    dataMap,
                    dataSource,
                    adapter, delegate);
            boolean modelChanged = false;
            for (MergerToken tok : tokensToMigrate) {
                int numOfFailuresBefore = mergerContext
                        .getValidationResult()
                        .getFailures()
                        .size();
                tok.execute(mergerContext);
                if (!modelChanged && tok.getDirection().equals(MergeDirection.TO_MODEL)) {
                    modelChanged = true;
                }

                if (numOfFailuresBefore == mergerContext
                        .getValidationResult()
                        .getFailures()
                        .size()) {
                    // looks like the token executed without failures
                    tokens.removeToken(tok);
                }
            }
           
            if (modelChanged) {
                // mark the model as unsaved
                Project project = Application.getProject();
                project.setModified(true);

                ProjectController projectController = Application
                        .getInstance()
                        .getFrameController()
                        .getProjectController();
                projectController.setDirty(true);
            }
           
            ValidationResult failures = mergerContext.getValidationResult();

            if (failures == null || !failures.hasFailures()) {
                JOptionPane.showMessageDialog(getView(), "Migration Complete.");
            }
            else {
View Full Code Here

        try {
            DataSource dataSource = connectionInfo.makeDataSource(getApplication()
                    .getClassLoadingService());
            // generator.runGenerator(dataSource);

            MergerContext mergerContext = new ExecutingMergerContext(
                    dataMap,
                    dataSource,
                    adapter,
                    delegate);
            boolean modelChanged = false;
            for (MergerToken tok : tokensToMigrate) {
                int numOfFailuresBefore = mergerContext
                        .getValidationResult()
                        .getFailures()
                        .size();
                tok.execute(mergerContext);
                if (!modelChanged && tok.getDirection().equals(MergeDirection.TO_MODEL)) {
                    modelChanged = true;
                }

                if (numOfFailuresBefore == mergerContext
                        .getValidationResult()
                        .getFailures()
                        .size()) {
                    // looks like the token executed without failures
                    tokens.removeToken(tok);
                }
            }

            if (modelChanged) {
                // mark the model as unsaved
                Project project = getApplication().getProject();
                project.setModified(true);

                ProjectController projectController = getApplication()
                        .getFrameController()
                        .getProjectController();
                projectController.setDirty(true);
            }

            ValidationResult failures = mergerContext.getValidationResult();

            if (failures == null || !failures.hasFailures()) {
                JOptionPane.showMessageDialog(getView(), "Migration Complete.");
            }
            else {
View Full Code Here

        try {
            DataSource dataSource = connectionInfo.makeDataSource(getApplication()
                    .getClassLoadingService());
            // generator.runGenerator(dataSource);

            MergerContext mergerContext = new ExecutingMergerContext(
                    dataMap,
                    dataSource,
                    adapter,
                    delegate);
            boolean modelChanged = false;
            for (MergerToken tok : tokensToMigrate) {
                int numOfFailuresBefore = mergerContext
                        .getValidationResult()
                        .getFailures()
                        .size();
                tok.execute(mergerContext);
                if (!modelChanged && tok.getDirection().equals(MergeDirection.TO_MODEL)) {
                    modelChanged = true;
                }

                if (numOfFailuresBefore == mergerContext
                        .getValidationResult()
                        .getFailures()
                        .size()) {
                    // looks like the token executed without failures
                    tokens.removeToken(tok);
                }
            }

            if (modelChanged) {
                // mark the model as unsaved
                Project project = getApplication().getProject();
                project.setModified(true);

                ProjectController projectController = getApplication()
                        .getFrameController()
                        .getProjectController();
                projectController.setDirty(true);
            }

            ValidationResult failures = mergerContext.getValidationResult();

            if (failures == null || !failures.hasFailures()) {
                JOptionPane.showMessageDialog(getView(), "Migration Complete.");
            }
            else {
View Full Code Here

TOP

Related Classes of org.apache.cayenne.merge.MergerContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.