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