use of com.revolsys.record.io.RecordWriter 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.RecordWriter in project com.revolsys.open by revolsys.
the class DirectoryRecordStore method insertRecord.
@Override
public synchronized void insertRecord(final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final String typePath = recordDefinition.getPath();
RecordWriter writer = this.writers.get(typePath);
if (writer == null) {
final String schemaName = PathUtil.getPath(typePath);
final File subDirectory = FileUtil.getDirectory(getDirectory(), schemaName);
final String fileExtension = getFileExtension();
final File file = new File(subDirectory, recordDefinition.getName() + "." + fileExtension);
final Resource resource = new PathResource(file);
writer = RecordWriter.newRecordWriter(recordDefinition, resource);
if (writer == null) {
throw new RuntimeException("Cannot create writer for: " + typePath);
} else if (writer instanceof ObjectWithProperties) {
final ObjectWithProperties properties = writer;
properties.setProperties(getProperties());
}
this.writers.put(typePath, writer);
}
writer.write(record);
addStatistic("Insert", record);
}
use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.
the class CategoryLabelCountMap method writeCounts.
public void writeCounts(final Object target, final String labelTitle, final Iterable<String> categoryNames) {
final RecordDefinitionBuilder recordDefinitionBuilder = new RecordDefinitionBuilder("Counts");
recordDefinitionBuilder.addField(labelTitle, DataTypes.STRING, 50);
final Set<String> allLabels = new TreeSet<>();
final List<String> matchedCategoryNames = new ArrayList<>();
for (final String categoryName : categoryNames) {
final LabelCountMap labelCountMap = this.labelCountMapByCategory.get(categoryName);
if (labelCountMap != null) {
matchedCategoryNames.add(categoryName);
recordDefinitionBuilder.addField(categoryName, DataTypes.LONG, 10);
final Set<String> labels = labelCountMap.getLabels();
allLabels.addAll(labels);
}
}
final RecordDefinition recordDefinition = recordDefinitionBuilder.getRecordDefinition();
try (RecordWriter recordWriter = RecordWriter.newRecordWriter(recordDefinition, target)) {
final List<Object> row = new ArrayList<>(matchedCategoryNames.size() + 1);
for (final String label : allLabels) {
row.clear();
row.add(label);
for (final String categoryName : matchedCategoryNames) {
final Long count = getCount(categoryName, label);
row.add(count);
}
recordWriter.write(row);
}
}
}
Aggregations