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