use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.
the class LabelCountMap method writeCounts.
public void writeCounts(final Object target, final String labelTitle) {
final RecordDefinitionBuilder recordDefinitionBuilder = new RecordDefinitionBuilder("Counts");
recordDefinitionBuilder.addField(labelTitle, DataTypes.STRING, 50);
recordDefinitionBuilder.addField("Count", DataTypes.LONG, 10);
final RecordDefinition recordDefinition = recordDefinitionBuilder.getRecordDefinition();
try (RecordWriter recordWriter = RecordWriter.newRecordWriter(recordDefinition, target)) {
for (final String label : getLabels()) {
final Long count = getCount(label);
recordWriter.write(label, count);
}
}
}
use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.
the class ZipRecordWriter method setWriteNulls.
@Override
public void setWriteNulls(final boolean writeNulls) {
final RecordWriter writer = getWriter();
writer.setWriteNulls(writeNulls);
}
use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.
the class ZipRecordWriter method setIndent.
@Override
public void setIndent(final boolean indent) {
final RecordWriter writer = getWriter();
writer.setIndent(indent);
}
use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.
the class ZipRecordWriter method setWriteCodeValues.
@Override
public void setWriteCodeValues(final boolean writeCodeValues) {
final RecordWriter writer = getWriter();
writer.setWriteCodeValues(writeCodeValues);
}
use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.
the class CopyRecords method run.
@Override
public void run() {
try {
final Query query = this.sourceRecordStore.newQuery(this.typePath);
query.setOrderBy(this.orderBy);
try (final RecordReader reader = this.sourceRecordStore.getRecords(query);
final RecordWriter targetWriter = this.targetRecordStore.newRecordWriter()) {
final RecordDefinition targetRecordDefinition = this.targetRecordStore.getRecordDefinition(this.typePath);
if (targetRecordDefinition == null) {
Logs.error(this, "Cannot find target table: " + this.typePath);
} else {
if (this.hasSequence) {
final String idFieldName = targetRecordDefinition.getIdFieldName();
Identifier maxId = this.targetRecordStore.newPrimaryIdentifier(this.typePath);
for (final Record sourceRecord : reader) {
final Record targetRecord = this.targetRecordStore.newRecord(this.typePath, sourceRecord);
final Identifier sourceId = sourceRecord.getIdentifier(idFieldName);
while (CompareUtil.compare(maxId, sourceId) < 0) {
maxId = this.targetRecordStore.newPrimaryIdentifier(this.typePath);
}
targetWriter.write(targetRecord);
}
} else {
for (final Record sourceRecord : reader) {
final Record targetRecord = this.targetRecordStore.newRecord(this.typePath, sourceRecord);
targetWriter.write(targetRecord);
}
}
}
}
} catch (final Throwable e) {
throw new RuntimeException("Unable to copy records for " + this.typePath, e);
}
}
Aggregations