Search in sources :

Example 11 with ValueMetaAndData

use of org.pentaho.di.core.row.ValueMetaAndData in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConditionDelegate method insertCondition.

public synchronized ObjectId insertCondition(ObjectId id_condition_parent, Condition condition) throws KettleException {
    ObjectId id = repository.connectionDelegate.getNextConditionID();
    String tablename = KettleDatabaseRepository.TABLE_R_CONDITION;
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CONDITION_ID_CONDITION), id);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CONDITION_ID_CONDITION_PARENT), id_condition_parent);
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_CONDITION_NEGATED), Boolean.valueOf(condition.isNegated()));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CONDITION_OPERATOR), condition.getOperatorDesc());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CONDITION_LEFT_NAME), condition.getLeftValuename());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CONDITION_CONDITION_FUNCTION), condition.getFunctionDesc());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CONDITION_RIGHT_NAME), condition.getRightValuename());
    ObjectId id_value = null;
    ValueMetaAndData v = condition.getRightExact();
    if (v != null) {
        // We have to make sure that all data is saved irrespective of locale differences.
        // Here is where we force that
        // 
        ValueMetaInterface valueMeta = v.getValueMeta();
        valueMeta.setDecimalSymbol(ValueMetaAndData.VALUE_REPOSITORY_DECIMAL_SYMBOL);
        valueMeta.setGroupingSymbol(ValueMetaAndData.VALUE_REPOSITORY_GROUPING_SYMBOL);
        switch(valueMeta.getType()) {
            case ValueMetaInterface.TYPE_NUMBER:
                valueMeta.setConversionMask(ValueMetaAndData.VALUE_REPOSITORY_NUMBER_CONVERSION_MASK);
                break;
            case ValueMetaInterface.TYPE_INTEGER:
                valueMeta.setConversionMask(ValueMetaAndData.VALUE_REPOSITORY_INTEGER_CONVERSION_MASK);
                break;
            case ValueMetaInterface.TYPE_DATE:
                valueMeta.setConversionMask(ValueMetaAndData.VALUE_REPOSITORY_DATE_CONVERSION_MASK);
                break;
            default:
                break;
        }
        String stringValue = valueMeta.getString(v.getValueData());
        id_value = insertValue(valueMeta.getName(), valueMeta.getTypeDesc(), stringValue, valueMeta.isNull(v.getValueData()), condition.getRightExactID());
        condition.setRightExactID(id_value);
    }
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CONDITION_ID_VALUE_RIGHT), id_value);
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), tablename);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
    return id;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ObjectId(org.pentaho.di.repository.ObjectId) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 12 with ValueMetaAndData

use of org.pentaho.di.core.row.ValueMetaAndData in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConditionDelegate method loadCondition.

/**
 * Read a condition from the repository.
 *
 * @param id_condition
 *          The condition id
 * @throws KettleException
 *           if something goes wrong.
 */
