Search in sources :

Example 1 with RecordWriter

use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.

the class AbstractJdbcRecordStore method writeAll.

protected int writeAll(final Iterable<? extends Record> records, final RecordState state) {
    int count = 0;
    try (Transaction transaction = newTransaction(Propagation.REQUIRED)) {
        // rolled back.
        try (final RecordWriter writer = newRecordWriter(true)) {
            for (final Record record : records) {
                write(writer, record, state);
                count++;
            }
        } catch (final RuntimeException e) {
            transaction.setRollbackOnly();
            throw e;
        } catch (final Error e) {
            transaction.setRollbackOnly();
            throw e;
        }
    }
    return count;
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter) Transaction(com.revolsys.transaction.Transaction) ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record)

Example 2 with RecordWriter

use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.

the class DirectoryRecordStore method closeWriters.

public void closeWriters(final String typeName) {
    final RecordWriter writer = this.writers.remove(typeName);
    FileUtil.closeSilent(writer);
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter)

Example 3 with RecordWriter

use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.

the class DirectoryRecordStore method close.

@Override
public void close() {
    this.directory = null;
    if (this.writers != null) {
        for (final RecordWriter writer : this.writers.values()) {
            if (writer != null) {
                writer.close();
            }
        }
        this.writers.clear();
    }
    super.close();
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter)

Example 4 with RecordWriter

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

Example 5 with RecordWriter

use of com.revolsys.record.io.RecordWriter in project com.revolsys.open by revolsys.

the class ShapefileZip method newRecordWriter.

@Override
public RecordWriter newRecordWriter(final String baseName, final RecordDefinition recordDefinition, final OutputStream outputStream, final Charset charset) {
    File directory;
    try {
        directory = FileUtil.newTempDirectory(baseName, "zipDir");
    } catch (final Throwable e) {
        throw new RuntimeException("Unable to create temporary directory", e);
    }
    final Resource tempResource = new PathResource(new File(directory, baseName + ".shp"));
    final RecordWriter shapeWriter = new ShapefileRecordWriter(recordDefinition, tempResource);
    return new ZipRecordWriter(directory, shapeWriter, outputStream);
}
Also used : ZipRecordWriter(com.revolsys.record.io.format.zip.ZipRecordWriter) RecordWriter(com.revolsys.record.io.RecordWriter) ZipRecordWriter(com.revolsys.record.io.format.zip.ZipRecordWriter) PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) File(java.io.File)

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