/** Generate and bind the update statement. */
  @Override
  public void bind() throws SQLException {

    SpiUpdatePlan updatePlan = meta.getUpdatePlan(persistRequest);

    if (updatePlan.isEmptySetClause()) {
      emptySetClause = true;
      return;
    }

    sql = updatePlan.getSql();

    SpiTransaction t = persistRequest.getTransaction();

    PreparedStatement pstmt;
    if (persistRequest.isBatched()) {
      pstmt = getPstmt(t, sql, persistRequest, false);
    } else {
      pstmt = getPstmt(t, sql, false);
    }
    dataBind = bind(pstmt);
    meta.bind(persistRequest, this, updatePlan);

    setUpdateGenValues();

    logSql(sql);
  }
示例#2
0
  // Generate code for create table...
  // Conversions done by Database
  private void create() {
    try {
      UpdateMeta info = new UpdateMeta();
      getInfo(info);

      String name = stepname; // new name might not yet be linked to other steps!
      StepMeta stepinfo =
          new StepMeta(
              Messages.getString("UpdateDialog.StepMeta.Title"), name, info); // $NON-NLS-1$
      Row prev = transMeta.getPrevStepFields(stepname);

      SQLStatement sql = info.getSQLStatements(transMeta, stepinfo, prev);
      if (!sql.hasError()) {
        if (sql.hasSQL()) {
          SQLEditor sqledit =
              new SQLEditor(
                  shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
          sqledit.open();
        } else {
          MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
          mb.setMessage(Messages.getString("UpdateDialog.NoSQLNeeds.DialogMessage")); // $NON-NLS-1$
          mb.setText(Messages.getString("UpdateDialog.NoSQLNeeds.DialogTitle")); // $NON-NLS-1$
          mb.open();
        }
      } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(sql.getError());
        mb.setText(Messages.getString("UpdateDialog.SQLError.DialogTitle")); // $NON-NLS-1$
        mb.open();
      }
    } catch (KettleException ke) {
      new ErrorDialog(
          shell,
          Messages.getString("UpdateDialog.CouldNotBuildSQL.DialogTitle"),
          Messages.getString("UpdateDialog.CouldNotBuildSQL.DialogMessage"),
          ke); //$NON-NLS-1$ //$NON-NLS-2$
    }
  }
示例#3
0
  private void ok() {
    // Get the information for the dialog into the input structure.
    getInfo(input);

    if (input.getDatabaseMeta() == null) {
      MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
      mb.setMessage(
          Messages.getString("UpdateDialog.InvalidConnection.DialogMessage")); // $NON-NLS-1$
      mb.setText(Messages.getString("UpdateDialog.InvalidConnection.DialogTitle")); // $NON-NLS-1$
      mb.open();
    }

    dispose();
  }
