Search in sources :

Example 6 with ArrayRecord

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

the class Json method toString.

public static String toString(final RecordDefinition recordDefinition, final List<? extends Map<String, Object>> list) {
    final StringWriter writer = new StringWriter();
    final JsonRecordWriter recordWriter = new JsonRecordWriter(recordDefinition, writer);
    for (final Map<String, Object> map : list) {
        final Record object = new ArrayRecord(recordDefinition);
        object.setValues(map);
        recordWriter.write(object);
    }
    recordWriter.close();
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Example 7 with ArrayRecord

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

the class Json method toString.

public static String toString(final RecordDefinition recordDefinition, final Map<String, ? extends Object> parameters) {
    final Record object = new ArrayRecord(recordDefinition);
    object.setValues(parameters);
    return toString(object);
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Example 8 with ArrayRecord

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

the class ShapefileRecordStore method newRecord.

@Override
public Record newRecord(final RecordDefinition recordDefinition) {
    final String typePath = recordDefinition.getPath();
    final RecordDefinition savedRecordDefinition = getRecordDefinition(typePath);
    if (savedRecordDefinition == null) {
        return new ArrayRecord(recordDefinition);
    } else {
        return new ArrayRecord(savedRecordDefinition);
    }
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 9 with ArrayRecord

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

the class RecordWriterPerformanceTest method newRecord.

private static Record newRecord(final RecordDefinition recordDefinition, final int index) {
    final Record record = new ArrayRecord(recordDefinition);
    record.setValue("boolean", index % 2 == 0);
    record.setValue("byte", index % 256 + Byte.MIN_VALUE);
    record.setValue("short", index % 65536 + Short.MIN_VALUE);
    record.setValue("int", index);
    record.setValue("long", index);
    record.setValue("float", index + index % 1000 / 1000.0);
    record.setValue("double", index + index % 1000 / 1000.0);
    record.setValue("string", "String with some special characters " + index + "\\/\"'\t\n\r");
    final Calendar calendar = new GregorianCalendar();
    calendar.set(2016, 11, index % 28 + 1, 0, 0);
    final Date date = new Date(calendar.getTimeInMillis());
    record.setValue("date", date);
    calendar.set(Calendar.MINUTE, index % 60);
    final java.util.Date dateTime = new java.util.Date(calendar.getTimeInMillis());
    record.setValue("dateTime", dateTime);
    calendar.set(Calendar.MILLISECOND, index % 1000);
    final Timestamp timestamp = new Timestamp(calendar.getTimeInMillis());
    record.setValue("timestamp", timestamp);
    record.setValue("geometry", new PointDoubleXY(index, index * 2));
    return record;
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Timestamp(java.sql.Timestamp) Date(java.sql.Date)

Example 10 with ArrayRecord

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

the class RecordIoTestSuite method doRecordReadTest.

private static void doRecordReadTest(final PathResource resource, final ArrayRecord record) {
    if (RecordReader.isReadable(resource)) {
        final RecordReaderFactory recordReaderFactory = IoFactory.factory(RecordReaderFactory.class, resource);
        try (RecordReader recordReader = RecordReader.newRecordReader(resource)) {
            final ClockDirection polygonRingDirection = recordReader.getPolygonRingDirection();
            final List<Record> records = recordReader.toList();
            Assert.assertEquals("Record Count", 1, records.size());
            final Record actualRecord = records.get(0);
            if (recordReaderFactory.isCustomFieldsSupported() && !(recordReader instanceof GeometryRecordReader)) {
                for (final String fieldName : record.getRecordDefinition().getFieldNames()) {
                    if (!fieldName.equals("GEOMETRY")) {
                        final Object expectedValue = record.getValue(fieldName);
                        final Object actualValue = actualRecord.getValue(fieldName);
                        final boolean equals = DataType.equal(expectedValue, actualValue);
                        com.revolsys.geometry.util.Assert.equals(fieldName, equals, expectedValue, actualValue);
                    }
                }
            }
            if (recordReaderFactory.isGeometrySupported()) {
                final Geometry expectedGeometry = record.getGeometry();
                final Geometry actualGeometry = actualRecord.getGeometry();
                assertGeometry(polygonRingDirection, expectedGeometry, actualGeometry);
            }
        }
    } else {
        Logs.debug(RecordIoTestSuite.class, "Reading geometry not supported for: " + resource.getFileNameExtension());
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) RecordReader(com.revolsys.record.io.RecordReader) GeometryRecordReader(com.revolsys.record.io.GeometryRecordReader) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) GeometryRecordReader(com.revolsys.record.io.GeometryRecordReader) RecordReaderFactory(com.revolsys.record.io.RecordReaderFactory) ClockDirection(com.revolsys.geometry.model.ClockDirection)

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