Esempio n. 1
0
  public void saveSharedObjects(
      final RepositoryElementInterface element, final String versionComment)
      throws KettleException {
    TransMeta transMeta = (TransMeta) element;
    // First store the databases and other depending objects in the transformation.
    //

    // Only store if the database has actually changed or doesn't have an object ID (imported)
    //
    for (DatabaseMeta databaseMeta : transMeta.getDatabases()) {
      if (databaseMeta.hasChanged() || databaseMeta.getObjectId() == null) {
        if (databaseMeta.getObjectId() == null
            || unifiedRepositoryConnectionAclService.hasAccess(
                databaseMeta.getObjectId(), RepositoryFilePermission.WRITE)) {
          repo.save(databaseMeta, versionComment, null);
        } else {
          log.logError(
              BaseMessages.getString(
                  PKG,
                  "PurRepository.ERROR_0004_DATABASE_UPDATE_ACCESS_DENIED",
                  databaseMeta.getName()));
        }
      }
    }

    // Store the slave servers...
    //
    for (SlaveServer slaveServer : transMeta.getSlaveServers()) {
      if (slaveServer.hasChanged() || slaveServer.getObjectId() == null) {
        repo.save(slaveServer, versionComment, null);
      }
    }

    // Store the cluster schemas
    //
    for (ClusterSchema clusterSchema : transMeta.getClusterSchemas()) {
      if (clusterSchema.hasChanged() || clusterSchema.getObjectId() == null) {
        repo.save(clusterSchema, versionComment, null);
      }
    }

    // Save the partition schemas
    //
    for (PartitionSchema partitionSchema : transMeta.getPartitionSchemas()) {
      if (partitionSchema.hasChanged() || partitionSchema.getObjectId() == null) {
        repo.save(partitionSchema, versionComment, null);
      }
    }
  }
