Search in sources :

Example 96 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition 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 97 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method insertRecord.

@Override
public void insertRecord(final Record record) {
    if (record == null) {
    } else {
        final RecordDefinition recordDefinition = record.getRecordDefinition();
        final Table table = getTableWithWriteLock(recordDefinition);
        try {
            insertRecord(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 98 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method getRecord.

@Override
public Record getRecord(final PathName typePath, final Object... id) {
    synchronized (this.apiSync) {
        final RecordDefinition recordDefinition = getRecordDefinition(typePath);
        if (recordDefinition == null) {
            throw new IllegalArgumentException("Unknown type " + typePath);
        } else {
            final String catalogPath = getCatalogPath(typePath);
            final FileGdbQueryIterator iterator = new FileGdbQueryIterator(this, catalogPath, recordDefinition.getIdFieldName() + " = " + id[0]);
            try {
                if (iterator.hasNext()) {
                    return iterator.next();
                } else {
                    return null;
                }
            } finally {
                iterator.close();
            }
        }
    }
}
Also used : VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 99 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method getRecordDefinition.

@SuppressWarnings("unchecked")
@Override
public <RD extends RecordDefinition> RD getRecordDefinition(final RecordDefinition sourceRecordDefinition) {
    synchronized (this.apiSync) {
        if (getGeometryFactory() == null) {
            setGeometryFactory(sourceRecordDefinition.getGeometryFactory());
        }
        final String typePath = sourceRecordDefinition.getPath();
        RecordDefinition recordDefinition = getRecordDefinition(typePath);
        if (recordDefinition == null) {
            if (!sourceRecordDefinition.hasGeometryField()) {
                recordDefinition = getRecordDefinition(PathUtil.getName(typePath));
            }
            if (this.createMissingTables && recordDefinition == null) {
                recordDefinition = newTableRecordDefinition(sourceRecordDefinition);
            }
        }
        return (RD) recordDefinition;
    }
}
Also used : VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 100 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method getRecordCount.

@Override
public int getRecordCount(final Query query) {
    if (query == null) {
        return 0;
    } else {
        synchronized (this.apiSync) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase == null) {
                return 0;
            } else {
                try {
                    String typePath = query.getTypeName();
                    RecordDefinition recordDefinition = query.getRecordDefinition();
                    if (recordDefinition == null) {
                        typePath = query.getTypeName();
                        recordDefinition = getRecordDefinition(typePath);
                        if (recordDefinition == null) {
                            return 0;
                        }
                    } else {
                        typePath = recordDefinition.getPath();
                    }
                    final StringBuilder whereClause = getWhereClause(query);
                    final BoundingBox boundingBox = QueryValue.getBoundingBox(query);
                    if (boundingBox == null) {
                        final StringBuilder sql = new StringBuilder();
                        sql.append("SELECT OBJECTID FROM ");
                        sql.append(JdbcUtils.getTableName(typePath));
                        if (whereClause.length() > 0) {
                            sql.append(" WHERE ");
                            sql.append(whereClause);
                        }
                        try (final FileGdbEnumRowsIterator rows = query(sql.toString(), false)) {
                            int count = 0;
                            for (@SuppressWarnings("unused") final Row row : rows) {
                                count++;
                            }
                            return count;
                        }
                    } else {
                        final GeometryFieldDefinition geometryField = (GeometryFieldDefinition) recordDefinition.getGeometryField();
                        if (geometryField == null || boundingBox.isEmpty()) {
                            return 0;
                        } else {
                            final StringBuilder sql = new StringBuilder();
                            sql.append("SELECT " + geometryField.getName() + " FROM ");
                            sql.append(JdbcUtils.getTableName(typePath));
                            if (whereClause.length() > 0) {
                                sql.append(" WHERE ");
                                sql.append(whereClause);
                            }
                            try (final FileGdbEnumRowsIterator rows = query(sql.toString(), false)) {
                                int count = 0;
                                for (final Row row : rows) {
                                    final Geometry geometry = (Geometry) geometryField.getValue(row);
                                    if (geometry != null) {
                                        final BoundingBox geometryBoundingBox = geometry.getBoundingBox();
                                        if (geometryBoundingBox.intersects(boundingBox)) {
                                            count++;
                                        }
                                    }
                                }
                                return count;
                            }
                        }
                    }
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) Geometry(com.revolsys.geometry.model.Geometry) BoundingBox(com.revolsys.geometry.model.BoundingBox) GeometryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordDefinition (com.revolsys.record.schema.RecordDefinition)189 FieldDefinition (com.revolsys.record.schema.FieldDefinition)38 Record (com.revolsys.record.Record)34 Geometry (com.revolsys.geometry.model.Geometry)20 CodeTable (com.revolsys.record.code.CodeTable)19 Query (com.revolsys.record.query.Query)18 LineString (com.revolsys.geometry.model.LineString)17 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)16 PathName (com.revolsys.io.PathName)13 ArrayList (java.util.ArrayList)12 DataType (com.revolsys.datatype.DataType)11 Identifier (com.revolsys.identifier.Identifier)11 RecordReader (com.revolsys.record.io.RecordReader)11 RecordStore (com.revolsys.record.schema.RecordStore)11 HashMap (java.util.HashMap)9 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 ArrayRecord (com.revolsys.record.ArrayRecord)8 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)5 RecordWriter (com.revolsys.record.io.RecordWriter)5