Search in sources :

Example 1 with ObjectException

use of com.revolsys.beans.ObjectException 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 2 with ObjectException

use of com.revolsys.beans.ObjectException 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

ObjectException (com.revolsys.beans.ObjectException)2 ObjectPropertyException (com.revolsys.beans.ObjectPropertyException)2 Row (com.revolsys.gis.esri.gdb.file.capi.swig.Row)2 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)2 AbstractFileGdbFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition)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 GeometryFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition)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 StringFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.StringFieldDefinition)2 XmlFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.XmlFieldDefinition)2 PathName (com.revolsys.io.PathName)2