protected void okPressed() {
    boolean hasErrors = popupValidationErrorDialogIfNecessary();

    if (!hasErrors) {
      try {
        conceptUtil.setId(wId.getText());
      } catch (ObjectAlreadyExistsException e) {
        if (logger.isErrorEnabled()) {
          logger.error("an exception occurred", e);
        }
        MessageDialog.openError(
            getShell(),
            Messages.getString("General.USER_TITLE_ERROR"),
            Messages.getString(
                "PhysicalTableDialog.USER_ERROR_PHYSICAL_TABLE_ID_EXISTS", wId.getText()));
        return;
      }

      // attempt to set the connection
      IStructuredSelection selection = (IStructuredSelection) comboViewer.getSelection();
      DatabaseMeta con = (DatabaseMeta) selection.getFirstElement();
      BusinessModel busModel = (BusinessModel) conceptUtil;
      if (!DUMMY_CON_NAME.equals(con.getName())) {
        busModel.setConnection((DatabaseMeta) con);
      } else {
        busModel.clearConnection();
      }

      super.okPressed();
    }
  }
  private void getTableName() {
    DatabaseMeta inf = null;
    // New class: SelectTableDialog
    int connr = wConnection.getSelectionIndex();
    if (connr >= 0) inf = transMeta.getDatabase(connr);

    if (inf != null) {
      logDebug(
          BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.Log.LookingAtConnection")
              + inf.toString()); // $NON-NLS-1$

      DatabaseExplorerDialog std =
          new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
      std.setSelectedSchemaAndTable(wSchema.getText(), wTable.getText());
      if (std.open()) {
        wSchema.setText(Const.NVL(std.getSchemaName(), ""));
        wTable.setText(Const.NVL(std.getTableName(), ""));
      }
    } else {
      MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
      mb.setMessage(
          BaseMessages.getString(
              PKG, "LucidDBBulkLoaderDialog.InvalidConnection.DialogMessage")); // $NON-NLS-1$
      mb.setText(
          BaseMessages.getString(
              PKG, "LucidDBBulkLoaderDialog.InvalidConnection.DialogTitle")); // $NON-NLS-1$
      mb.open();
    }
  }
  public boolean canFlipToNextPage() {
    DatabaseMeta source = getSourceDatabase();
    DatabaseMeta target = getTargetDatabase();

    if (source == null && target == null) {
      setErrorMessage(
          BaseMessages.getString(PKG, "CopyTableWizardPage1.SourceAndTargetIsNull.DialogMessage"));
      return false;
    } else if (source == null && target != null) {
      setErrorMessage(
          BaseMessages.getString(PKG, "CopyTableWizardPage1.SourceIsNull.DialogMessage"));
      return false;
    } else if (source != null && target == null) {
      setErrorMessage(
          BaseMessages.getString(PKG, "CopyTableWizardPage1.TargetIsNull.DialogMessage"));
      return false;
    } else if (source != null && target != null && source.equals(target)) {
      setErrorMessage(
          BaseMessages.getString(PKG, "CopyTableWizardPage1.SourceAndTargetIsSame.DialogMessage"));
      return false;
    } else {
      setErrorMessage(null);
      setMessage(BaseMessages.getString(PKG, "CopyTableWizardPage1.GoOnNext.DialogMessage"));
      return true;
    }
  }
  public void saveRep(Repository rep, long id_transformation, long id_step) throws KettleException {
    try {
      rep.saveStepAttribute(
          id_transformation,
          id_step,
          "id_connection",
          databaseMeta == null ? -1 : databaseMeta.getID()); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "commit", commitSize); // $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$

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

      // Also, save the step-database relationship!
      if (databaseMeta != null)
        rep.insertStepDatabase(id_transformation, id_step, databaseMeta.getID());
    } catch (Exception e) {
      throw new KettleException(
          Messages.getString("DeleteMeta.Exception.UnableToSaveStepInfo") + id_step,
          e); //$NON-NLS-1$
    }
  }
 public void addDatabases() {
   connections = new String[jobMeta.nrDatabases()];
   for (int i = 0; i < jobMeta.nrDatabases(); i++) {
     DatabaseMeta ci = jobMeta.getDatabase(i);
     connections[i] = ci.getName();
   }
 }
  private static String getFunction(Selection column, DatabaseMeta databaseMeta) {
    String fn = ""; // $NON-NLS-1$

    switch (column.getActiveAggregationType()) {
      case AVERAGE:
        fn = databaseMeta.getFunctionAverage();
        break;
      case COUNT_DISTINCT:
      case COUNT:
        fn = databaseMeta.getFunctionCount();
        break;
      case MAXIMUM:
        fn = databaseMeta.getFunctionMaximum();
        break;
      case MINIMUM:
        fn = databaseMeta.getFunctionMinimum();
        break;
      case SUM:
        fn = databaseMeta.getFunctionSum();
        break;
      default:
        break;
    }

    return fn;
  }
  /** Copy information from the meta-data input to the dialog fields. */
  public void getData() {
    for (DatabaseMeta dbMeta : transMeta.getDatabases()) {
      wReferenceDB.add(dbMeta.getName());
      wCompareDB.add(dbMeta.getName());
    }

    wReferenceDB.setText(
        input.getReferenceConnection() != null ? input.getReferenceConnection().getName() : "");
    wReferenceSchema.setText(Const.NVL(input.getReferenceSchemaField(), ""));
    wReferenceTable.setText(Const.NVL(input.getReferenceTableField(), ""));
    wCompareDB.setText(
        input.getCompareConnection() != null ? input.getCompareConnection().getName() : "");
    wCompareSchema.setText(Const.NVL(input.getCompareSchemaField(), ""));
    wCompareTable.setText(Const.NVL(input.getCompareTableField(), ""));
    wKeyFields.setText(Const.NVL(input.getKeyFieldsField(), ""));
    wExcludeFields.setText(Const.NVL(input.getExcludeFieldsField(), ""));

    wNrErrors.setText(Const.NVL(input.getNrErrorsField(), ""));
    wNrRecordsReference.setText(Const.NVL(input.getNrRecordsReferenceField(), ""));
    wNrRecordsCompare.setText(Const.NVL(input.getNrRecordsCompareField(), ""));
    wNrErrorsLeftJoin.setText(Const.NVL(input.getNrErrorsLeftJoinField(), ""));
    wNrErrorsInnerJoin.setText(Const.NVL(input.getNrErrorsInnerJoinField(), ""));
    wNrErrorsRightJoin.setText(Const.NVL(input.getNrErrorsRightJoinField(), ""));

    wKeyDesc.setText(Const.NVL(input.getKeyDescriptionField(), ""));
    wReferenceValue.setText(Const.NVL(input.getValueReferenceField(), ""));
    wCompareValue.setText(Const.NVL(input.getValueCompareField(), ""));

    setComboValues();

    wStepname.selectAll();
    wStepname.setFocus();
  }
  public void saveRep(Repository rep, long id_transformation, long id_step) throws KettleException {
    try {
      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,
          "id_connection_read",
          databaseReadMeta == null ? -1 : databaseReadMeta.getID()); // $NON-NLS-1$
      rep.saveStepAttribute(
          id_transformation,
          id_step,
          "id_connection_write",
          databaseWriteMeta == null
              ? -1
              : databaseWriteMeta
                  .getID()); //$NON-NLS-1$			rep.saveStepAttribute(id_transformation, id_step,
      // "commit",         commitSize); //$NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "cache_size", cacheSize); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "replace", replaceFields); // $NON-NLS-1$

      rep.saveStepAttribute(id_transformation, id_step, "crc", useHash); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "crcfield", hashField); // $NON-NLS-1$

      for (int i = 0; i < keyField.length; i++) {
        rep.saveStepAttribute(
            id_transformation, id_step, i, "lookup_key_name", keyField[i]); // $NON-NLS-1$
        rep.saveStepAttribute(
            id_transformation, id_step, i, "lookup_key_field", keyLookup[i]); // $NON-NLS-1$
      }

      rep.saveStepAttribute(
          id_transformation,
          id_step,
          "return_name",
          Const.isEmpty(technicalKeyField) ? "" : technicalKeyField); // $NON-NLS-1$
      rep.saveStepAttribute(id_transformation, id_step, "sequence", sequenceFrom); // $NON-NLS-1$
      rep.saveStepAttribute(
          id_transformation, id_step, "creation_method", techKeyCreation); // $NON-NLS-1$

      // For the moment still save 'use_autoinc' for backwards compatibility (Sven Boden).
      rep.saveStepAttribute(id_transformation, id_step, "use_autoinc", useAutoinc); // $NON-NLS-1$

      rep.saveStepAttribute(
          id_transformation, id_step, "last_update_field", lastUpdateField); // $NON-NLS-1$

      // Also, save the step-database relationship!
      if (databaseReadMeta != null)
        rep.insertStepDatabase(id_transformation, id_step, databaseReadMeta.getID());
      if (databaseWriteMeta != null)
        rep.insertStepDatabase(id_transformation, id_step, databaseWriteMeta.getID());
    } catch (Exception e) {
      throw new KettleException(
          Messages.getString("ConcurrentCombinationLookupMeta.Exception.UnableToSaveStepInfo")
              + id_step,
          e); //$NON-NLS-1$
    }
  }
  private void readData(Node stepnode, List<? extends SharedObjectInterface> databases)
      throws KettleXMLException {
    try {
      String commit, csize;

      schemaName = XMLHandler.getTagValue(stepnode, "schema"); // $NON-NLS-1$
      tablename = XMLHandler.getTagValue(stepnode, "table"); // $NON-NLS-1$
      String con = XMLHandler.getTagValue(stepnode, "connectionRead"); // $NON-NLS-1$
      databaseReadMeta = DatabaseMeta.findDatabase(databases, con);
      con = XMLHandler.getTagValue(stepnode, "connectionWrite"); // $NON-NLS-1$
      databaseWriteMeta = DatabaseMeta.findDatabase(databases, con);
      commit = XMLHandler.getTagValue(stepnode, "commit"); // $NON-NLS-1$
      commitSize = Const.toInt(commit, 0);
      csize = XMLHandler.getTagValue(stepnode, "cache_size"); // $NON-NLS-1$
      cacheSize = Const.toInt(csize, 0);

      replaceFields =
          "Y"
              .equalsIgnoreCase(
                  XMLHandler.getTagValue(stepnode, "replace")); // $NON-NLS-1$ //$NON-NLS-2$
      useHash =
          "Y"
              .equalsIgnoreCase(
                  XMLHandler.getTagValue(stepnode, "crc")); // $NON-NLS-1$ //$NON-NLS-2$

      hashField = XMLHandler.getTagValue(stepnode, "crcfield"); // $NON-NLS-1$

      Node keys = XMLHandler.getSubNode(stepnode, "fields"); // $NON-NLS-1$
      int nrkeys = XMLHandler.countNodes(keys, "key"); // $NON-NLS-1$

      allocate(nrkeys);

      // Read keys to dimension
      for (int i = 0; i < nrkeys; i++) {
        Node knode = XMLHandler.getSubNodeByNr(keys, "key", i); // $NON-NLS-1$
        keyField[i] = XMLHandler.getTagValue(knode, "name"); // $NON-NLS-1$
        keyLookup[i] = XMLHandler.getTagValue(knode, "lookup"); // $NON-NLS-1$
      }

      // If this is empty: use auto-increment field!
      sequenceFrom = XMLHandler.getTagValue(stepnode, "sequence"); // $NON-NLS-1$

      Node fields = XMLHandler.getSubNode(stepnode, "fields"); // $NON-NLS-1$
      Node retkey = XMLHandler.getSubNode(fields, "return"); // $NON-NLS-1$
      technicalKeyField = XMLHandler.getTagValue(retkey, "name"); // $NON-NLS-1$
      useAutoinc =
          !"N"
              .equalsIgnoreCase(
                  XMLHandler.getTagValue(retkey, "use_autoinc")); // $NON-NLS-1$ //$NON-NLS-2$
      lastUpdateField = XMLHandler.getTagValue(stepnode, "last_update_field"); // $NON-NLS-1$

      setTechKeyCreation(XMLHandler.getTagValue(retkey, "creation_method")); // $NON-NLS-1$
    } catch (Exception e) {
      throw new KettleXMLException(
          Messages.getString("ConcurrentCombinationLookupMeta.Exception.UnableToLoadStepInfo"),
          e); //$NON-NLS-1$
    }
  }
 public List<ResourceReference> getResourceDependencies(JobMeta jobMeta) {
   List<ResourceReference> references = super.getResourceDependencies(jobMeta);
   if (connection != null) {
     ResourceReference reference = new ResourceReference(this);
     reference.getEntries().add(new ResourceEntry(connection.getHostname(), ResourceType.SERVER));
     reference
         .getEntries()
         .add(new ResourceEntry(connection.getDatabaseName(), ResourceType.DATABASENAME));
     references.add(reference);
   }
   return references;
 }
 public void getDatabases() {
   wFields.removeAll();
   for (int i = 0; i < jobMeta.nrDatabases(); i++) {
     DatabaseMeta ci = jobMeta.getDatabase(i);
     if (ci != null) {
       wFields.add(new String[] {ci.getName(), "0", JobEntryCheckDbConnections.unitTimeDesc[0]});
     }
   }
   wFields.removeEmptyRows();
   wFields.setRowNums();
   wFields.optWidth(true);
 }
  public void createControl(Composite parent) {
    int margin = Const.MARGIN;

    // create the composite to hold the widgets
    Composite composite = new Composite(parent, SWT.NONE);
    props.setLook(composite);

    FormLayout compLayout = new FormLayout();
    compLayout.marginHeight = Const.FORM_MARGIN;
    compLayout.marginWidth = Const.FORM_MARGIN;
    composite.setLayout(compLayout);

    wSourceDB = new List(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    props.setLook(wSourceDB);
    for (int i = 0; i < databases.size(); i++) {
      DatabaseMeta dbInfo = databases.get(i);
      wSourceDB.add(dbInfo.getName());
    }
    fdSourceDB = new FormData();
    fdSourceDB.top = new FormAttachment(0, 0);
    fdSourceDB.left = new FormAttachment(0, 0);
    fdSourceDB.bottom = new FormAttachment(100, 0);
    fdSourceDB.right = new FormAttachment(50, 0);
    wSourceDB.setLayoutData(fdSourceDB);
    wSourceDB.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            setPageComplete(false);
          }
        });

    wTargetDB = new List(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    props.setLook(wTargetDB);
    for (int i = 0; i < databases.size(); i++) {
      DatabaseMeta dbInfo = databases.get(i);
      wTargetDB.add(dbInfo.getName());
    }
    fdTargetDB = new FormData();
    fdTargetDB.top = new FormAttachment(0, 0);
    fdTargetDB.left = new FormAttachment(50, margin);
    fdTargetDB.bottom = new FormAttachment(100, 0);
    fdTargetDB.right = new FormAttachment(100, 0);
    wTargetDB.setLayoutData(fdTargetDB);
    wTargetDB.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            setPageComplete(false);
          }
        });

    // set the composite as the control for this page
    setControl(composite);
  }
