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