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