Search in sources :

Example 6 with RecordStoreSchemaElement

use of com.revolsys.record.schema.RecordStoreSchemaElement in project com.revolsys.open by revolsys.

the class OgrRecordStore method refreshSchemaElements.

@Override
protected synchronized Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
    final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
    if (!isClosed()) {
        final DataSource dataSource = getDataSource();
        if (dataSource != null) {
            for (int layerIndex = 0; layerIndex < dataSource.GetLayerCount(); layerIndex++) {
                final Layer layer = dataSource.GetLayer(layerIndex);
                if (layer != null) {
                    try {
                        final RecordDefinitionImpl recordDefinition = newLayerRecordDefinition(schema, layer);
                        final PathName typePath = recordDefinition.getPathName();
                        final String layerName = layer.GetName();
                        this.layerNameToPathMap.put(layerName.toUpperCase(), typePath);
                        this.pathToLayerNameMap.put(typePath, layerName);
                        elementsByPath.put(typePath, recordDefinition);
                    } finally {
                        layer.delete();
                    }
                }
            }
        }
    }
    return elementsByPath;
}
Also used : RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) PathName(com.revolsys.io.PathName) TreeMap(java.util.TreeMap) Layer(org.gdal.ogr.Layer) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement) DataSource(org.gdal.ogr.DataSource)

Example 7 with RecordStoreSchemaElement

use of com.revolsys.record.schema.RecordStoreSchemaElement in project com.revolsys.open by revolsys.

the class AbstractJdbcRecordStore method refreshSchemaElements.

@Override
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
    final JdbcRecordStoreSchema jdbcSchema = (JdbcRecordStoreSchema) schema;
    final JdbcRecordStoreSchema rootSchema = getRootSchema();
    final PathName schemaPath = jdbcSchema.getPathName();
    if (jdbcSchema == rootSchema) {
        if (this.usesSchema) {
            final Map<PathName, RecordStoreSchemaElement> schemas = new TreeMap<>();
            final Set<String> databaseSchemaNames = getDatabaseSchemaNames();
            for (final String dbSchemaName : databaseSchemaNames) {
                final PathName childSchemaPath = schemaPath.newChild(dbSchemaName.toUpperCase());
                RecordStoreSchema childSchema = schema.getSchema(childSchemaPath);
                if (childSchema == null) {
                    childSchema = new JdbcRecordStoreSchema(rootSchema, childSchemaPath, dbSchemaName);
                } else {
                    if (childSchema.isInitialized()) {
                        childSchema.refresh();
                    }
                }
                schemas.put(childSchemaPath, childSchema);
            }
            return schemas;
        } else {
            return refreshSchemaElementsDo(jdbcSchema, schemaPath);
        }
    } else {
        return refreshSchemaElementsDo(jdbcSchema, schemaPath);
    }
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) PathName(com.revolsys.io.PathName) TreeMap(java.util.TreeMap) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement)

Example 8 with RecordStoreSchemaElement

use of com.revolsys.record.schema.RecordStoreSchemaElement 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)

Aggregations

RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)8 PathName (com.revolsys.io.PathName)7 TreeMap (java.util.TreeMap)6 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)4 ArrayList (java.util.ArrayList)3 JdbcConnection (com.revolsys.jdbc.JdbcConnection)2 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)2 RecordStore (com.revolsys.record.schema.RecordStore)2 BaseTreeNode (com.revolsys.swing.tree.BaseTreeNode)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2 Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)1 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)1 ExtensionFilenameFilter (com.revolsys.io.filter.ExtensionFilenameFilter)1 JdbcRecordDefinition (com.revolsys.jdbc.io.JdbcRecordDefinition)1 SpatialReference (com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference)1 FieldDefinition (com.revolsys.record.schema.FieldDefinition)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 PathResource (com.revolsys.spring.resource.PathResource)1