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