Search in sources :

Example 6 with Transaction

use of com.revolsys.transaction.Transaction 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 7 with Transaction

use of com.revolsys.transaction.Transaction 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 8 with Transaction

use of com.revolsys.transaction.Transaction 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)

Aggregations

Transaction (com.revolsys.transaction.Transaction)8 Identifier (com.revolsys.identifier.Identifier)5 Record (com.revolsys.record.Record)5 RecordDefinition (com.revolsys.record.schema.RecordDefinition)5 RecordReader (com.revolsys.record.io.RecordReader)4 RecordStore (com.revolsys.record.schema.RecordStore)4 BaseCloseable (com.revolsys.io.BaseCloseable)2 Geometry (com.revolsys.geometry.model.Geometry)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Polygonal (com.revolsys.geometry.model.Polygonal)1 PathName (com.revolsys.io.PathName)1 JdbcConnection (com.revolsys.jdbc.JdbcConnection)1 ArrayRecord (com.revolsys.record.ArrayRecord)1 RecordWriter (com.revolsys.record.io.RecordWriter)1 Condition (com.revolsys.record.query.Condition)1 Query (com.revolsys.record.query.Query)1 LabelCountMap (com.revolsys.util.count.LabelCountMap)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1