Search in sources :

Example 1 with FieldValueInvalidException

use of com.revolsys.record.FieldValueInvalidException in project com.revolsys.open by revolsys.

the class MapReaderRecordReader method next.

@Override
public Record next() {
    if (hasNext()) {
        final MapEx source = this.mapIterator.next();
        final Record target = new ArrayRecord(this.recordDefinition);
        for (final FieldDefinition field : this.recordDefinition.getFields()) {
            final String name = field.getName();
            final Object value = source.get(name);
            if (value != null) {
                final DataType dataType = this.recordDefinition.getFieldType(name);
                final Object convertedValue;
                try {
                    convertedValue = dataType.toObject(value);
                } catch (final Throwable e) {
                    throw new FieldValueInvalidException(name, value, e);
                }
                target.setValue(name, convertedValue);
            }
        }
        return target;
    } else {
        throw new NoSuchElementException();
    }
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) FieldValueInvalidException(com.revolsys.record.FieldValueInvalidException) MapEx(com.revolsys.collection.map.MapEx) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

MapEx (com.revolsys.collection.map.MapEx)1 DataType (com.revolsys.datatype.DataType)1 ArrayRecord (com.revolsys.record.ArrayRecord)1 FieldValueInvalidException (com.revolsys.record.FieldValueInvalidException)1 Record (com.revolsys.record.Record)1 FieldDefinition (com.revolsys.record.schema.FieldDefinition)1 NoSuchElementException (java.util.NoSuchElementException)1