示例#4
0
  public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();

    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    props.setLook(shell);
    setShellImage(shell, input);

    ModifyListener lsMod =
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            input.setChanged();
          }
        };
    changed = input.hasChanged();

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(Messages.getString("UpdateDialog.Shell.Title")); // $NON-NLS-1$

    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;

    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(Messages.getString("UpdateDialog.Stepname.Label")); // $NON-NLS-1$
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wStepname.setText(stepname);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);

    // Connection line
    wConnection = addConnectionLine(shell, wStepname, middle, margin);
    if (input.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) wConnection.select(0);
    wConnection.addModifyListener(lsMod);

    // Schema line...
    wlSchema = new Label(shell, SWT.RIGHT);
    wlSchema.setText(Messages.getString("UpdateDialog.TargetSchema.Label")); // $NON-NLS-1$
    props.setLook(wlSchema);
    fdlSchema = new FormData();
    fdlSchema.left = new FormAttachment(0, 0);
    fdlSchema.right = new FormAttachment(middle, -margin);
    fdlSchema.top = new FormAttachment(wConnection, margin * 2);
    wlSchema.setLayoutData(fdlSchema);

    wSchema = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wSchema);
    wSchema.addModifyListener(lsMod);
    fdSchema = new FormData();
    fdSchema.left = new FormAttachment(middle, 0);
    fdSchema.top = new FormAttachment(wConnection, margin * 2);
    fdSchema.right = new FormAttachment(100, 0);
    wSchema.setLayoutData(fdSchema);

    // Table line...
    wlTable = new Label(shell, SWT.RIGHT);
    wlTable.setText(Messages.getString("UpdateDialog.TargetTable.Label")); // $NON-NLS-1$
    props.setLook(wlTable);
    fdlTable = new FormData();
    fdlTable.left = new FormAttachment(0, 0);
    fdlTable.right = new FormAttachment(middle, -margin);
    fdlTable.top = new FormAttachment(wSchema, margin);
    wlTable.setLayoutData(fdlTable);

    wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbTable);
    wbTable.setText(Messages.getString("UpdateDialog.Browse.Button")); // $NON-NLS-1$
    fdbTable = new FormData();
    fdbTable.right = new FormAttachment(100, 0);
    fdbTable.top = new FormAttachment(wSchema, margin);
    wbTable.setLayoutData(fdbTable);

    wTable = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wTable);
    wTable.addModifyListener(lsMod);
    fdTable = new FormData();
    fdTable.left = new FormAttachment(middle, 0);
    fdTable.top = new FormAttachment(wSchema, margin);
    fdTable.right = new FormAttachment(wbTable, -margin);
    wTable.setLayoutData(fdTable);

    // Commit line
    wlCommit = new Label(shell, SWT.RIGHT);
    wlCommit.setText(Messages.getString("UpdateDialog..Commit.Label")); // $NON-NLS-1$
    props.setLook(wlCommit);
    fdlCommit = new FormData();
    fdlCommit.left = new FormAttachment(0, 0);
    fdlCommit.top = new FormAttachment(wTable, margin);
    fdlCommit.right = new FormAttachment(middle, -margin);
    wlCommit.setLayoutData(fdlCommit);
    wCommit = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCommit);
    wCommit.addModifyListener(lsMod);
    fdCommit = new FormData();
    fdCommit.left = new FormAttachment(middle, 0);
    fdCommit.top = new FormAttachment(wTable, margin);
    fdCommit.right = new FormAttachment(100, 0);
    wCommit.setLayoutData(fdCommit);

    wlErrorIgnored = new Label(shell, SWT.RIGHT);
    wlErrorIgnored.setText(Messages.getString("UpdateDialog.ErrorIgnored.Label")); // $NON-NLS-1$
    props.setLook(wlErrorIgnored);
    fdlErrorIgnored = new FormData();
    fdlErrorIgnored.left = new FormAttachment(0, 0);
    fdlErrorIgnored.top = new FormAttachment(wCommit, margin);
    fdlErrorIgnored.right = new FormAttachment(middle, -margin);
    wlErrorIgnored.setLayoutData(fdlErrorIgnored);

    wErrorIgnored = new Button(shell, SWT.CHECK);
    props.setLook(wErrorIgnored);
    wErrorIgnored.setToolTipText(
        Messages.getString("UpdateDialog.ErrorIgnored.ToolTip")); // $NON-NLS-1$
    fdErrorIgnored = new FormData();
    fdErrorIgnored.left = new FormAttachment(middle, 0);
    fdErrorIgnored.top = new FormAttachment(wCommit, margin);
    wErrorIgnored.setLayoutData(fdErrorIgnored);
    wErrorIgnored.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            input.setChanged();
            setFlags();
          }
        });

    wlIgnoreFlagField = new Label(shell, SWT.LEFT);
    wlIgnoreFlagField.setText(Messages.getString("UpdateDialog.FlagField.Label")); // $NON-NLS-1$
    props.setLook(wlIgnoreFlagField);
    fdlIgnoreFlagField = new FormData();
    fdlIgnoreFlagField.left = new FormAttachment(wErrorIgnored, margin);
    fdlIgnoreFlagField.top = new FormAttachment(wCommit, margin);
    wlIgnoreFlagField.setLayoutData(fdlIgnoreFlagField);
    wIgnoreFlagField = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wIgnoreFlagField);
    wIgnoreFlagField.addModifyListener(lsMod);
    fdIgnoreFlagField = new FormData();
    fdIgnoreFlagField.left = new FormAttachment(wlIgnoreFlagField, margin);
    fdIgnoreFlagField.top = new FormAttachment(wCommit, margin);
    fdIgnoreFlagField.right = new FormAttachment(100, 0);
    wIgnoreFlagField.setLayoutData(fdIgnoreFlagField);

    wlKey = new Label(shell, SWT.NONE);
    wlKey.setText(Messages.getString("UpdateDialog.Key.Label")); // $NON-NLS-1$
    props.setLook(wlKey);
    fdlKey = new FormData();
    fdlKey.left = new FormAttachment(0, 0);
    fdlKey.top = new FormAttachment(wIgnoreFlagField, margin);
    wlKey.setLayoutData(fdlKey);

    int nrKeyCols = 4;
    int nrKeyRows = (input.getKeyStream() != null ? input.getKeyStream().length : 1);

    ColumnInfo[] ciKey = new ColumnInfo[nrKeyCols];
    ciKey[0] =
        new ColumnInfo(
            Messages.getString("UpdateDialog.ColumnInfo.TableField"),
            ColumnInfo.COLUMN_TYPE_TEXT,
            false); //$NON-NLS-1$
    ciKey[1] =
        new ColumnInfo(
            Messages.getString("UpdateDialog.ColumnInfo.Comparator"),
            ColumnInfo.COLUMN_TYPE_CCOMBO,
            new String[] {
              "=", "<>", "<", "<=", ">", ">=", "LIKE", "BETWEEN", "IS NULL", "IS NOT NULL"
            }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
                // //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$
    ciKey[2] =
        new ColumnInfo(
            Messages.getString("UpdateDialog.ColumnInfo.StreamField1"),
            ColumnInfo.COLUMN_TYPE_TEXT,
            false); //$NON-NLS-1$
    ciKey[3] =
        new ColumnInfo(
            Messages.getString("UpdateDialog.ColumnInfo.StreamField2"),
            ColumnInfo.COLUMN_TYPE_TEXT,
            false); //$NON-NLS-1$

    wKey =
        new TableView(
            shell,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL,
            ciKey,
            nrKeyRows,
            lsMod,
            props);

    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(Messages.getString("UpdateDialog.GetFields.Button")); // $NON-NLS-1$
    fdGet = new FormData();
    fdGet.right = new FormAttachment(100, 0);
    fdGet.top = new FormAttachment(wlKey, margin);
    wGet.setLayoutData(fdGet);

    fdKey = new FormData();
    fdKey.left = new FormAttachment(0, 0);
    fdKey.top = new FormAttachment(wlKey, margin);
    fdKey.right = new FormAttachment(wGet, -margin);
    fdKey.bottom = new FormAttachment(wlKey, 190);
    wKey.setLayoutData(fdKey);

    // THE BUTTONS
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(Messages.getString("System.Button.OK")); // $NON-NLS-1$
    wSQL = new Button(shell, SWT.PUSH);
    wSQL.setText(Messages.getString("UpdateDialog.SQL.Button")); // $NON-NLS-1$
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(Messages.getString("System.Button.Cancel")); // $NON-NLS-1$

    setButtonPositions(new Button[] {wOK, wSQL, wCancel}, margin, null);

    // THE UPDATE/INSERT TABLE
    wlReturn = new Label(shell, SWT.NONE);
    wlReturn.setText(Messages.getString("UpdateDialog.Return.Label")); // $NON-NLS-1$
    props.setLook(wlReturn);
    fdlReturn = new FormData();
    fdlReturn.left = new FormAttachment(0, 0);
    fdlReturn.top = new FormAttachment(wKey, margin);
    wlReturn.setLayoutData(fdlReturn);

    int UpInsCols = 2;
    int UpInsRows = (input.getUpdateLookup() != null ? input.getUpdateLookup().length : 1);

    ColumnInfo[] ciReturn = new ColumnInfo[UpInsCols];
    ciReturn[0] =
        new ColumnInfo(
            Messages.getString("UpdateDialog.ColumnInfo.TableField"),
            ColumnInfo.COLUMN_TYPE_TEXT,
            false); //$NON-NLS-1$
    ciReturn[1] =
        new ColumnInfo(
            Messages.getString("UpdateDialog.ColumnInfo.StreamField"),
            ColumnInfo.COLUMN_TYPE_TEXT,
            false); //$NON-NLS-1$

    wReturn =
        new TableView(
            shell,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL,
            ciReturn,
            UpInsRows,
            lsMod,
            props);

    wGetLU = new Button(shell, SWT.PUSH);
    wGetLU.setText(Messages.getString("UpdateDialog.GetAndUpdateFields")); // $NON-NLS-1$
    fdGetLU = new FormData();
    fdGetLU.top = new FormAttachment(wlReturn, margin);
    fdGetLU.right = new FormAttachment(100, 0);
    wGetLU.setLayoutData(fdGetLU);

    fdReturn = new FormData();
    fdReturn.left = new FormAttachment(0, 0);
    fdReturn.top = new FormAttachment(wlReturn, margin);
    fdReturn.right = new FormAttachment(wGetLU, -margin);
    fdReturn.bottom = new FormAttachment(wOK, -2 * margin);
    wReturn.setLayoutData(fdReturn);

    // Add listeners
    lsOK =
        new Listener() {
          public void handleEvent(Event e) {
            ok();
          }
        };
    lsGet =
        new Listener() {
          public void handleEvent(Event e) {
            get();
          }
        };
    lsGetLU =
        new Listener() {
          public void handleEvent(Event e) {
            getUpdate();
          }
        };
    lsSQL =
        new Listener() {
          public void handleEvent(Event e) {
            create();
          }
        };
    lsCancel =
        new Listener() {
          public void handleEvent(Event e) {
            cancel();
          }
        };

    wOK.addListener(SWT.Selection, lsOK);
    wGet.addListener(SWT.Selection, lsGet);
    wGetLU.addListener(SWT.Selection, lsGetLU);
    wSQL.addListener(SWT.Selection, lsSQL);
    wCancel.addListener(SWT.Selection, lsCancel);

    lsDef =
        new SelectionAdapter() {
          public void widgetDefaultSelected(SelectionEvent e) {
            ok();
          }
        };

    wStepname.addSelectionListener(lsDef);
    wSchema.addSelectionListener(lsDef);
    wTable.addSelectionListener(lsDef);
    wCommit.addSelectionListener(lsDef);
    wIgnoreFlagField.addSelectionListener(lsDef);

    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(
        new ShellAdapter() {
          public void shellClosed(ShellEvent e) {
            cancel();
          }
        });

    wbTable.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            getTableName();
          }
        });

    // Set the shell size, based upon previous time...
    setSize();

    getData();
    input.setChanged(changed);

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    return stepname;
  }
