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