Search in sources :

Example 1 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class DirectoryRecordStore method loadRecordDefinition.

protected RecordDefinition loadRecordDefinition(final RecordStoreSchema schema, final String schemaName, final Resource resource) {
    try (RecordReader recordReader = RecordReader.newRecordReader(resource)) {
        final String typePath = PathUtil.toPath(schemaName, resource.getBaseName());
        recordReader.setProperty("schema", schema);
        recordReader.setProperty("typePath", typePath);
        final RecordDefinition recordDefinition = recordReader.getRecordDefinition();
        if (recordDefinition != null) {
            this.resourcesByRecordDefinition.put(recordDefinition, resource);
            this.typePathByResource.put(resource, typePath);
        }
        return recordDefinition;
    }
}
Also used : RecordReader(com.revolsys.record.io.RecordReader) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 2 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class DirectoryRecordStore method newIterator.

@Override
public AbstractIterator<Record> newIterator(final Query query, final Map<String, Object> properties) {
    final PathName path = query.getTypePath();
    final RecordReader reader = getRecords(path);
    reader.setProperties(properties);
    return new RecordReaderQueryIterator(reader, query);
}
Also used : RecordReader(com.revolsys.record.io.RecordReader) PathName(com.revolsys.io.PathName)

Example 3 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class SimpleCodeTable method newCodeTable.

public static CodeTable newCodeTable(final String name, final Resource resource) {
    final SimpleCodeTable codeTable = new SimpleCodeTable(name);
    try (final RecordReader reader = RecordReader.newRecordReader(resource)) {
        for (final Record record : reader) {
            final Identifier id = record.getIdentifier(0);
            final List<Object> values = new ArrayList<>();
            final int fieldCount = record.getRecordDefinition().getFieldCount();
            for (int i = 1; i < fieldCount; i++) {
                final Object value = record.getValue(i);
                values.add(value);
            }
            codeTable.addValue(id, values);
        }
    }
    return codeTable;
}
Also used : Identifier(com.revolsys.identifier.Identifier) RecordReader(com.revolsys.record.io.RecordReader) ArrayList(java.util.ArrayList) Record(com.revolsys.record.Record)

Example 4 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class RecordStore method getRecordLocked.

default Record getRecordLocked(final PathName typePath, final LockMode lockMode, final Identifier id) {
    final Query query = newGetRecordQuery(typePath, id);
    if (query == null) {
        return null;
    } else {
        query.setLockMode(lockMode);
        final RecordReader records = getRecords(query);
        return records.getFirst();
    }
}
Also used : Query(com.revolsys.record.query.Query) ListRecordReader(com.revolsys.record.io.ListRecordReader) RecordReader(com.revolsys.record.io.RecordReader)

Example 5 with RecordReader

use of com.revolsys.record.io.RecordReader in project com.revolsys.open by revolsys.

the class Records method copyRecords.

static void copyRecords(final RecordStore sourceRecordStore, final String sourceTableName, final RecordStore targetRecordStore, final String targetTableName) {
    final Query query = new Query(sourceTableName);
    try (RecordReader reader = sourceRecordStore.getRecords(query);
        RecordWriter writer = targetRecordStore.newRecordWriter()) {
        final RecordDefinition recordDefinition = targetRecordStore.getRecordDefinition(targetTableName);
        for (final Record record : reader) {
            final Record newRecord = recordDefinition.newRecord();
            newRecord.setValuesAll(record);
            writer.write(newRecord);
        }
    }
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter) Query(com.revolsys.record.query.Query) RecordReader(com.revolsys.record.io.RecordReader) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordReader (com.revolsys.record.io.RecordReader)43 Record (com.revolsys.record.Record)34 ChannelWriter (com.revolsys.io.channels.ChannelWriter)19 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Identifier (com.revolsys.identifier.Identifier)5 ArrayRecord (com.revolsys.record.ArrayRecord)5 ListRecordReader (com.revolsys.record.io.ListRecordReader)5 Query (com.revolsys.record.query.Query)5 HashMap (java.util.HashMap)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 BaseCloseable (com.revolsys.io.BaseCloseable)4 Transaction (com.revolsys.transaction.Transaction)4 ArrayList (java.util.ArrayList)4 Maps (com.revolsys.collection.map.Maps)3 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)3 Geometry (com.revolsys.geometry.model.Geometry)3 RecordWriter (com.revolsys.record.io.RecordWriter)3 RecordStore (com.revolsys.record.schema.RecordStore)3 Resource (com.revolsys.spring.resource.Resource)3 LinkedHashMap (java.util.LinkedHashMap)3