Example #13
0
 // This method is for backwards compatibility of already defined
 // isExact formulas that may contain at the root an aggregate function.
 private static boolean hasAggregateDefinedAlready(String sql, DatabaseMeta databaseMeta) {
   String trimmed = sql.trim();
   return trimmed.startsWith(databaseMeta.getFunctionAverage() + "(")
       || //$NON-NLS-1$
       trimmed.startsWith(databaseMeta.getFunctionCount() + "(")
       || //$NON-NLS-1$
       trimmed.startsWith(databaseMeta.getFunctionMaximum() + "(")
       || //$NON-NLS-1$
       trimmed.startsWith(databaseMeta.getFunctionMinimum() + "(")
       || //$NON-NLS-1$
       trimmed.startsWith(databaseMeta.getFunctionSum() + "("); // $NON-NLS-1$
 }
  /**
   * Adds db connection text boxes for input
   *
   * @return the last control specified
   */
  protected Control addDbConnectionInputs() {
    List<String> ibConnections = new ArrayList<String>();
    for (DatabaseMeta dbMeta : transMeta.getDatabases()) {
      if (dbMeta.getDatabaseInterface() instanceof IngresDatabaseMeta) {
        ibConnections.add(dbMeta.getName());
      }
    }
    serverConnection =
        addStandardSelect(
            "Connection", wStepname, ibConnections.toArray(new String[ibConnections.size()]));

    return serverConnection;
  }
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepMeta,
      RowMetaInterface prev,
      String[] input,
      String[] output,
      RowMetaInterface info,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {
    if (prev != null) {
      // Lookup: we do a lookup on the natural keys
      for (int i = 0; i < keyLookup.length; i++) {
        ValueMetaInterface v = prev.searchValueMeta(keyStream[i]);

        DatabaseImpact ii =
            new DatabaseImpact(
                DatabaseImpact.TYPE_IMPACT_READ,
                transMeta.getName(),
                stepMeta.getName(),
                databaseMeta.getDatabaseName(),
                tableName,
                keyLookup[i],
                keyStream[i],
                v != null ? v.getOrigin() : "?",
                "",
                "Type = " + v.toStringMeta());
        impact.add(ii);
      }

      // Insert update fields : read/write
      for (int i = 0; i < updateLookup.length; i++) {
        ValueMetaInterface v = prev.searchValueMeta(updateStream[i]);

        DatabaseImpact ii =
            new DatabaseImpact(
                DatabaseImpact.TYPE_IMPACT_READ_WRITE,
                transMeta.getName(),
                stepMeta.getName(),
                databaseMeta.getDatabaseName(),
                tableName,
                updateLookup[i],
                updateStream[i],
                v != null ? v.getOrigin() : "?",
                "",
                "Type = " + v.toStringMeta());
        impact.add(ii);
      }
    }
  }
  /** Get a list of columns, comma separated, allow the user to select from it. */
  private void getListColumns() {
    if (!Const.isEmpty(wTablename.getText())) {
      DatabaseMeta databaseMeta = jobMeta.findDatabase(wConnection.getText());
      if (databaseMeta != null) {
        Database database = new Database(loggingObject, databaseMeta);
        database.shareVariablesWith(jobMeta);
        try {
          database.connect();
          String schemaTable =
              databaseMeta.getQuotedSchemaTableCombination(
                  wSchemaname.getText(), wTablename.getText());
          RowMetaInterface row = database.getTableFields(schemaTable);
          String[] available = row.getFieldNames();

          String[] source = wListattribut.getText().split(",");
          for (int i = 0; i < source.length; i++) {
            source[i] = Const.trim(source[i]);
          }
          int[] idxSource = Const.indexsOfStrings(source, available);
          EnterSelectionDialog dialog =
              new EnterSelectionDialog(
                  shell,
                  available,
                  BaseMessages.getString(PKG, "JobMysqlBulkLoad.SelectColumns.Title"),
                  BaseMessages.getString(PKG, "JobMysqlBulkLoad.SelectColumns.Message"));
          dialog.setMulti(true);
          dialog.setAvoidQuickSearch();
          dialog.setSelectedNrs(idxSource);
          if (dialog.open() != null) {
            String columns = "";
            int[] idx = dialog.getSelectionIndeces();
            for (int i = 0; i < idx.length; i++) {
              if (i > 0) {
                columns += ", ";
              }
              columns += available[idx[i]];
            }
            wListattribut.setText(columns);
          }
        } catch (KettleDatabaseException e) {
          new ErrorDialog(
              shell,
              BaseMessages.getString(PKG, "System.Dialog.Error.Title"),
              BaseMessages.getString(PKG, "JobMysqlBulkLoad.ConnectionError2.DialogMessage"),
              e);
        } finally {
          database.disconnect();
        }
      }
    }
  }
  public void removeConnection() {
    try {
      Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems();

      if (connections != null && !connections.isEmpty()) {
        for (Object obj : connections) {
          if (obj != null && obj instanceof UIDatabaseConnection) {
            UIDatabaseConnection connection = (UIDatabaseConnection) obj;

            DatabaseMeta databaseMeta = connection.getDatabaseMeta();

            // Make sure this connection already exists and store its id for updating
            ObjectId idDatabase = repository.getDatabaseID(databaseMeta.getName());
            if (idDatabase == null) {
              MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
              mb.setMessage(
                  BaseMessages.getString(
                      PKG,
                      "RepositoryExplorerDialog.Connection.Delete.DoesNotExists.Message",
                      databaseMeta.getName()));
              mb.setText(
                  BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Delete.Title"));
              mb.open();
            } else {
              repository.deleteDatabaseMeta(databaseMeta.getName());
            }
          }
        }
      } else {
        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        mb.setMessage(
            BaseMessages.getString(
                PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message"));
        mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Delete.Title"));
        mb.open();
      }
    } catch (KettleException e) {
      if (mainController == null || !mainController.handleLostRepository(e)) {
        new ErrorDialog(
            shell,
            BaseMessages.getString(
                PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"),
            BaseMessages.getString(
                PKG, "RepositoryExplorerDialog.Connection.Remove.UnexpectedError.Message"),
            e);
      }
    } finally {
      refreshConnectionList();
    }
  }
  public void createConnection() {
    try {
      DatabaseMeta databaseMeta = new DatabaseMeta();
      databaseMeta.initializeVariablesFrom(null);
      getDatabaseDialog().setDatabaseMeta(databaseMeta);

      String dbName = getDatabaseDialog().open();
      if (dbName != null) {
        dbName = dbName.trim();
        if (!dbName.isEmpty()) {
          // See if this user connection exists...
          ObjectId idDatabase = repository.getDatabaseID(dbName);
          if (idDatabase == null) {
            repository.insertLogEntry(
                BaseMessages.getString(
                    PKG,
                    "ConnectionsController.Message.CreatingDatabase",
                    getDatabaseDialog().getDatabaseMeta().getName()));
            repository.save(
                getDatabaseDialog().getDatabaseMeta(), Const.VERSION_COMMENT_INITIAL_VERSION, null);
          } else {
            showAlreadyExistsMessage();
          }
        }
      }
      // We should be able to tell the difference between a cancel and an empty database name
      //
      // else {
      // MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
      // mb.setMessage(BaseMessages.getString(PKG,
      // "RepositoryExplorerDialog.Connection.Edit.MissingName.Message"));
      // mb.setText(BaseMessages.getString(PKG,
      // "RepositoryExplorerDialog.Connection.Edit.MissingName.Title"));
      // mb.open();
      // }
    } catch (KettleException e) {
      if (mainController == null || !mainController.handleLostRepository(e)) {
        new ErrorDialog(
            shell,
            BaseMessages.getString(
                PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"),
            BaseMessages.getString(
                PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Message"),
            e);
      }
    } finally {
      refreshConnectionList();
    }
  }
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepMeta,
      RowMetaInterface prev,
      String input[],
      String output[],
      RowMetaInterface info) {
    // The keys are read-only...
    for (int i = 0; i < keyField.length; i++) {
      ValueMetaInterface v = prev.searchValueMeta(keyField[i]);
      DatabaseImpact ii =
          new DatabaseImpact(
              DatabaseImpact.TYPE_IMPACT_READ_WRITE,
              transMeta.getName(),
              stepMeta.getName(),
              databaseWriteMeta.getDatabaseName(),
              tablename,
              keyLookup[i],
              keyField[i],
              v != null ? v.getOrigin() : "?", // $NON-NLS-1$
              "", //$NON-NLS-1$
              useHash
                  ? Messages.getString("ConcurrentCombinationLookupMeta.ReadAndInsert.Label")
                  : Messages.getString(
                      "ConcurrentCombinationLookupMeta.LookupAndInsert.Label") //$NON-NLS-1$
              // //$NON-NLS-2$
              );
      impact.add(ii);
    }

    // Do we lookup-on the hash-field?
    if (useHash) {
      DatabaseImpact ii =
          new DatabaseImpact(
              DatabaseImpact.TYPE_IMPACT_READ_WRITE,
              transMeta.getName(),
              stepMeta.getName(),
              databaseWriteMeta.getDatabaseName(),
              tablename,
              hashField,
              "", //$NON-NLS-1$
              "", //$NON-NLS-1$
              "", //$NON-NLS-1$
              Messages.getString("ConcurrentCombinationLookupMeta.KeyLookup.Label") // $NON-NLS-1$
              );
      impact.add(ii);
    }
  }
 /**
  * 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();
 }
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepMeta,
      RowMetaInterface prev,
      String input[],
      String output[],
      RowMetaInterface info)
      throws KettleStepException {
    if (prev != null) {
      /* DEBUG CHECK THIS */
      // Insert dateMask fields : read/write
      for (int i = 0; i < fieldTable.length; i++) {
        ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);

        DatabaseImpact ii =
            new DatabaseImpact(
                DatabaseImpact.TYPE_IMPACT_READ_WRITE,
                transMeta.getName(),
                stepMeta.getName(),
                databaseMeta.getDatabaseName(),
                transMeta.environmentSubstitute(tableName),
                fieldTable[i],
                fieldStream[i],
                v != null ? v.getOrigin() : "?",
                "",
                "Type = " + v.toStringMeta()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        impact.add(ii);
      }
    }
  }
 public DatabaseMeta getTargetDatabase() {
   if (wTargetDB.getSelection().length == 1) {
     String targetDbName = wTargetDB.getSelection()[0];
     return DatabaseMeta.findDatabase(databases, targetDbName);
   }
   return null;
 }
  public SQLStatement getSQLStatements(
      TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev) throws KettleStepException {
    SQLStatement retval =
        new SQLStatement(stepMeta.getName(), databaseMeta, null); // default: nothing to do!

    if (databaseMeta != null) {
      if (prev != null && prev.size() > 0) {
        // Copy the row
        RowMetaInterface tableFields = new RowMeta();

        // Now change the field names
        for (int i = 0; i < fieldTable.length; i++) {
          ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
          if (v != null) {
            ValueMetaInterface tableField = v.clone();
            tableField.setName(fieldTable[i]);
            tableFields.addValueMeta(tableField);
          } else {
            throw new KettleStepException(
                "Unable to find field [" + fieldStream[i] + "] in the input rows");
          }
        }

        if (!Const.isEmpty(tableName)) {
          Database db = new Database(loggingObject, databaseMeta);
          db.shareVariablesWith(transMeta);
          try {
            db.connect();

            String schemaTable =
                databaseMeta.getQuotedSchemaTableCombination(
                    transMeta.environmentSubstitute(schemaName),
                    transMeta.environmentSubstitute(tableName));
            String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);

            if (sql.length() == 0) retval.setSQL(null);
            else retval.setSQL(sql);
          } catch (KettleException e) {
            retval.setError(
                BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred")
                    + e.getMessage()); // $NON-NLS-1$
          }
        } else {
          retval.setError(
              BaseMessages.getString(
                  PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection")); // $NON-NLS-1$
        }
      } else {
        retval.setError(
            BaseMessages.getString(
                PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields")); // $NON-NLS-1$
      }
    } else {
      retval.setError(
          BaseMessages.getString(
              PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined")); // $NON-NLS-1$
    }

    return retval;
  }
  public RowMetaInterface getRequiredFields(VariableSpace space) throws KettleException {
    String realTableName = space.environmentSubstitute(tableName);
    String realSchemaName = space.environmentSubstitute(schemaName);

    if (databaseMeta != null) {
      Database db = new Database(loggingObject, databaseMeta);
      try {
        db.connect();

        if (!Const.isEmpty(realTableName)) {
          String schemaTable =
              databaseMeta.getQuotedSchemaTableCombination(realSchemaName, realTableName);

          // Check if this table exists...
          if (db.checkTableExists(schemaTable)) {
            return db.getTableFields(schemaTable);
          } else {
            throw new KettleException(
                BaseMessages.getString(PKG, "GPBulkLoaderMeta.Exception.TableNotFound"));
          }
        } else {
          throw new KettleException(
              BaseMessages.getString(PKG, "GPBulkLoaderMeta.Exception.TableNotSpecified"));
        }
      } catch (Exception e) {
        throw new KettleException(
            BaseMessages.getString(PKG, "GPBulkLoaderMeta.Exception.ErrorGettingFields"), e);
      } finally {
        db.disconnect();
      }
    } else {
      throw new KettleException(
          BaseMessages.getString(PKG, "GPBulkLoaderMeta.Exception.ConnectionNotDefined"));
    }
  }
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepMeta,
      RowMetaInterface prev,
      String[] input,
      String[] output,
      RowMetaInterface info)
      throws KettleStepException {
    if (prev != null) {
      // Lookup: we do a lookup on the natural keys
      for (int i = 0; i < keyLookup.length; i++) {
        ValueMetaInterface v = prev.searchValueMeta(keyStream[i]);

        DatabaseImpact ii =
            new DatabaseImpact(
                DatabaseImpact.TYPE_IMPACT_DELETE,
                transMeta.getName(),
                stepMeta.getName(),
                databaseMeta.getDatabaseName(),
                tableName,
                keyLookup[i],
                keyStream[i],
                v != null ? v.getOrigin() : "?",
                "",
                "Type = " + v.toStringMeta()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        impact.add(ii);
      }
    }
  }
  @Before
  public void setUp() throws Exception {
    MockDriver.registerInstance();
    Job job = new Job(null, new JobMeta());
    entry = new JobEntryEvalTableContent();

    job.getJobMeta().addJobEntry(new JobEntryCopy(entry));
    entry.setParentJob(job);

    job.setStopped(false);

    DatabaseMeta dbMeta = new DatabaseMeta();
    dbMeta.setDatabaseType("mock-db");

    entry.setDatabase(dbMeta);
  }
  public void readRep(
      Repository rep, long id_step, List<DatabaseMeta> databases, Map<String, Counter> counters)
      throws KettleException {
    try {
      long id_connection = rep.getStepAttributeInteger(id_step, "id_connection"); // $NON-NLS-1$
      databaseMeta = DatabaseMeta.findDatabase(databases, id_connection);

      commitSize = (int) rep.getStepAttributeInteger(id_step, "commit"); // $NON-NLS-1$
      schemaName = rep.getStepAttributeString(id_step, "schema"); // $NON-NLS-1$
      tableName = rep.getStepAttributeString(id_step, "table"); // $NON-NLS-1$

      int nrkeys = rep.countNrStepAttributes(id_step, "key_name"); // $NON-NLS-1$

      allocate(nrkeys);

      for (int i = 0; i < nrkeys; i++) {
        keyStream[i] = rep.getStepAttributeString(id_step, i, "key_name"); // $NON-NLS-1$
        keyLookup[i] = rep.getStepAttributeString(id_step, i, "key_field"); // $NON-NLS-1$
        keyCondition[i] = rep.getStepAttributeString(id_step, i, "key_condition"); // $NON-NLS-1$
        keyStream2[i] = rep.getStepAttributeString(id_step, i, "key_name2"); // $NON-NLS-1$
      }
    } catch (Exception e) {
      throw new KettleException(
          Messages.getString("DeleteMeta.Exception.UnexpectedErrorInReadingStepInfo"),
          e); //$NON-NLS-1$
    }
  }
  private void readData(Node stepnode, List<? extends SharedObjectInterface> databases)
      throws KettleXMLException {
    try {
      String csize;
      int nrkeys;

      String con = XMLHandler.getTagValue(stepnode, "connection"); // $NON-NLS-1$
      databaseMeta = DatabaseMeta.findDatabase(databases, con);
      csize = XMLHandler.getTagValue(stepnode, "commit"); // $NON-NLS-1$
      commitSize = Const.toInt(csize, 0);
      schemaName =
          XMLHandler.getTagValue(stepnode, "lookup", "schema"); // $NON-NLS-1$ //$NON-NLS-2$
      tableName = XMLHandler.getTagValue(stepnode, "lookup", "table"); // $NON-NLS-1$ //$NON-NLS-2$

      Node lookup = XMLHandler.getSubNode(stepnode, "lookup"); // $NON-NLS-1$
      nrkeys = XMLHandler.countNodes(lookup, "key"); // $NON-NLS-1$

      allocate(nrkeys);

      for (int i = 0; i < nrkeys; i++) {
        Node knode = XMLHandler.getSubNodeByNr(lookup, "key", i); // $NON-NLS-1$

        keyStream[i] = XMLHandler.getTagValue(knode, "name"); // $NON-NLS-1$
        keyLookup[i] = XMLHandler.getTagValue(knode, "field"); // $NON-NLS-1$
        keyCondition[i] = XMLHandler.getTagValue(knode, "condition"); // $NON-NLS-1$
        if (keyCondition[i] == null) keyCondition[i] = "="; // $NON-NLS-1$
        keyStream2[i] = XMLHandler.getTagValue(knode, "name2"); // $NON-NLS-1$
      }

    } catch (Exception e) {
      throw new KettleXMLException(
          Messages.getString("DeleteMeta.Exception.UnableToReadStepInfoFromXML"), e); // $NON-NLS-1$
    }
  }
  public String getXML() {
    StringBuilder retval = new StringBuilder(400);

    retval
        .append("    ")
        .append(
            XMLHandler.addTagValue(
                "connection", databaseMeta == null ? "" : databaseMeta.getName()));
    retval.append("    ").append(XMLHandler.addTagValue("commit", commitSize));
    retval.append("    ").append(XMLHandler.addTagValue("update_bypassed", updateBypassed));
    retval.append("    <lookup>").append(Const.CR);
    retval.append("      ").append(XMLHandler.addTagValue("schema", schemaName));
    retval.append("      ").append(XMLHandler.addTagValue("table", tableName));

    for (int i = 0; i < keyStream.length; i++) {
      retval.append("      <key>").append(Const.CR);
      retval.append("        ").append(XMLHandler.addTagValue("name", keyStream[i]));
      retval.append("        ").append(XMLHandler.addTagValue("field", keyLookup[i]));
      retval.append("        ").append(XMLHandler.addTagValue("condition", keyCondition[i]));
      retval.append("        ").append(XMLHandler.addTagValue("name2", keyStream2[i]));
      retval.append("      </key>").append(Const.CR);
    }

    for (int i = 0; i < updateLookup.length; i++) {
      retval.append("      <value>").append(Const.CR);
      retval.append("        ").append(XMLHandler.addTagValue("name", updateLookup[i]));
      retval.append("        ").append(XMLHandler.addTagValue("rename", updateStream[i]));
      retval.append("        ").append(XMLHandler.addTagValue("update", update[i].booleanValue()));
      retval.append("      </value>").append(Const.CR);
    }

    retval.append("    </lookup>").append(Const.CR);

    return retval.toString();
  }
  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);
    }
  }