use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.
the class DirectoryRecordStore method getRecordDefinition.
@Override
public RecordDefinition getRecordDefinition(final RecordDefinition recordDefinition) {
final RecordDefinition storeRecordDefinition = super.getRecordDefinition(recordDefinition);
if (storeRecordDefinition == null && this.createMissingTables) {
final PathName typePath = recordDefinition.getPathName();
final PathName schemaPath = typePath.getParent();
RecordStoreSchema schema = getSchema(schemaPath);
if (schema == null && this.createMissingTables) {
final RecordStoreSchema rootSchema = getRootSchema();
schema = rootSchema.newSchema(schemaPath);
}
final File schemaDirectory = new File(this.directory, schemaPath.getPath());
if (!schemaDirectory.exists()) {
schemaDirectory.mkdirs();
}
final RecordDefinitionImpl newRecordDefinition = new RecordDefinitionImpl(schema, typePath);
for (final FieldDefinition field : recordDefinition.getFields()) {
final FieldDefinition newField = new FieldDefinition(field);
newRecordDefinition.addField(newField);
}
schema.addElement(newRecordDefinition);
return newRecordDefinition;
}
return storeRecordDefinition;
}
use of com.revolsys.record.schema.RecordStoreSchema 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;
}
Aggregations