Search in sources :

Example 6 with RecordWriter

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);
        }
    }
}
Also used : RecordDefinitionBuilder(com.revolsys.record.schema.RecordDefinitionBuilder) RecordWriter(com.revolsys.record.io.RecordWriter) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 7 with RecordWriter

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);
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter)

Example 8 with RecordWriter

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);
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter)

Example 9 with RecordWriter

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);
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter)

Example 10 with RecordWriter

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);
    }
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter) Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordWriter (com.revolsys.record.io.RecordWriter)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)6 RecordReader (com.revolsys.record.io.RecordReader)3 Query (com.revolsys.record.query.Query)3 Record (com.revolsys.record.Record)2 RecordDefinitionBuilder (com.revolsys.record.schema.RecordDefinitionBuilder)2 PathResource (com.revolsys.spring.resource.PathResource)2 Resource (com.revolsys.spring.resource.Resource)2 File (java.io.File)2 Identifier (com.revolsys.identifier.Identifier)1 ObjectWithProperties (com.revolsys.properties.ObjectWithProperties)1 ArrayRecord (com.revolsys.record.ArrayRecord)1 ZipRecordWriter (com.revolsys.record.io.format.zip.ZipRecordWriter)1 Transaction (com.revolsys.transaction.Transaction)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1