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