Search in sources :

Example 1 with Row

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

the class FileGdbEnumRowsIterator method getNext.

@Override
protected Row getNext() {
    synchronized (this.recordStore.getApiSync()) {
        if (this.rows == null) {
            throw new NoSuchElementException();
        } else {
            closeObject();
            final Row row = this.rows.next();
            if (row == null) {
                throw new NoSuchElementException();
            } else {
                return row;
            }
        }
    }
}
Also used : Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with Row

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

the class FileGdbRecordStore method deleteRecord.

boolean deleteRecord(final Table table, final Record record) {
    final Integer objectId = record.getInteger("OBJECTID");
    final PathName typePath = record.getPathName();
    if (objectId != null && table != null) {
        synchronized (table) {
            final String whereClause = "OBJECTID=" + objectId;
            try (final FileGdbEnumRowsIterator rows = search(typePath, table, "OBJECTID", whereClause, false)) {
                for (final Row row : rows) {
                    synchronized (this.apiSync) {
                        final boolean loadOnly = isTableLocked(typePath);
                        if (loadOnly) {
                            table.setLoadOnlyMode(false);
                        }
                        table.deleteRow(row);
                        if (loadOnly) {
                            table.setLoadOnlyMode(true);
                        }
                    }
                    record.setState(RecordState.DELETED);
                    addStatistic("Delete", record);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : PathName(com.revolsys.io.PathName) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row)

Example 3 with Row

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

the class FileGdbRecordStore method insertRecord.

void insertRecord(final Table table, final Record record) {
    final RecordDefinition sourceRecordDefinition = record.getRecordDefinition();
    final RecordDefinition recordDefinition = getRecordDefinition(sourceRecordDefinition);
    validateRequired(record, recordDefinition);
    final PathName typePath = recordDefinition.getPathName();
    if (table == null) {
        throw new ObjectException(record, "Cannot find table: " + typePath);
    } else {
        try {
            final Row row = newRowObject(table);
            try {
                for (final FieldDefinition field : recordDefinition.getFields()) {
                    final String name = field.getName();
                    try {
                        final Object value = record.getValue(name);
                        final AbstractFileGdbFieldDefinition esriField = (AbstractFileGdbFieldDefinition) field;
                        esriField.setInsertValue(record, row, value);
                    } catch (final Throwable e) {
                        throw new ObjectPropertyException(record, name, e);
                    }
                }
                insertRow(table, row);
                if (sourceRecordDefinition == recordDefinition) {
                    for (final FieldDefinition field : recordDefinition.getFields()) {
                        final AbstractFileGdbFieldDefinition esriField = (AbstractFileGdbFieldDefinition) field;
                        try {
                            esriField.setPostInsertValue(record, row);
                        } catch (final Throwable e) {
                            throw new ObjectPropertyException(record, field.getName(), e);
                        }
                    }
                    record.setState(RecordState.PERSISTED);
                }
            } finally {
                row.delete();
                addStatistic("Insert", record);
            }
        } catch (final ObjectException e) {
            if (e.getObject() == record) {
                throw e;
            } else {
                throw new ObjectException(record, e);
            }
        } catch (final Throwable e) {
            throw new ObjectException(record, e);
        }
    }
}
Also used : ObjectPropertyException(com.revolsys.beans.ObjectPropertyException) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) OidFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.OidFieldDefinition) DoubleFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.DoubleFieldDefinition) FloatFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.FloatFieldDefinition) AreaFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition) StringFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.StringFieldDefinition) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GlobalIdFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition) IntegerFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.IntegerFieldDefinition) GuidFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GuidFieldDefinition) XmlFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.XmlFieldDefinition) ShortFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.ShortFieldDefinition) LengthFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition) BinaryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.BinaryFieldDefinition) DateFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.DateFieldDefinition) GeometryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition) PathName(com.revolsys.io.PathName) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) ObjectException(com.revolsys.beans.ObjectException) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 4 with Row

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

Example 5 with Row

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

the class FileGdbRecordStore method updateRecord.

void updateRecord(final Table table, final Record record) {
    final Object objectId = record.getValue("OBJECTID");
    if (objectId == null) {
        insertRecord(table, record);
    } else {
        final RecordDefinition sourceRecordDefinition = record.getRecordDefinition();
        final RecordDefinition recordDefinition = getRecordDefinition(sourceRecordDefinition);
        validateRequired(record, recordDefinition);
        final PathName typePath = sourceRecordDefinition.getPathName();
        final String whereClause = "OBJECTID=" + objectId;
        try (final FileGdbEnumRowsIterator rows = search(typePath, table, "*", whereClause, false)) {
            for (final Row row : rows) {
                try {
                    for (final FieldDefinition field : recordDefinition.getFields()) {
                        final String name = field.getName();
                        try {
                            final Object value = record.getValue(name);
                            final AbstractFileGdbFieldDefinition esriField = (AbstractFileGdbFieldDefinition) field;
                            esriField.setUpdateValue(record, row, value);
                        } catch (final Throwable e) {
                            throw new ObjectPropertyException(record, name, e);
                        }
                    }
                    updateRow(typePath, table, row);
                    record.setState(RecordState.PERSISTED);
                    addStatistic("Update", record);
                } catch (final ObjectException e) {
                    if (e.getObject() == record) {
                        throw e;
                    } else {
                        throw new ObjectException(record, e);
                    }
                } catch (final Throwable e) {
                    throw new ObjectException(record, e);
                }
            }
        }
    }
}
Also used : ObjectPropertyException(com.revolsys.beans.ObjectPropertyException) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) OidFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.OidFieldDefinition) DoubleFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.DoubleFieldDefinition) FloatFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.FloatFieldDefinition) AreaFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition) StringFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.StringFieldDefinition) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GlobalIdFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition) IntegerFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.IntegerFieldDefinition) GuidFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GuidFieldDefinition) XmlFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.XmlFieldDefinition) ShortFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.ShortFieldDefinition) LengthFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition) BinaryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.BinaryFieldDefinition) DateFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.DateFieldDefinition) GeometryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition) PathName(com.revolsys.io.PathName) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) ObjectException(com.revolsys.beans.ObjectException) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

Row (com.revolsys.gis.esri.gdb.file.capi.swig.Row)6 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)4 AbstractFileGdbFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition)3 GeometryFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition)3 PathName (com.revolsys.io.PathName)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 ObjectException (com.revolsys.beans.ObjectException)2 ObjectPropertyException (com.revolsys.beans.ObjectPropertyException)2 AreaFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition)2 BinaryFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.BinaryFieldDefinition)2 DateFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.DateFieldDefinition)2 DoubleFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.DoubleFieldDefinition)2 FloatFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.FloatFieldDefinition)2 GlobalIdFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition)2 GuidFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GuidFieldDefinition)2 IntegerFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.IntegerFieldDefinition)2 LengthFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition)2 OidFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.OidFieldDefinition)2 ShortFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.ShortFieldDefinition)2