public Condition loadCondition(ObjectId id_condition) throws KettleException {
    Condition condition = new Condition();
    try {
        RowMetaAndData r = getCondition(id_condition);
        if (r != null) {
            condition.setNegated(r.getBoolean("NEGATED", false));
            condition.setOperator(Condition.getOperator(r.getString("OPERATOR", null)));
            long conditionId = r.getInteger("ID_CONDITION", -1L);
            if (conditionId > 0) {
                condition.setObjectId(new LongObjectId(conditionId));
            } else {
                condition.setObjectId(null);
            }
            ObjectId[] subids = repository.getSubConditionIDs(condition.getObjectId());
            if (subids.length == 0) {
                condition.setLeftValuename(r.getString("LEFT_NAME", null));
                condition.setFunction(Condition.getFunction(r.getString("CONDITION_FUNCTION", null)));
                condition.setRightValuename(r.getString("RIGHT_NAME", null));
                long id_value = r.getInteger("ID_VALUE_RIGHT", -1L);
                if (id_value > 0) {
                    ValueMetaAndData v = repository.loadValueMetaAndData(new LongObjectId(id_value));
                    condition.setRightExact(v);
                }
            } else {
                for (int i = 0; i < subids.length; i++) {
                    condition.addCondition(loadCondition(subids[i]));
                }
            }
            return condition;
        } else {
            throw new KettleException("Condition with id_condition=" + id_condition + " could not be found in the repository");
        }
    } catch (KettleException dbe) {
        throw new KettleException("Error loading condition from the repository (id_condition=" + id_condition + ")", dbe);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ObjectId(org.pentaho.di.repository.ObjectId) LongObjectId(org.pentaho.di.repository.LongObjectId) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData)

Example 13 with ValueMetaAndData

use of org.pentaho.di.core.row.ValueMetaAndData in project pentaho-kettle by pentaho.

the class EnterValueDialog method test.

/**
 * Test the entered value
 */
public void test() {
    try {
        ValueMetaAndData v = getValue(valueMeta.getName());
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
        StringBuilder result = new StringBuilder();
        result.append(Const.CR).append(Const.CR).append("    ").append(v.toString());
        result.append(Const.CR).append("    ").append(v.toStringMeta());
        mb.setMessage(BaseMessages.getString(PKG, "EnterValueDialog.TestResult.Message", result.toString()));
        mb.setText(BaseMessages.getString(PKG, "EnterValueDialog.TestResult.Title"));
        mb.open();
    } catch (KettleValueException e) {
        new ErrorDialog(shell, "Error", "There was an error during data type conversion: ", e);
    }
}
Also used : ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) KettleValueException(org.pentaho.di.core.exception.KettleValueException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 14 with ValueMetaAndData

use of org.pentaho.di.core.row.ValueMetaAndData in project pentaho-kettle by pentaho.

the class DummyPluginDialog method open.

@Override
public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
    props.setLook(shell);
    setShellImage(shell, input);
    ModifyListener lsMod = new ModifyListener() {

        @Override
        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);
    // $NON-NLS-1$
    shell.setText(Messages.getString("DummyPluginDialog.Shell.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Stepname line
    wlStepname = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlStepname.setText(Messages.getString("DummyPluginDialog.StepName.Label"));
    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);
    // ValName line
    wlValName = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlValName.setText(Messages.getString("DummyPluginDialog.ValueName.Label"));
    props.setLook(wlValName);
    fdlValName = new FormData();
    fdlValName.left = new FormAttachment(0, 0);
    fdlValName.right = new FormAttachment(middle, -margin);
    fdlValName.top = new FormAttachment(wStepname, margin);
    wlValName.setLayoutData(fdlValName);
    wValName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wValName);
    wValName.addModifyListener(lsMod);
    fdValName = new FormData();
    fdValName.left = new FormAttachment(middle, 0);
    fdValName.right = new FormAttachment(100, 0);
    fdValName.top = new FormAttachment(wStepname, margin);
    wValName.setLayoutData(fdValName);
    // Value line
    wlValue = new Label(shell, SWT.RIGHT);
    // $NON-NLS-1$
    wlValue.setText(Messages.getString("DummyPluginDialog.ValueToAdd.Label"));
    props.setLook(wlValue);
    fdlValue = new FormData();
    fdlValue.left = new FormAttachment(0, 0);
    fdlValue.right = new FormAttachment(middle, -margin);
    fdlValue.top = new FormAttachment(wValName, margin);
    wlValue.setLayoutData(fdlValue);
    wbValue = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbValue);
    // $NON-NLS-1$
    wbValue.setText(Messages.getString("System.Button.Edit"));
    fdbValue = new FormData();
    fdbValue.right = new FormAttachment(100, 0);
    fdbValue.top = new FormAttachment(wValName, margin);
    wbValue.setLayoutData(fdbValue);
    wValue = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wValue);
    wValue.addModifyListener(lsMod);
    fdValue = new FormData();
    fdValue.left = new FormAttachment(middle, 0);
    fdValue.right = new FormAttachment(wbValue, -margin);
    fdValue.top = new FormAttachment(wValName, margin);
    wValue.setLayoutData(fdValue);
    wbValue.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            ValueMetaAndData v = (ValueMetaAndData) value.clone();
            EnterValueDialog evd = new EnterValueDialog(shell, SWT.NONE, v.getValueMeta(), v.getValueData());
            ValueMetaAndData newval = evd.open();
            if (newval != null) {
                value = newval;
                getData();
            }
        }
    });
    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wOK.setText(Messages.getString("System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    // $NON-NLS-1$
    wCancel.setText(Messages.getString("System.Button.Cancel"));
    BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, wValue);
    // Add listeners
    lsCancel = new Listener() {

        @Override
        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsOK = new Listener() {

        @Override
        public void handleEvent(Event e) {
            ok();
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    lsDef = new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wStepname.addSelectionListener(lsDef);
    wValName.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        @Override
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    // 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;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) ModifyListener(org.eclipse.swt.events.ModifyListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) EnterValueDialog(org.pentaho.di.ui.core.dialog.EnterValueDialog) ShellEvent(org.eclipse.swt.events.ShellEvent) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display)

Example 15 with ValueMetaAndData

use of org.pentaho.di.core.row.ValueMetaAndData in project pentaho-kettle by pentaho.

the class AccessInputMeta method getValueMetaAndData.

/**
 * Returns kettle type from Microsoft Access database also convert data to prepare kettle value
 *
 * @param : MS Access column
 * @param : destination field name
 * @param : MS Access column value
 * @return valuemeta and data
 */
public static ValueMetaAndData getValueMetaAndData(Column c, String name, Object data) {
    ValueMetaAndData valueMetaData = new ValueMetaAndData();
    // get data
    Object o = data;
    // Get column type
    DataType type = c.getType();
    int sourceValueType = ValueMetaInterface.TYPE_STRING;
    // We have to take of Meta AND data
    switch(type) {
        case BINARY:
            sourceValueType = ValueMetaInterface.TYPE_BINARY;
            break;
        case BOOLEAN:
            sourceValueType = ValueMetaInterface.TYPE_BOOLEAN;
            if (o != null) {
                o = Boolean.valueOf(o.toString());
            }
            break;
        case DOUBLE:
            sourceValueType = ValueMetaInterface.TYPE_NUMBER;
            break;
        case FLOAT:
            sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
            if (o != null) {
                o = new BigDecimal(Float.toString((Float) o));
            }
            break;
        case INT:
            sourceValueType = ValueMetaInterface.TYPE_NUMBER;
            if (o != null) {
                o = Double.parseDouble(o.toString());
            }
            break;
        case BYTE:
            sourceValueType = ValueMetaInterface.TYPE_NUMBER;
            if (o != null) {
                o = Double.parseDouble(o.toString());
            }
            break;
        case LONG:
            sourceValueType = ValueMetaInterface.TYPE_INTEGER;
            if (o != null) {
                Integer i = (Integer) o;
                o = i.longValue();
            }
            break;
        case MEMO:
            break;
        case MONEY:
            sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
            break;
        case NUMERIC:
            sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
            break;
        case SHORT_DATE_TIME:
            sourceValueType = ValueMetaInterface.TYPE_DATE;
            break;
        default:
            // Default it's string
            if (o != null) {
                o = o.toString();
            }
            break;
    }
    ValueMetaInterface sourceValueMeta;
    try {
        sourceValueMeta = ValueMetaFactory.createValueMeta(name == null ? c.getName() : name, sourceValueType);
    } catch (KettlePluginException e) {
        sourceValueMeta = new ValueMetaNone(name == null ? c.getName() : name);
    }
    sourceValueMeta.setLength(c.getLength(), c.getPrecision());
    // set value meta data and return it
    valueMetaData.setValueMeta(sourceValueMeta);
    if (o != null) {
        valueMetaData.setValueData(o);
    }
    return valueMetaData;
}
Also used : ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) DataType(com.healthmarketscience.jackcess.DataType) FileObject(org.apache.commons.vfs2.FileObject) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) BigDecimal(java.math.BigDecimal) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMetaAndData (org.pentaho.di.core.row.ValueMetaAndData)17 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)6 Condition (org.pentaho.di.core.Condition)4 KettleException (org.pentaho.di.core.exception.KettleException)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 KettleValueException (org.pentaho.di.core.exception.KettleValueException)3 RowMeta (org.pentaho.di.core.row.RowMeta)3 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)3 LongObjectId (org.pentaho.di.repository.LongObjectId)2 ObjectId (org.pentaho.di.repository.ObjectId)2 ParameterGenerationTest.newCondition (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition)2 Node (org.w3c.dom.Node)2 Column (com.healthmarketscience.jackcess.Column)1 DataType (com.healthmarketscience.jackcess.DataType)1 DBObject (com.mongodb.DBObject)1 BigDecimal (java.math.BigDecimal)1 FileObject (org.apache.commons.vfs2.FileObject)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1