Search in sources :

Example 36 with RecordReader

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

the class RecordStoreLayer method forEachRecordsPersisted.

@SuppressWarnings("unchecked")
public <R extends LayerRecord> void forEachRecordsPersisted(final Query query, final Consumer<? super R> consumer) {
    if (query != null && isExists()) {
        final RecordStore recordStore = getRecordStore();
        if (recordStore != null) {
            try (final BaseCloseable booleanValueCloseable = eventsDisabled();
                Transaction transaction = recordStore.newTransaction(Propagation.REQUIRES_NEW);
                final RecordReader reader = newRecordStoreRecordReader(query)) {
                final LabelCountMap labelCountMap = query.getProperty("statistics");
                for (final LayerRecord record : reader.<LayerRecord>i()) {
                    final Identifier identifier = getId(record);
                    R proxyRecord = null;
                    if (identifier == null) {
                        proxyRecord = (R) newProxyLayerRecordNoId(record);
                    } else {
                        synchronized (getSync()) {
                            final LayerRecord cachedRecord = getCachedRecord(identifier, record, true);
                            if (!cachedRecord.isDeleted()) {
                                proxyRecord = newProxyLayerRecord(identifier);
                            }
                        }
                    }
                    if (proxyRecord != null) {
                        consumer.accept(proxyRecord);
                        if (labelCountMap != null) {
                            labelCountMap.addCount(record);
                        }
                    }
                }
            }
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Identifier(com.revolsys.identifier.Identifier) Transaction(com.revolsys.transaction.Transaction) LabelCountMap(com.revolsys.util.count.LabelCountMap) RecordStore(com.revolsys.record.schema.RecordStore) RecordReader(com.revolsys.record.io.RecordReader)

Example 37 with RecordReader

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

the class RecordStoreLayer method getCachedRecord.

@SuppressWarnings("unchecked")
@Override
protected <R extends LayerRecord> R getCachedRecord(final Identifier identifier) {
    final RecordDefinition recordDefinition = getInternalRecordDefinition();
    synchronized (getSync()) {
        LayerRecord record = this.recordsByIdentifier.get(identifier);
        if (record == null) {
            final List<String> idFieldNames = recordDefinition.getIdFieldNames();
            if (idFieldNames.isEmpty()) {
                return null;
            } else {
                final Condition where = getCachedRecordQuery(idFieldNames, identifier);
                final Query query = new Query(recordDefinition, where);
                final RecordStore recordStore = this.recordStore;
                if (recordStore != null) {
                    try (Transaction transaction = recordStore.newTransaction(Propagation.REQUIRED);
                        RecordReader reader = newRecordStoreRecordReader(query)) {
                        record = reader.getFirst();
                        if (record != null) {
                            addCachedRecord(identifier, record);
                        }
                    }
                }
            }
        }
        return (R) record;
    }
}
Also used : Condition(com.revolsys.record.query.Condition) Query(com.revolsys.record.query.Query) Transaction(com.revolsys.transaction.Transaction) RecordStore(com.revolsys.record.schema.RecordStore) RecordReader(com.revolsys.record.io.RecordReader) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 38 with RecordReader

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

the class RecordStoreLayer method updateCachedRecords.

private void updateCachedRecords(final RecordStore recordStore, final Query query) {
    try (Transaction transaction = recordStore.newTransaction(Propagation.REQUIRES_NEW);
        RecordReader reader = recordStore.getRecords(query)) {
        for (final Record record : reader) {
            final Identifier identifier = record.getIdentifier();
            final RecordStoreLayerRecord cachedRecord = this.recordsByIdentifier.get(identifier);
            if (cachedRecord != null) {
                cachedRecord.refreshFromRecordStore(record);
            }
        }
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) Transaction(com.revolsys.transaction.Transaction) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record)

Example 39 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 BiConsumer<Record, Record> recordEditor) {
    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);
            recordEditor.accept(record, newRecord);
            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)

Example 40 with RecordReader

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

the class DirectoryRecordStore method getRecords.

@Override
public RecordReader getRecords(final PathName path) {
    final RecordDefinition recordDefinition = getRecordDefinition(path);
    final Resource resource = getResource(path.toString(), recordDefinition);
    final RecordReader reader = RecordReader.newRecordReader(resource);
    if (reader == null) {
        throw new IllegalArgumentException("Cannot find reader for: " + path);
    } else {
        final String typePath = this.typePathByResource.get(resource);
        reader.setProperty("schema", recordDefinition.getSchema());
        reader.setProperty("typePath", typePath);
        return reader;
    }
}
Also used : RecordReader(com.revolsys.record.io.RecordReader) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) 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