Search in sources :

Example 1 with DBFField

use of com.linuxense.javadbf.DBFField in project pentaho-kettle by pentaho.

the class XBase method getFields.

@SuppressWarnings("fallthrough")
public RowMetaInterface getFields() throws KettleException {
    String debug = "get fields from XBase file";
    RowMetaInterface row = new RowMeta();
    try {
        // Fetch all field information
        // 
        debug = "allocate data types";
        datatype = new byte[reader.getFieldCount()];
        for (int i = 0; i < reader.getFieldCount(); i++) {
            if (log.isDebug()) {
                debug = "get field #" + i;
            }
            DBFField field = reader.getField(i);
            ValueMetaInterface value = null;
            datatype[i] = field.getDataType();
            switch(datatype[i]) {
                case // Memo
                DBFField.FIELD_TYPE_M:
                    debug = "memo field";
                    if ((log != null) && log.isDebug()) {
                        log.logDebug("Field #" + i + " is a memo-field! (" + field.getName() + ")");
                    }
                case // Character
                DBFField.FIELD_TYPE_C:
                    // case DBFField.FIELD_TYPE_P: // Picture
                    debug = "character field";
                    value = new ValueMetaString(field.getName());
                    value.setLength(field.getFieldLength());
                    break;
                // Integer
                case FIELD_TYPE_I:
                // Numeric
                case DBFField.FIELD_TYPE_N:
                case // Float
                DBFField.FIELD_TYPE_F:
                    debug = "Number field";
                    value = new ValueMetaNumber(field.getName());
                    value.setLength(field.getFieldLength(), field.getDecimalCount());
                    break;
                case // Logical
                DBFField.FIELD_TYPE_L:
                    debug = "Logical field";
                    value = new ValueMetaBoolean(field.getName());
                    value.setLength(-1, -1);
                    break;
                case // Date
                DBFField.FIELD_TYPE_D:
                    debug = "Date field";
                    value = new ValueMetaDate(field.getName());
                    value.setLength(-1, -1);
                    break;
                default:
                    if ((log != null) && (log.isDebug())) {
                        log.logDebug("Unknown Datatype" + datatype[i]);
                    }
            }
            if (value != null) {
                row.addValueMeta(value);
            }
        }
    } catch (Exception e) {
        throw new KettleException("Error reading DBF metadata (in part " + debug + ")", e);
    }
    return row;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) DBFField(com.linuxense.javadbf.DBFField) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) DBFException(com.linuxense.javadbf.DBFException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

DBFException (com.linuxense.javadbf.DBFException)1 DBFField (com.linuxense.javadbf.DBFField)1 IOException (java.io.IOException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)1 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)1 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1