示例#5
0
  private void getInfo(UpdateMeta inf) {
    // Table ktable = wKey.table;
    int nrkeys = wKey.nrNonEmpty();
    int nrfields = wReturn.nrNonEmpty();

    inf.allocate(nrkeys, nrfields);

    inf.setCommitSize(Const.toInt(wCommit.getText(), 0));

    log.logDebug(
        toString(),
        Messages.getString("UpdateDialog.Log.FoundKeys", nrkeys + "")); // $NON-NLS-1$ //$NON-NLS-2$
    for (int i = 0; i < nrkeys; i++) {
      TableItem item = wKey.getNonEmpty(i);
      inf.getKeyLookup()[i] = item.getText(1);
      inf.getKeyCondition()[i] = item.getText(2);
      inf.getKeyStream()[i] = item.getText(3);
      inf.getKeyStream2()[i] = item.getText(4);
    }

    // Table ftable = wReturn.table;

    log.logDebug(
        toString(),
        Messages.getString(
            "UpdateDialog.Log.FoundFields", nrfields + "")); // $NON-NLS-1$ //$NON-NLS-2$
    for (int i = 0; i < nrfields; i++) {
      TableItem item = wReturn.getNonEmpty(i);
      inf.getUpdateLookup()[i] = item.getText(1);
      inf.getUpdateStream()[i] = item.getText(2);
    }

    inf.setSchemaName(wSchema.getText());
    inf.setTableName(wTable.getText());
    inf.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));

    inf.setErrorIgnored(wErrorIgnored.getSelection());
    inf.setIgnoreFlagField(wIgnoreFlagField.getText());

    stepname = wStepname.getText(); // return value
  }
