use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class RecordRowTable method initializeColumnPreferredWidth.
@Override
protected void initializeColumnPreferredWidth(final TableColumn column) {
super.initializeColumnPreferredWidth(column);
final RecordRowTableModel model = getTableModel();
final int columnIndex = column.getModelIndex();
final FieldDefinition fieldDefinition = model.getColumnFieldDefinition(columnIndex);
if (fieldDefinition != null) {
Integer columnWidth = fieldDefinition.getProperty("tableColumnWidth");
final String columnName = fieldDefinition.getTitle();
if (columnWidth == null) {
columnWidth = fieldDefinition.getMaxStringLength() * 7;
columnWidth = Math.min(columnWidth, 200);
fieldDefinition.setProperty("tableColumnWidth", columnWidth);
}
final int nameWidth = columnName.length() * 8 + 15;
column.setPreferredWidth(Math.max(nameWidth, columnWidth));
}
}
use of com.revolsys.record.schema.FieldDefinition 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);
}
}
}
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method newIterator.
@Override
public AbstractIterator<Record> newIterator(final Query query, final Map<String, Object> properties) {
PathName typePath = query.getTypePath();
RecordDefinition recordDefinition = query.getRecordDefinition();
if (recordDefinition == null) {
recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
throw new IllegalArgumentException("Type name does not exist " + typePath);
}
} else {
typePath = recordDefinition.getPathName();
}
final String catalogPath = getCatalogPath(typePath);
final BoundingBox boundingBox = QueryValue.getBoundingBox(query);
final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
final StringBuilder whereClause = getWhereClause(query);
StringBuilder sql = new StringBuilder();
if (orderBy.isEmpty() || boundingBox != null) {
if (!orderBy.isEmpty()) {
Logs.error(this, "Unable to sort on " + catalogPath + " " + orderBy.keySet() + " as the ESRI library can't sort with a bounding box query");
}
sql = whereClause;
} else {
sql.append("SELECT ");
final List<String> fieldNames = query.getFieldNames();
if (fieldNames.isEmpty()) {
StringBuilders.append(sql, recordDefinition.getFieldNames());
} else {
StringBuilders.append(sql, fieldNames);
}
sql.append(" FROM ");
sql.append(JdbcUtils.getTableName(catalogPath));
if (whereClause.length() > 0) {
sql.append(" WHERE ");
sql.append(whereClause);
}
boolean first = true;
for (final Entry<? extends CharSequence, Boolean> entry : orderBy.entrySet()) {
final CharSequence fieldName = entry.getKey();
final DataType dataType = recordDefinition.getFieldType(fieldName);
if (dataType != null && !Geometry.class.isAssignableFrom(dataType.getJavaClass())) {
if (first) {
sql.append(" ORDER BY ");
first = false;
} else {
sql.append(", ");
}
if (fieldName instanceof FieldDefinition) {
final FieldDefinition field = (FieldDefinition) fieldName;
field.appendColumnName(sql);
} else {
sql.append(fieldName);
}
final Boolean ascending = entry.getValue();
if (!ascending) {
sql.append(" DESC");
}
} else {
Logs.error(this, "Unable to sort on " + recordDefinition.getPath() + "." + fieldName + " as the ESRI library can't sort on " + dataType + " columns");
}
}
}
final FileGdbQueryIterator iterator = new FileGdbQueryIterator(this, catalogPath, sql.toString(), boundingBox, query, query.getOffset(), query.getLimit());
iterator.setStatistics(query.getStatistics());
return iterator;
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class RecordIoTestSuite method doRecordWriteTest.
private static void doRecordWriteTest(final PathResource resource, final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final GeometryFactory geometryFactory = recordDefinition.getGeometryFactory();
try (Writer<Record> writer = RecordWriter.newRecordWriter(record, resource)) {
writer.setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
final FieldDefinition geometryField = recordDefinition.getGeometryField();
if (geometryField != null) {
final DataType geometryDataType = geometryField.getDataType();
writer.setProperty(IoConstants.GEOMETRY_TYPE, geometryDataType);
}
writer.write(record);
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class FileGdbQueryIterator method getNext.
@Override
protected synchronized Record getNext() throws NoSuchElementException {
final FileGdbRecordStore recordStore = this.recordStore;
final FileGdbEnumRowsIterator rows = this.rows;
if (rows == null || this.closed) {
throw new NoSuchElementException();
} else {
Row row = null;
while (this.offset > 0 && this.count < this.offset) {
row = rows.next();
this.count++;
if (this.closed) {
throw new NoSuchElementException();
}
}
if (this.count - this.offset >= this.limit) {
throw new NoSuchElementException();
}
row = rows.next();
this.count++;
try {
final Record record = this.recordFactory.newRecord(this.recordDefinition);
if (this.labelCountMap == null) {
recordStore.addStatistic("query", record);
} else {
this.labelCountMap.addCount(record);
}
record.setState(RecordState.INITIALIZING);
for (final FieldDefinition field : this.recordDefinition.getFields()) {
final String name = field.getName();
final AbstractFileGdbFieldDefinition esriFieldDefinition = (AbstractFileGdbFieldDefinition) field;
final Object value = esriFieldDefinition.getValue(row);
record.setValue(name, value);
if (this.closed) {
throw new NoSuchElementException();
}
}
record.setState(RecordState.PERSISTED);
if (this.closed) {
throw new NoSuchElementException();
}
return record;
} catch (final RuntimeException e) {
if (this.closed) {
throw new NoSuchElementException();
} else {
throw e;
}
} finally {
row.delete();
}
}
}
Aggregations