Search in sources :

Example 21 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class OracleJdbcClobFieldDefinition method setPreparedStatementValue.

@Override
public int setPreparedStatementValue(final PreparedStatement statement, final int parameterIndex, final Object value) throws SQLException {
    if (value == null) {
        final int sqlType = getSqlType();
        statement.setNull(parameterIndex, sqlType);
    } else {
        if (value instanceof Clob) {
            final Clob clob = (Clob) value;
            statement.setClob(parameterIndex, clob);
        } else {
            Reader in;
            if (value instanceof Resource) {
                final Resource resource = (Resource) value;
                in = resource.newBufferedReader();
            } else if (value instanceof Clob) {
                final Clob clob = (Clob) value;
                in = clob.getCharacterStream();
            } else if (value instanceof String) {
                final String string = (String) value;
                in = new StringReader(string);
            } else if (value instanceof File) {
                final File file = (File) value;
                final PathResource resource = new PathResource(file);
                in = resource.newBufferedReader();
            } else {
                throw new IllegalArgumentException("Not valid for a clob column");
            }
            statement.setCharacterStream(parameterIndex, in);
        }
    }
    return parameterIndex + 1;
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) PathResource(com.revolsys.spring.resource.PathResource) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) Clob(java.sql.Clob) File(java.io.File)

Example 22 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class MavenRepository method setRoot.

public void setRoot(final Resource root) {
    if (root == null) {
        this.root = new PathResource(System.getProperty("user.home") + "/.m2/repository/");
    } else {
        try {
            String url = root.getURL().toExternalForm();
            url = url.replaceAll("([^(:/{2,3)])//+", "$1/");
            if (!url.endsWith("/")) {
                url += '/';
            }
            this.root = new DefaultResourceLoader().getResource(url);
        } catch (final Throwable e) {
            this.root = root;
        }
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) DefaultResourceLoader(com.revolsys.spring.resource.DefaultResourceLoader)

Example 23 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class DirectoryRecordStore method refreshSchemaElements.

@Override
protected Map<PathName, RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
    final Map<PathName, RecordStoreSchemaElement> elements = new TreeMap<>();
    final String schemaPath = schema.getPath();
    final PathName schemaPathName = schema.getPathName();
    final File subDirectory;
    if (schemaPath.equals("/")) {
        subDirectory = this.directory;
    } else {
        subDirectory = new File(this.directory, schemaPath);
    }
    final FileFilter filter = new ExtensionFilenameFilter(this.fileExtensions);
    final File[] files = subDirectory.listFiles();
    if (files != null) {
        for (final File file : files) {
            if (filter.accept(file)) {
                final PathResource resource = new PathResource(file);
                final RecordDefinition recordDefinition = loadRecordDefinition(schema, schemaPath, resource);
                if (recordDefinition != null) {
                    final PathName path = recordDefinition.getPathName();
                    elements.put(path, recordDefinition);
                }
            } else if (file.isDirectory()) {
                final String name = file.getName();
                final PathName childSchemaPath = schemaPathName.newChild(name);
                RecordStoreSchema childSchema = schema.getSchema(childSchemaPath);
                if (childSchema == null) {
                    childSchema = new RecordStoreSchema(schema, childSchemaPath);
                } else {
                    if (!childSchema.isInitialized()) {
                        childSchema.refresh();
                    }
                }
                elements.put(childSchemaPath, childSchema);
            }
        }
    }
    return elements;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) PathResource(com.revolsys.spring.resource.PathResource) ExtensionFilenameFilter(com.revolsys.io.filter.ExtensionFilenameFilter) PathName(com.revolsys.io.PathName) TreeMap(java.util.TreeMap) FileFilter(java.io.FileFilter) File(java.io.File) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 24 with PathResource

use of com.revolsys.spring.resource.PathResource 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

PathResource (com.revolsys.spring.resource.PathResource)24 File (java.io.File)15 Resource (com.revolsys.spring.resource.Resource)7 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 Geometry (com.revolsys.geometry.model.Geometry)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 FileNameExtensionFilter (com.revolsys.io.file.FileNameExtensionFilter)2 RecordWriter (com.revolsys.record.io.RecordWriter)2 Path (java.nio.file.Path)2 JFileChooser (javax.swing.JFileChooser)2 LasPointCloud (com.revolsys.elevation.cloud.las.LasPointCloud)1 TriangulatedIrregularNetwork (com.revolsys.elevation.tin.TriangulatedIrregularNetwork)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)1 PathName (com.revolsys.io.PathName)1 ExtensionFilenameFilter (com.revolsys.io.filter.ExtensionFilenameFilter)1 ObjectWithProperties (com.revolsys.properties.ObjectWithProperties)1 RecordWriterFactory (com.revolsys.record.io.RecordWriterFactory)1