Search in sources :

Example 76 with FieldDefinition

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));
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordRowTableModel(com.revolsys.swing.table.record.model.RecordRowTableModel)

Example 77 with FieldDefinition

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

Example 78 with FieldDefinition

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;
}
Also used : 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) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) RecordDefinition(com.revolsys.record.schema.RecordDefinition) BoundingBox(com.revolsys.geometry.model.BoundingBox) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 79 with FieldDefinition

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);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 80 with FieldDefinition

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();
        }
    }
}
Also used : AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) FieldDefinition(com.revolsys.record.schema.FieldDefinition) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) Record(com.revolsys.record.Record) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

FieldDefinition (com.revolsys.record.schema.FieldDefinition)133 RecordDefinition (com.revolsys.record.schema.RecordDefinition)38 DataType (com.revolsys.datatype.DataType)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)19 PathName (com.revolsys.io.PathName)15 Record (com.revolsys.record.Record)15 ArrayList (java.util.ArrayList)15 Geometry (com.revolsys.geometry.model.Geometry)13 CodeTable (com.revolsys.record.code.CodeTable)9 Query (com.revolsys.record.query.Query)8 LineString (com.revolsys.geometry.model.LineString)7 ArrayRecord (com.revolsys.record.ArrayRecord)7 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)7 SQLException (java.sql.SQLException)7 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 BadLocationException (javax.swing.text.BadLocationException)4