Esempio n. 2
0
  public void saveRep(
      Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step)
      throws KettleException {
    try {
      rep.saveDatabaseMetaStepAttribute(id_transformation, id_step, "id_connection", databaseMeta);
      rep.saveStepAttribute(id_transformation, id_step, "commit", commitSize);
      rep.saveStepAttribute(id_transformation, id_step, "schema", schemaName);
      rep.saveStepAttribute(id_transformation, id_step, "table", tableName);
      rep.saveStepAttribute(id_transformation, id_step, "update_bypassed", updateBypassed);

      for (int i = 0; i < keyStream.length; i++) {
        rep.saveStepAttribute(id_transformation, id_step, i, "key_name", keyStream[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "key_field", keyLookup[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "key_condition", keyCondition[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "key_name2", keyStream2[i]);
      }

      for (int i = 0; i < updateLookup.length; i++) {
        rep.saveStepAttribute(id_transformation, id_step, i, "value_name", updateLookup[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "value_rename", updateStream[i]);
        rep.saveStepAttribute(
            id_transformation, id_step, i, "value_update", update[i].booleanValue());
      }

      // Also, save the step-database relationship!
      if (databaseMeta != null) {
        rep.insertStepDatabase(id_transformation, id_step, databaseMeta.getObjectId());
      }
    } catch (Exception e) {
      throw new KettleException(
          BaseMessages.getString(PKG, "InsertUpdateMeta.Exception.UnableToSaveStepInfoToRepository")
              + id_step,
          e);
    }
  }
  public void saveRep(
      Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step)
      throws KettleException {
    try {
      rep.saveDatabaseMetaStepAttribute(id_transformation, id_step, "id_connection", databaseMeta);

      rep.saveStepAttribute(id_transformation, id_step, "schema", schemaName);
      rep.saveStepAttribute(id_transformation, id_step, "table", tableName);

      rep.saveStepAttribute(id_transformation, id_step, "load_action", loadAction);
      rep.saveStepAttribute(id_transformation, id_step, "PsqlPath", PsqlPath);

      rep.saveStepAttribute(id_transformation, id_step, "dbname_override", dbNameOverride);
      rep.saveStepAttribute(id_transformation, id_step, "enclosure", enclosure);
      rep.saveStepAttribute(id_transformation, id_step, "delimiter", delimiter);
      rep.saveStepAttribute(id_transformation, id_step, "stop_on_error", stopOnError);

      for (int i = 0; i < fieldTable.length; i++) {
        rep.saveStepAttribute(id_transformation, id_step, i, "stream_name", fieldTable[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "field_name", fieldStream[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "date_mask", dateMask[i]);
      }

      // Also, save the step-database relationship!
      if (databaseMeta != null) {
        rep.insertStepDatabase(id_transformation, id_step, databaseMeta.getObjectId());
      }
    } catch (Exception e) {
      throw new KettleException(
          BaseMessages.getString(PKG, "GPBulkLoaderMeta.Exception.UnableToSaveStepInfoToRepository")
              + id_step,
          e);
    }
  }
  public void saveRep(
      Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step)
      throws KettleException {
    try {
      rep.saveDatabaseMetaStepAttribute(id_transformation, id_step, "id_connection", databaseMeta);
      rep.saveStepAttribute(id_transformation, id_step, "commit", commitSize);
      rep.saveStepAttribute(id_transformation, id_step, "sql_field", sqlField);

      rep.saveStepAttribute(id_transformation, id_step, "insert_field", insertField);
      rep.saveStepAttribute(id_transformation, id_step, "update_field", updateField);
      rep.saveStepAttribute(id_transformation, id_step, "delete_field", deleteField);
      rep.saveStepAttribute(id_transformation, id_step, "read_field", readField);

      // Also, save the step-database relationship!
      if (databaseMeta != null) {
        rep.insertStepDatabase(id_transformation, id_step, databaseMeta.getObjectId());
      }

      rep.saveStepAttribute(id_transformation, id_step, "sqlFromfile", sqlFromfile);
      rep.saveStepAttribute(id_transformation, id_step, "sendOneStatement", sendOneStatement);
    } catch (Exception e) {
      throw new KettleException(
          BaseMessages.getString(PKG, "ExecSQLRowMeta.Exception.UnableToSaveStepInfo") + id_step,
          e);
    }
  }
  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();
        }
      }
    }
  }
  public void saveRep(
      Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step)
      throws KettleException {
    try {
      rep.saveDatabaseMetaStepAttribute(id_transformation, id_step, "id_connection", databaseMeta);
      rep.saveStepAttribute(id_transformation, id_step, "table", tablename);
      rep.saveStepAttribute(id_transformation, id_step, "fifo_file_name", fifoFileName);
      rep.saveStepAttribute(id_transformation, id_step, "sql_path", sqlPath);
      rep.saveStepAttribute(id_transformation, id_step, "encoding", encoding);
      rep.saveStepAttribute(id_transformation, id_step, "delimiter", delimiter);
      rep.saveStepAttribute(id_transformation, id_step, "continue_on_error", continueOnError);
      rep.saveStepAttribute(id_transformation, id_step, "error_file_name", errorFileName);
      rep.saveStepAttribute(
          id_transformation, id_step, "use_standard_conversion", useStandardConversion);
      rep.saveStepAttribute(id_transformation, id_step, "use_authentication", useAuthentication);
      rep.saveStepAttribute(id_transformation, id_step, "use_dynamic_vnode", useDynamicVNode);
      rep.saveStepAttribute(id_transformation, id_step, "use_SSV_delimiter", useSSV);
      rep.saveStepAttribute(
          id_transformation, id_step, "escape_special_characters", escapingSpecialCharacters);
      rep.saveStepAttribute(id_transformation, id_step, "use_vwload", usingVwload);
      rep.saveStepAttribute(id_transformation, id_step, "max_errors", maxNrErrors);
      rep.saveStepAttribute(id_transformation, id_step, "truncate_table", truncatingTable);
      rep.saveStepAttribute(id_transformation, id_step, "buffer_size", bufferSize);

      int nrRows =
          (fieldDatabase.length < fieldStream.length ? fieldStream.length : fieldDatabase.length);
      for (int idx = 0; idx < nrRows; idx++) {
        String columnName = (idx < fieldDatabase.length ? fieldDatabase[idx] : "");
        String streamName = (idx < fieldStream.length ? fieldStream[idx] : "");
        rep.saveStepAttribute(id_transformation, id_step, idx, "column_name", columnName);
        rep.saveStepAttribute(id_transformation, id_step, idx, "stream_name", streamName);
      }

      // Also, save the step-database relationship!
      if (databaseMeta != null) {
        rep.insertStepDatabase(id_transformation, id_step, databaseMeta.getObjectId());
      }
    } catch (Exception e) {
      throw new KettleException(
          "Unable to save step information to the repository for id_step=" + id_step, e);
    }
  }
  public void saveRep(
      Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step)
      throws KettleException {
    try {
      rep.saveDatabaseMetaStepAttribute(id_transformation, id_step, "id_connection", databaseMeta);
      rep.saveStepAttribute(id_transformation, id_step, "schema", schemaName);
      rep.saveStepAttribute(id_transformation, id_step, "table", tableName);
      rep.saveStepAttribute(id_transformation, id_step, "encoding", encoding);
      rep.saveStepAttribute(id_transformation, id_step, "enclosure", enclosure);
      rep.saveStepAttribute(id_transformation, id_step, "delimiter", delimiter);
      rep.saveStepAttribute(id_transformation, id_step, "escape_char", escapeChar);
      rep.saveStepAttribute(id_transformation, id_step, "fifo_file_name", fifoFileName);
      rep.saveStepAttribute(id_transformation, id_step, "replace", replacingData);
      rep.saveStepAttribute(id_transformation, id_step, "ignore", ignoringErrors);
      rep.saveStepAttribute(id_transformation, id_step, "local", localFile);
      rep.saveStepAttribute(id_transformation, id_step, "bulk_size", bulkSize);

      for (int i = 0; i < fieldTable.length; i++) {
        rep.saveStepAttribute(id_transformation, id_step, i, "stream_name", fieldTable[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "field_name", fieldStream[i]);
        rep.saveStepAttribute(
            id_transformation,
            id_step,
            i,
            "field_format_ok",
            getFieldFormatTypeCode(fieldFormatType[i]));
      }

      // Also, save the step-database relationship!
      if (databaseMeta != null) {
        rep.insertStepDatabase(id_transformation, id_step, databaseMeta.getObjectId());
      }
    } catch (Exception e) {
      throw new KettleException(
          BaseMessages.getString(
                  PKG, "MySQLBulkLoaderMeta.Exception.UnableToSaveStepInfoToRepository")
              + id_step,
          e);
    }
  }
  public void saveRep(Repository rep, ObjectId id_transformation, ObjectId id_step)
      throws KettleException {
    try {
      rep.saveDatabaseMetaStepAttribute(id_transformation, id_step, "id_connection", databaseMeta);
      rep.saveStepAttribute(id_transformation, id_step, "errors", maxErrors); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "schema", schemaName); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "table", tableName); // $NON-NLS-1$

      rep.saveStepAttribute(id_transformation, id_step, "load_method", loadMethod); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "load_action", loadAction); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "PsqlPath", PsqlPath); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "control_file", controlFile); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "data_file", dataFile); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "log_file", logFile); // $NON-NLS-1$

      rep.saveStepAttribute(id_transformation, id_step, "erase_files", eraseFiles); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "encoding", encoding); // $NON-NLS-1$
      rep.saveStepAttribute(
          id_transformation, id_step, "dbname_override", dbNameOverride); // $NON-NLS-1$

      for (int i = 0; i < fieldTable.length; i++) {
        rep.saveStepAttribute(
            id_transformation, id_step, i, "stream_name", fieldTable[i]); // $NON-NLS-1$
        rep.saveStepAttribute(
            id_transformation, id_step, i, "field_name", fieldStream[i]); // $NON-NLS-1$
        rep.saveStepAttribute(
            id_transformation, id_step, i, "date_mask", dateMask[i]); // $NON-NLS-1$
      }

      // Also, save the step-database relationship!
      if (databaseMeta != null)
        rep.insertStepDatabase(id_transformation, id_step, databaseMeta.getObjectId());
    } catch (Exception e) {
      throw new KettleException(
          BaseMessages.getString(PKG, "GPBulkLoaderMeta.Exception.UnableToSaveStepInfoToRepository")
              + id_step,
          e); //$NON-NLS-1$
    }
  }
  /**
   * Saves the database information into a given repository.
   *
   * @param databaseMeta The database metadata object to store
   * @throws KettleException if an error occurs.
   */
  public void saveDatabaseMeta(DatabaseMeta databaseMeta) throws KettleException {
    try {
      // If we don't have an ID, we don't know which entry in the database we need to update.
      // See if a database with the same name is already available...
      if (databaseMeta.getObjectId() == null) {
        databaseMeta.setObjectId(getDatabaseID(databaseMeta.getName()));
      }

      // Still not found? --> Insert
      if (databaseMeta.getObjectId() == null) {
        // Insert new Note in repository
        //
        databaseMeta.setObjectId(
            insertDatabase(
                databaseMeta.getName(),
                databaseMeta.getPluginId(),
                DatabaseMeta.getAccessTypeDesc(databaseMeta.getAccessType()),
                databaseMeta.getHostname(),
                databaseMeta.getDatabaseName(),
                databaseMeta.getDatabasePortNumberString(),
                databaseMeta.getUsername(),
                databaseMeta.getPassword(),
                databaseMeta.getServername(),
                databaseMeta.getDataTablespace(),
                databaseMeta.getIndexTablespace()));
      } else {
        // --> found entry with the same name...

        // Update the note...
        updateDatabase(
            databaseMeta.getObjectId(),
            databaseMeta.getName(),
            databaseMeta.getPluginId(),
            DatabaseMeta.getAccessTypeDesc(databaseMeta.getAccessType()),
            databaseMeta.getHostname(),
            databaseMeta.getDatabaseName(),
            databaseMeta.getDatabasePortNumberString(),
            databaseMeta.getUsername(),
            databaseMeta.getPassword(),
            databaseMeta.getServername(),
            databaseMeta.getDataTablespace(),
            databaseMeta.getIndexTablespace());
      }

      // For the extra attributes, just delete them and re-add them.
      delDatabaseAttributes(databaseMeta.getObjectId());

      // OK, now get a list of all the attributes set on the database connection...
      //
      Properties attributes = databaseMeta.getAttributes();
      Enumeration<Object> keys = databaseMeta.getAttributes().keys();
      while (keys.hasMoreElements()) {
        String code = (String) keys.nextElement();
        String attribute = (String) attributes.get(code);

        // Save this attribute
        //
        insertDatabaseAttribute(databaseMeta.getObjectId(), code, attribute);
      }
    } catch (KettleDatabaseException dbe) {
      throw new KettleException(
          "Error saving database connection or one of its attributes to the repository.", dbe);
    }
  }
 public void setAttribute(String code, DatabaseMeta databaseMeta) {
   dataNode.setProperty(code, databaseMeta.getObjectId().getId());
 }