Search in sources :

Example 1 with DataType

use of com.healthmarketscience.jackcess.DataType 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

DataType (com.healthmarketscience.jackcess.DataType)1 BigDecimal (java.math.BigDecimal)1 FileObject (org.apache.commons.vfs2.FileObject)1 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)1 ValueMetaAndData (org.pentaho.di.core.row.ValueMetaAndData)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)1 ValueMetaNone (org.pentaho.di.core.row.value.ValueMetaNone)1