Search in sources :

Example 1 with Geodatabase

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

the class FileGdbRecordStore method releaseTableAndWriteLock.

protected void releaseTableAndWriteLock(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.tableWriteLockCountsByCatalogPath, catalogPath);
                    if (count == 0) {
                        try {
                            table.setLoadOnlyMode(false);
                            table.freeWriteLock();
                        } catch (final Exception e) {
                            Logs.error(this, "Unable to free write lock for table: " + catalogPath, e);
                        }
                    }
                }
                releaseTable(catalogPath);
            } 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)

Example 2 with Geodatabase

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

the class FileGdbRecordStore method newSchema.

private RecordStoreSchema newSchema(final PathName schemaPath, final SpatialReference spatialReference) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase == null) {
                return null;
            } else {
                try {
                    String parentCatalogPath = "\\";
                    RecordStoreSchema schema = getRootSchema();
                    for (final PathName childSchemaPath : schemaPath.getPaths()) {
                        if (childSchemaPath.length() > 1) {
                            RecordStoreSchema childSchema = schema.getSchema(childSchemaPath);
                            final String childCatalogPath = toCatalogPath(childSchemaPath);
                            if (!hasChildDataset(getGeodatabase(), parentCatalogPath, "Feature Dataset", childCatalogPath)) {
                                if (spatialReference != null) {
                                    final DEFeatureDataset dataset = EsriXmlRecordDefinitionUtil.newDEFeatureDataset(childCatalogPath, spatialReference);
                                    final String datasetDefinition = EsriGdbXmlSerializer.toString(dataset);
                                    try {
                                        geodatabase.createFeatureDataset(datasetDefinition);
                                    } catch (final Throwable t) {
                                        Logs.debug(this, datasetDefinition);
                                        throw new RuntimeException("Unable to create feature dataset " + childCatalogPath, t);
                                    }
                                }
                            }
                            if (childSchema == null) {
                                childSchema = newFeatureDatasetSchema(schema, childSchemaPath);
                                schema.addElement(childSchema);
                            }
                            schema = childSchema;
                            parentCatalogPath = childCatalogPath;
                        }
                    }
                    return schema;
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) DEFeatureDataset(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureDataset) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) PathName(com.revolsys.io.PathName)

Example 3 with Geodatabase

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

the class FileGdbRecordStore method refreshSchemaRecordDefinitions.

private void refreshSchemaRecordDefinitions(final Map<PathName, RecordStoreSchemaElement> elementsByPath, final PathName schemaPath, final String catalogPath, final String datasetType) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase != null) {
                try {
                    final boolean pathExists = isPathExists(geodatabase, catalogPath);
                    if (pathExists) {
                        final VectorOfWString childFeatureClasses = getChildDatasets(geodatabase, catalogPath, datasetType);
                        if (childFeatureClasses != null) {
                            for (int i = 0; i < childFeatureClasses.size(); i++) {
                                final String childCatalogPath = childFeatureClasses.get(i);
                                final String tableDefinition = geodatabase.getTableDefinition(childCatalogPath);
                                final RecordDefinition recordDefinition = getRecordDefinition(schemaPath, childCatalogPath, tableDefinition);
                                initRecordDefinition(recordDefinition);
                                final PathName childPath = recordDefinition.getPathName();
                                elementsByPath.put(childPath, recordDefinition);
                            }
                        }
                    }
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
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) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 4 with Geodatabase

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

the class FileGdbRecordStore method closeTable.

public boolean closeTable(final PathName typePath) {
    synchronized (this.apiSync) {
        final String path = getCatalogPath(typePath);
        int count = Maps.getInteger(this.tableReferenceCountsByCatalogPath, path, 0);
        count--;
        if (count <= 0) {
            this.tableReferenceCountsByCatalogPath.remove(path);
            final Table table = this.tableByCatalogPath.remove(path);
            synchronized (API_SYNC) {
                if (table != null) {
                    try {
                        final Geodatabase geodatabase = getGeodatabase();
                        if (geodatabase != null) {
                            try {
                                geodatabase.closeTable(table);
                            } finally {
                                releaseGeodatabase();
                            }
                        }
                    } catch (final Throwable e) {
                        Logs.error(this, "Cannot close Table " + typePath, e);
                    } finally {
                        try {
                            table.delete();
                        } catch (final Throwable t) {
                        }
                    }
                }
            }
            return true;
        } else {
            this.tableReferenceCountsByCatalogPath.put(path, count);
            return false;
        }
    }
}
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)

Example 5 with Geodatabase

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

the class FileGdbRecordStore method newTableRecordDefinition.

private RecordDefinitionImpl newTableRecordDefinition(final DETable deTable) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase == null) {
                return null;
            } else {
                try {
                    String schemaCatalogPath = deTable.getParentCatalogPath();
                    SpatialReference spatialReference;
                    if (deTable instanceof DEFeatureClass) {
                        final DEFeatureClass featureClass = (DEFeatureClass) deTable;
                        spatialReference = featureClass.getSpatialReference();
                    } else {
                        spatialReference = null;
                    }
                    PathName schemaPath = toPath(schemaCatalogPath);
                    final RecordStoreSchema schema = newSchema(schemaPath, spatialReference);
                    if (schemaPath.equals(this.defaultSchemaPath)) {
                        if (!(deTable instanceof DEFeatureClass)) {
                            schemaCatalogPath = "\\";
                            deTable.setCatalogPath("\\" + deTable.getName());
                        }
                    } else if (schemaPath.equals("")) {
                        schemaPath = this.defaultSchemaPath;
                    }
                    for (final Field field : deTable.getFields()) {
                        final String fieldName = field.getName();
                        final CodeTable codeTable = getCodeTableByFieldName(fieldName);
                        if (codeTable instanceof FileGdbDomainCodeTable) {
                            final FileGdbDomainCodeTable domainCodeTable = (FileGdbDomainCodeTable) codeTable;
                            field.setDomain(domainCodeTable.getDomain());
                        }
                    }
                    final String tableDefinition = EsriGdbXmlSerializer.toString(deTable);
                    try {
                        final Table table = geodatabase.createTable(tableDefinition, schemaCatalogPath);
                        geodatabase.closeTable(table);
                        table.delete();
                        final RecordDefinitionImpl recordDefinition = getRecordDefinition(PathName.newPathName(schemaPath), schemaCatalogPath, tableDefinition);
                        initRecordDefinition(recordDefinition);
                        schema.addElement(recordDefinition);
                        return recordDefinition;
                    } catch (final Throwable t) {
                        throw new RuntimeException("Unable to create table " + deTable.getCatalogPath(), t);
                    }
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) 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) DEFeatureClass(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) Field(com.revolsys.record.io.format.esri.gdb.xml.model.Field) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) PathName(com.revolsys.io.PathName)

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