Search in sources :

Example 1 with CombinationLookupMeta

use of org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta in project pentaho-kettle by pentaho.

the class CombinationLookupDialog method create.

/**
 * Generate code for create table. Conversions done by database.
 */
private void create() {
    try {
        // Gather info...
        CombinationLookupMeta info = new CombinationLookupMeta();
        getInfo(info);
        // new name might not yet be linked to other steps!
        String name = stepname;
        StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "CombinationLookupDialog.StepMeta.Title"), name, info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
        if (!sql.hasError()) {
            if (sql.hasSQL()) {
                SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                sqledit.open();
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                mb.setMessage(BaseMessages.getString(PKG, "CombinationLookupDialog.NoSQLNeeds.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "CombinationLookupDialog.NoSQLNeeds.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "CombinationLookupDialog.SQLError.DialogTitle"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "CombinationLookupDialog.UnableToCreateSQL.DialogTitle"), BaseMessages.getString(PKG, "CombinationLookupDialog.UnableToCreateSQL.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) CombinationLookupMeta(org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with CombinationLookupMeta

use of org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta in project pentaho-kettle by pentaho.

the class CombinationLookupDialog method ok.

private void ok() {
    if (Utils.isEmpty(wStepname.getText())) {
        return;
    }
    CombinationLookupMeta oldMetaState = (CombinationLookupMeta) input.clone();
    getInfo(input);
    // return value
    stepname = wStepname.getText();
    if (transMeta.findDatabase(wConnection.getText()) == null) {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "CombinationLookupDialog.NoValidConnection.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "CombinationLookupDialog.NoValidConnection.DialogTitle"));
        mb.open();
    }
    if (!input.equals(oldMetaState)) {
        input.setChanged();
    }
    dispose();
}
Also used : CombinationLookupMeta(org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 3 with CombinationLookupMeta

use of org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta in project pentaho-kettle by pentaho.

the class JobGenerator method generateCombinationLookupStepFromLogicalTable.

protected StepMeta generateCombinationLookupStepFromLogicalTable(DatabaseMeta databaseMeta, LogicalTable logicalTable) {
    String name = ConceptUtil.getName(logicalTable, locale);
    String description = ConceptUtil.getDescription(logicalTable, locale);
    String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(null, Const.NVL(phTable, name));
    CombinationLookupMeta meta = new CombinationLookupMeta();
    meta.setDatabaseMeta(databaseMeta);
    // TODO
    meta.setSchemaName(null);
    meta.setTablename(schemaTable);
    meta.setUseAutoinc(databaseMeta.supportsAutoinc());
    meta.setCacheSize(5000);
    meta.setCommitSize(500);
    // replace attribute fields with a TK
    meta.setReplaceFields(true);
    // Find the technical key (if any defined)
    // 
    LogicalColumn keyColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.TECHNICAL_KEY);
    if (keyColumn != null) {
        ValueMetaInterface keyValue = getValueForLogicalColumn(databaseMeta, keyColumn);
        meta.setTechnicalKeyField(keyValue.getName());
    }
    // Simply add all the attributes as key columns...
    // 
    List<LogicalColumn> attributes = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.ATTRIBUTE);
    meta.setKeyLookup(new String[attributes.size()]);
    meta.setKeyField(new String[attributes.size()]);
    for (int i = 0; i < attributes.size(); i++) {
        LogicalColumn logicalColumn = attributes.get(i);
        ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, logicalColumn);
        meta.getKeyLookup()[i] = valueMeta.getName();
        meta.getKeyField()[i] = valueMeta.getName();
    }
    StepMeta stepMeta = new StepMeta(name, meta);
    stepMeta.drawStep();
    stepMeta.setDescription(description);
    return stepMeta;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) CombinationLookupMeta(org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

CombinationLookupMeta (org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta)3 MessageBox (org.eclipse.swt.widgets.MessageBox)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 SQLStatement (org.pentaho.di.core.SQLStatement)1 KettleException (org.pentaho.di.core.exception.KettleException)1 Point (org.pentaho.di.core.gui.Point)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 SQLEditor (org.pentaho.di.ui.core.database.dialog.SQLEditor)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)1