Search in sources :

Example 6 with Geodatabase

use of com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method closeTables.

private void closeTables() {
    synchronized (this.apiSync) {
        if (!this.tableByCatalogPath.isEmpty()) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase != null) {
                try {
                    for (final Table table : this.tableByCatalogPath.values()) {
                        try {
                            table.setLoadOnlyMode(false);
                            table.freeWriteLock();
                            geodatabase.closeTable(table);
                        } catch (final Throwable e) {
                        } finally {
                            try {
                                table.delete();
                            } catch (final Throwable t) {
                            }
                        }
                    }
                    this.tableByCatalogPath.clear();
                    this.tableReferenceCountsByCatalogPath.clear();
                    this.tableWriteLockCountsByCatalogPath.clear();
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) CodeTable(com.revolsys.record.code.CodeTable) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable) Table(com.revolsys.gis.esri.gdb.file.capi.swig.Table) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)

Example 7 with Geodatabase

use of com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method initializeDo.

@Override
public void initializeDo() {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            Geodatabase geodatabase = null;
            try {
                super.initialize();
                final File file = new File(this.fileName);
                if (file.exists()) {
                    if (file.isDirectory()) {
                        if (!new File(this.fileName, "gdb").exists()) {
                            throw new IllegalArgumentException(FileUtil.getCanonicalPath(file) + " is not a valid ESRI File Geodatabase");
                        }
                        geodatabase = getSingleThreadResult(() -> {
                            return EsriFileGdb.openGeodatabase(this.fileName);
                        });
                    } else {
                        throw new IllegalArgumentException(FileUtil.getCanonicalPath(file) + " ESRI File Geodatabase must be a directory");
                    }
                } else if (this.createMissingRecordStore) {
                    geodatabase = newGeodatabase();
                } else {
                    throw new IllegalArgumentException("ESRI file geodatabase not found " + this.fileName);
                }
                if (geodatabase == null) {
                    throw new IllegalArgumentException("Unable to open ESRI file geodatabase not found " + this.fileName);
                }
                final VectorOfWString domainNames = geodatabase.getDomains();
                for (int i = 0; i < domainNames.size(); i++) {
                    final String domainName = domainNames.get(i);
                    loadDomain(geodatabase, domainName);
                }
                this.exists = true;
            } catch (final Throwable e) {
                try {
                    closeDo();
                } finally {
                    Exceptions.throwUncheckedException(e);
                }
            } finally {
                if (geodatabase != null) {
                    closeGeodatabase(geodatabase);
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) File(java.io.File)

Example 8 with Geodatabase

use of com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method refreshSchemaElements.

@Override
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase != null) {
                try {
                    final PathName schemaPath = schema.getPathName();
                    final String schemaCatalogPath = getCatalogPath(schema);
                    final VectorOfWString childDatasets = getChildDatasets(geodatabase, schemaCatalogPath, "Feature Dataset");
                    if (childDatasets != null) {
                        for (int i = 0; i < childDatasets.size(); i++) {
                            final String childCatalogPath = childDatasets.get(i);
                            final PathName childPath = toPath(childCatalogPath);
                            RecordStoreSchema childSchema = schema.getSchema(childPath);
                            if (childSchema == null) {
                                childSchema = newFeatureDatasetSchema(schema, childPath);
                            } else {
                                if (childSchema.isInitialized()) {
                                    childSchema.refresh();
                                }
                            }
                            elementsByPath.put(childPath, childSchema);
                        }
                    }
                    if (schemaPath.isParentOf(this.defaultSchemaPath) && !elementsByPath.containsKey(this.defaultSchemaPath)) {
                        final SpatialReference spatialReference = getSpatialReference(getGeometryFactory());
                        final RecordStoreSchema childSchema = newSchema(this.defaultSchemaPath, spatialReference);
                        elementsByPath.put(this.defaultSchemaPath, childSchema);
                    }
                    if (schema.equalPath(this.defaultSchemaPath)) {
                        refreshSchemaRecordDefinitions(elementsByPath, schemaPath, "\\", "Feature Class");
                        refreshSchemaRecordDefinitions(elementsByPath, schemaPath, "\\", "Table");
                    }
                    refreshSchemaRecordDefinitions(elementsByPath, schemaPath, schemaCatalogPath, "Feature Class");
                    refreshSchemaRecordDefinitions(elementsByPath, schemaPath, schemaCatalogPath, "Table");
                } finally {
                    releaseGeodatabase();
                }
            }
            return elementsByPath;
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) PathName(com.revolsys.io.PathName) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) TreeMap(java.util.TreeMap) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement)

