Search in sources :

Example 1 with ObjectWithProperties

use of com.revolsys.properties.ObjectWithProperties 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);
}
Also used : RecordWriter(com.revolsys.record.io.RecordWriter) PathResource(com.revolsys.spring.resource.PathResource) ObjectWithProperties(com.revolsys.properties.ObjectWithProperties) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) File(java.io.File) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

ObjectWithProperties (com.revolsys.properties.ObjectWithProperties)1 RecordWriter (com.revolsys.record.io.RecordWriter)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 PathResource (com.revolsys.spring.resource.PathResource)1 Resource (com.revolsys.spring.resource.Resource)1 File (java.io.File)1