Search in sources :

Example 1 with Table

use of com.revolsys.gis.esri.gdb.file.capi.swig.Table 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 Table

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

the class FileGdbRecordStore method deleteRecord.

@Override
public boolean deleteRecord(final Record record) {
    if (record == null) {
        return false;
    } else {
        final RecordDefinition recordDefinition = record.getRecordDefinition();
        final Table table = getTableWithWriteLock(recordDefinition);
        try {
            return deleteRecord(table, record);
        } finally {
            releaseTableAndWriteLock(recordDefinition);
        }
    }
}
Also used : 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) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 3 with Table

use of com.revolsys.gis.esri.gdb.file.capi.swig.Table 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 4 with Table

use of com.revolsys.gis.esri.gdb.file.capi.swig.Table 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)

Example 5 with Table

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

the class FileGdbWriter method getTable.

private Table getTable(final Record record) {
    final RecordDefinition recordDefinition = record.getRecordDefinition();
    final String catalogPath = this.recordStore.getCatalogPath(recordDefinition);
    Table table = this.tablesByCatalogPath.get(catalogPath);
    if (table == null) {
        table = this.recordStore.getTableWithWriteLock(recordDefinition);
        if (table != null) {
            this.tablesByCatalogPath.put(catalogPath, table);
        }
    }
    return table;
}
Also used : Table(com.revolsys.gis.esri.gdb.file.capi.swig.Table) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)14 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)10 CodeTable (com.revolsys.record.code.CodeTable)10 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)10 Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)6 RecordDefinition (com.revolsys.record.schema.RecordDefinition)5 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)4 ObjectException (com.revolsys.beans.ObjectException)2 ObjectPropertyException (com.revolsys.beans.ObjectPropertyException)2 PathName (com.revolsys.io.PathName)1 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)1 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)1 SpatialReference (com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference)1 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)1 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)1