private void replaceSharedObjects(AbstractMeta abstractMeta) {
    for (DatabaseMeta databaseMeta : getSharedObjects(DatabaseMeta.class)) {
      // Database...
      int index = abstractMeta.indexOfDatabase(databaseMeta);
      if (index < 0) {
        abstractMeta.addDatabase(databaseMeta);
      } else {
        DatabaseMeta imported = abstractMeta.getDatabase(index);
        // Preserve the object id so we can update without having to look up the id
        imported.setObjectId(databaseMeta.getObjectId());
        if (equals(databaseMeta, imported)
            || !getPromptResult(
                BaseMessages.getString(
                    PKG,
                    "RepositoryImporter.Dialog.ConnectionExistsOverWrite.Message",
                    imported.getName()),
                BaseMessages.getString(
                    PKG,
                    "RepositoryImporter.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage"),
                IMPORT_ASK_ABOUT_REPLACE_DB)) {
          imported.replaceMeta(databaseMeta);
          // We didn't actually change anything
          imported.clearChanged();
        } else {
          imported.setChanged();
        }
      }
    }

    for (SlaveServer slaveServer : getSharedObjects(SlaveServer.class)) {
      int index = abstractMeta.getSlaveServers().indexOf(slaveServer);
      if (index < 0) {
        abstractMeta.getSlaveServers().add(slaveServer);
      } else {
        SlaveServer imported = abstractMeta.getSlaveServers().get(index);
        // Preserve the object id so we can update without having to look up the id
        imported.setObjectId(slaveServer.getObjectId());
        if (equals(slaveServer, imported)
            || !getPromptResult(
                BaseMessages.getString(
                    PKG,
                    "RepositoryImporter.Dialog.SlaveServerExistsOverWrite.Message",
                    imported.getName()),
                BaseMessages.getString(
                    PKG,
                    "RepositoryImporter.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage"),
                IMPORT_ASK_ABOUT_REPLACE_SS)) {
          imported.replaceMeta(slaveServer);
          // We didn't actually change anything
          imported.clearChanged();
        } else {
          imported.setChanged();
        }
      }
    }
  }
Exemplo n.º 2
0
 /**
  * Insert all the databases from the repository into the TransMeta object, overwriting optionally
  *
  * @param TransMeta The transformation to load into.
  * @param overWriteShared if an object with the same name exists, overwrite
  * @throws KettleException
  */
 protected void readDatabases(
     TransMeta transMeta, boolean overWriteShared, List<DatabaseMeta> databaseMetas) {
   for (DatabaseMeta databaseMeta : databaseMetas) {
     if (overWriteShared || transMeta.findDatabase(databaseMeta.getName()) == null) {
       if (databaseMeta.getName() != null) {
         databaseMeta.shareVariablesWith(transMeta);
         transMeta.addOrReplaceDatabase(databaseMeta);
         if (!overWriteShared) {
           databaseMeta.setChanged(false);
         }
       }
     }
   }
   transMeta.clearChangedDatabases();
 }