Search in sources :

Example 1 with ArrayRecord

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

the class RecordDefinitionConvertRecordReader method next.

@Override
public Record next() {
    if (hasNext()) {
        final Record source = this.iterator.next();
        final Record target = new ArrayRecord(this.recordDefinition);
        for (final FieldDefinition attribute : this.recordDefinition.getFields()) {
            final String name = attribute.getName();
            final Object value = source.getValue(name);
            if (value != null) {
                final DataType dataType = this.recordDefinition.getFieldType(name);
                final Object convertedValue = dataType.toObject(value);
                target.setValue(name, convertedValue);
            }
        }
        return target;
    } else {
        throw new NoSuchElementException();
    }
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) 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)

Example 2 with ArrayRecord

use of com.revolsys.record.ArrayRecord 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)

Example 3 with ArrayRecord

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

the class RecordStore method insertRecord.

default Record insertRecord(final PathName pathName, final Object... values) {
    final RecordDefinition recordDefinition = getRecordDefinition(pathName);
    final Record record = new ArrayRecord(recordDefinition, values);
    insertRecord(record);
    return record;
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Example 4 with ArrayRecord

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

the class GeometryTest method writeTestFile.

public static void writeTestFile(final GeometryFactory geometryFactory, final String wkt) {
    final Geometry geometry = geometryFactory.geometry(wkt);
    final DataType geometryDataType = DataTypes.getDataType(geometry);
    String name = "/" + geometryDataType.getName();
    if (geometryFactory.hasZ()) {
        name += "Z";
    }
    final File file = new File("target/test-data/" + name + ".gdb");
    FileUtil.deleteDirectory(file);
    final PathName pathName = PathName.newPathName(name);
    RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(pathName);
    recordDefinition.addField("ID", DataTypes.INT, true);
    final FieldDefinition geometryField = recordDefinition.addField("Geometry", geometryDataType, true);
    geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
    recordDefinition.setIdFieldName("ID");
    final FileGdbRecordStore recordStore = FileGdbRecordStoreFactory.newRecordStore(file);
    recordStore.initialize();
    recordDefinition = (RecordDefinitionImpl) recordStore.getRecordDefinition(recordDefinition);
    final Record object = new ArrayRecord(recordDefinition);
    object.setIdentifier(Identifier.newIdentifier(1));
    object.setGeometryValue(geometry);
    recordStore.insertRecord(object);
    final Record object2 = recordStore.getRecord(pathName, Identifier.newIdentifier(1));
    if (!DataType.equal(object, object2)) {
        System.out.println("Not Equal");
        System.out.println(object);
        System.out.println(object2);
    }
    recordStore.close();
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) FileGdbRecordStore(com.revolsys.gis.esri.gdb.file.FileGdbRecordStore) ArrayRecord(com.revolsys.record.ArrayRecord) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) PathName(com.revolsys.io.PathName) File(java.io.File)

Example 5 with ArrayRecord

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

the class CopyProcess method copy.

protected Record copy(final Record object) {
    Record targetObject;
    if (this.recordDefinition == null) {
        targetObject = object;
    } else {
        targetObject = new ArrayRecord(this.recordDefinition);
        for (final String fieldName : this.recordDefinition.getFieldNames()) {
            copyAttribute(object, fieldName, targetObject, fieldName);
        }
        if (this.attributeMap != null) {
            for (final Entry<String, String> mapping : this.attributeMap.entrySet()) {
                final String sourceFieldName = mapping.getKey();
                final String targetFieldName = mapping.getValue();
                copyAttribute(object, sourceFieldName, targetObject, targetFieldName);
            }
        }
    }
    return targetObject;
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Aggregations

ArrayRecord (com.revolsys.record.ArrayRecord)19 Record (com.revolsys.record.Record)15 Geometry (com.revolsys.geometry.model.Geometry)5 FieldDefinition (com.revolsys.record.schema.FieldDefinition)5 RecordDefinition (com.revolsys.record.schema.RecordDefinition)5 DataType (com.revolsys.datatype.DataType)4 LineString (com.revolsys.geometry.model.LineString)2 RecordReader (com.revolsys.record.io.RecordReader)2 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)2 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 Bindings (javax.script.Bindings)2 MapEx (com.revolsys.collection.map.MapEx)1 Edge (com.revolsys.geometry.graph.Edge)1 Node (com.revolsys.geometry.graph.Node)1 RecordGraph (com.revolsys.geometry.graph.RecordGraph)1 ClockDirection (com.revolsys.geometry.model.ClockDirection)1 Point (com.revolsys.geometry.model.Point)1