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;
}
Aggregations