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);
}
}
}
}
}
}
}
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;
}
}
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);
}
}
}
}
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);
}
}
}
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;
}
}
Aggregations