示例#6
0
 private void cancel() {
   stepname = null;
   input.setChanged(changed);
   dispose();
 }
示例#7
0
  /** Copy information from the meta-data input to the dialog fields. */
  public void getData() {
    int i;
    log.logDebug(toString(), Messages.getString("UpdateDialog.Log.GettingKeyInfo")); // $NON-NLS-1$

    wCommit.setText("" + input.getCommitSize()); // $NON-NLS-1$

    wErrorIgnored.setSelection(input.isErrorIgnored());
    if (input.getIgnoreFlagField() != null) wIgnoreFlagField.setText(input.getIgnoreFlagField());

    if (input.getKeyStream() != null)
      for (i = 0; i < input.getKeyStream().length; i++) {
        TableItem item = wKey.table.getItem(i);
        if (input.getKeyLookup()[i] != null) item.setText(1, input.getKeyLookup()[i]);
        if (input.getKeyCondition()[i] != null) item.setText(2, input.getKeyCondition()[i]);
        if (input.getKeyStream()[i] != null) item.setText(3, input.getKeyStream()[i]);
        if (input.getKeyStream2()[i] != null) item.setText(4, input.getKeyStream2()[i]);
      }

    if (input.getUpdateLookup() != null)
      for (i = 0; i < input.getUpdateLookup().length; i++) {
        TableItem item = wReturn.table.getItem(i);
        if (input.getUpdateLookup()[i] != null) item.setText(1, input.getUpdateLookup()[i]);
        if (input.getUpdateStream()[i] != null) item.setText(2, input.getUpdateStream()[i]);
      }

    if (input.getSchemaName() != null) wSchema.setText(input.getSchemaName());
    if (input.getTableName() != null) wTable.setText(input.getTableName());
    if (input.getDatabaseMeta() != null) wConnection.setText(input.getDatabaseMeta().getName());
    else if (transMeta.nrDatabases() == 1) {
      wConnection.setText(transMeta.getDatabase(0).getName());
    }

    wStepname.selectAll();
    wKey.setRowNums();
    wKey.optWidth(true);
    wReturn.setRowNums();
    wReturn.optWidth(true);

    setFlags();
  }
 public UpdateHandler(PersistRequestBean<?> persist, UpdateMeta meta) {
   super(persist, meta.isEmptyStringAsNull());
   this.meta = meta;
 }