Example 9 with Geodatabase

use of com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method getTable.

protected Table getTable(final RecordDefinition recordDefinition) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final RecordDefinition fgdbRecordDefinition = getRecordDefinition(recordDefinition);
            if (!isExists() || fgdbRecordDefinition == null) {
                return null;
            } else {
                try {
                    final Geodatabase geodatabase = getGeodatabase();
                    if (geodatabase == null) {
                        return null;
                    } else {
                        final String catalogPath = getCatalogPath(fgdbRecordDefinition);
                        try {
                            Table table = this.tableByCatalogPath.get(catalogPath);
                            if (table == null) {
                                table = this.geodatabase.openTable(catalogPath);
                                if (table != null) {
                                    if (this.tableByCatalogPath.isEmpty()) {
                                        this.geodatabaseReferenceCount++;
                                    }
                                    Maps.addCount(this.tableReferenceCountsByCatalogPath, catalogPath);
                                    this.tableByCatalogPath.put(catalogPath, table);
                                }
                            } else {
                                Maps.addCount(this.tableReferenceCountsByCatalogPath, catalogPath);
                            }
                            return table;
                        } catch (final RuntimeException e) {
                            throw new RuntimeException("Unable to open table " + catalogPath, e);
                        }
                    }
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) CodeTable(com.revolsys.record.code.CodeTable) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable) Table(com.revolsys.gis.esri.gdb.file.capi.swig.Table) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 10 with Geodatabase

use of com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method releaseTable.

protected void releaseTable(final String catalogPath) {
    synchronized (this.apiSync) {
        final Geodatabase geodatabase = getGeodatabase();
        if (geodatabase != null) {
            try {
                final Table table = this.tableByCatalogPath.get(catalogPath);
                if (table != null) {
                    final Integer count = Maps.decrementCount(this.tableReferenceCountsByCatalogPath, catalogPath);
                    if (count == 0) {
                        try {
                            this.tableByCatalogPath.remove(catalogPath);
                            this.tableWriteLockCountsByCatalogPath.remove(catalogPath);
                            geodatabase.closeTable(table);
                        } catch (final Exception e) {
                            Logs.error(this, "Unable to close table: " + catalogPath, e);
                        } finally {
                            if (this.tableByCatalogPath.isEmpty()) {
                                this.geodatabaseReferenceCount--;
                            }
                            table.delete();
                        }
                    }
                }
            } finally {
                releaseGeodatabase();
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) CodeTable(com.revolsys.record.code.CodeTable) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable) Table(com.revolsys.gis.esri.gdb.file.capi.swig.Table) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) ObjectException(com.revolsys.beans.ObjectException) ObjectPropertyException(com.revolsys.beans.ObjectPropertyException)

Aggregations

Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)11 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)6 CodeTable (com.revolsys.record.code.CodeTable)6 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)6 PathName (com.revolsys.io.PathName)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)3 ObjectException (com.revolsys.beans.ObjectException)2 ObjectPropertyException (com.revolsys.beans.ObjectPropertyException)2 SpatialReference (com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 Geometry (com.revolsys.geometry.model.Geometry)1 Row (com.revolsys.gis.esri.gdb.file.capi.swig.Row)1 GeometryFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition)1 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)1 DEFeatureDataset (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureDataset)1 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)1 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)1