/** Adapted from KettleDatabaseRepositoryDatabaseDelegate.saveDatabaseMeta */
 protected boolean equals(DatabaseMeta databaseMeta, DatabaseMeta databaseMeta2) {
   if (!equals(databaseMeta.getName(), databaseMeta2.getName())) {
     return false;
   } else if (!equals(databaseMeta.getPluginId(), databaseMeta2.getPluginId())) {
     return false;
   } else if (!equals(databaseMeta.getAccessType(), databaseMeta2.getAccessType())) {
     return false;
   } else if (!equals(databaseMeta.getHostname(), databaseMeta2.getHostname())) {
     return false;
   } else if (!equals(databaseMeta.getDatabaseName(), databaseMeta2.getDatabaseName())) {
     return false;
   } else if (!equals(
       databaseMeta.getDatabasePortNumberString(), databaseMeta2.getDatabasePortNumberString())) {
     return false;
   } else if (!equals(databaseMeta.getUsername(), databaseMeta2.getUsername())) {
     return false;
   } else if (!equals(databaseMeta.getPassword(), databaseMeta2.getPassword())) {
     return false;
   } else if (!equals(databaseMeta.getServername(), databaseMeta2.getServername())) {
     return false;
   } else if (!equals(databaseMeta.getDataTablespace(), databaseMeta2.getDataTablespace())) {
     return false;
   } else if (!equals(databaseMeta.getIndexTablespace(), databaseMeta2.getIndexTablespace())) {
     return false;
   }
   Map<Object, Object> databaseMeta2Attributes =
       new HashMap<Object, Object>(databaseMeta2.getAttributes());
   for (Entry<Object, Object> databaseMetaEntry :
       new HashMap<Object, Object>(databaseMeta.getAttributes()).entrySet()) {
     Object value = databaseMeta2Attributes.remove(databaseMetaEntry.getKey());
     if (!equals(value, databaseMetaEntry.getValue())) {
       return false;
     }
   }
   if (databaseMeta2Attributes.size() > 0) {
     return false;
   }
   return true;
 }
  /**
   * 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);
    }
  }