Search in sources :

Example 56 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class RecordWriterPerformanceTest method main.

public static void main(final String[] args) {
    final Path basePath = Paths.getPath("target/test/performance/recordWriter");
    Paths.createDirectories(basePath);
    final RecordDefinition recordDefinition = newRecordDefinition(DataTypes.POINT);
    for (final RecordWriterFactory writerFactory : IoFactory.factories(RecordWriterFactory.class)) {
        writeRecords(basePath, recordDefinition, writerFactory);
    }
// writeRecords(basePath, recordDefinition, new Kml());
}
Also used : Path(java.nio.file.Path) RecordWriterFactory(com.revolsys.record.io.RecordWriterFactory) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 57 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class PostgreSQLJdbcQueryResultPager method getList.

@Override
public List<Record> getList() {
    synchronized (this) {
        if (this.results == null) {
            final ArrayList<Record> results = new ArrayList<>();
            final int pageSize = getPageSize();
            final int pageNumber = getPageNumber();
            if (pageNumber != -1) {
                String sql = getSql();
                final int startRowNum = (pageNumber - 1) * pageSize;
                sql = getSql() + " OFFSET " + startRowNum + " LIMIT " + pageSize;
                final RecordDefinition recordDefinition = getRecordDefinition();
                if (recordDefinition != null) {
                    final RecordFactory recordFactory = getRecordFactory();
                    final JdbcRecordStore recordStore = getRecordStore();
                    try (JdbcConnection connection = recordStore.getJdbcConnection()) {
                        final List<FieldDefinition> attributes = recordDefinition.getFields();
                        try (final PreparedStatement statement = connection.prepareStatement(sql);
                            final ResultSet resultSet = JdbcQueryIterator.getResultSet(statement, getQuery())) {
                            if (resultSet.next()) {
                                int i = 0;
                                do {
                                    final Record object = JdbcQueryIterator.getNextRecord(recordStore, recordDefinition, attributes, recordFactory, resultSet, this.internStrings);
                                    results.add(object);
                                    i++;
                                } while (resultSet.next() && i < pageSize);
                            }
                        } catch (final SQLException e) {
                            throw connection.getException("updateResults", sql, e);
                        }
                    }
                }
            }
            this.results = results;
        }
        return this.results;
    }
}
Also used : SQLException(java.sql.SQLException) JdbcRecordStore(com.revolsys.jdbc.io.JdbcRecordStore) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) JdbcConnection(com.revolsys.jdbc.JdbcConnection) PreparedStatement(java.sql.PreparedStatement) RecordDefinition(com.revolsys.record.schema.RecordDefinition) RecordFactory(com.revolsys.record.RecordFactory) ResultSet(java.sql.ResultSet) Record(com.revolsys.record.Record)

Example 58 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class LayerRecordForm method setFieldValue.

public void setFieldValue(final String fieldName, Object value, final boolean validate) {
    final Object oldValue = getFieldValue(fieldName);
    final RecordDefinition recordDefinition = getRecordDefinition();
    if (recordDefinition != null) {
        try {
            final FieldDefinition field = recordDefinition.getField(fieldName);
            if (field != null) {
                value = field.toFieldValue(value);
            }
        } catch (final Throwable e) {
        }
    }
    this.fieldValues.put(fieldName, value);
    final JComponent field = (JComponent) getField(fieldName);
    boolean changed = Property.isChanged(oldValue, value);
    if (!changed) {
        final Object recordValue = this.record.getValue(fieldName);
        if (Property.isChanged(oldValue, recordValue)) {
            this.record.setValueByPath(fieldName, value);
            changed = true;
        }
    }
    SwingUtil.setFieldValue(field, value);
    if (changed) {
        if (validate) {
            validateFields(fieldName);
        } else {
            final Set<String> fieldsToValidate = this.fieldsToValidate.get();
            if (fieldsToValidate != null) {
                fieldsToValidate.add(fieldName);
            }
        }
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) JComponent(javax.swing.JComponent) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 59 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class LayerRecordForm method validateFieldInternalDo.

protected boolean validateFieldInternalDo(final String fieldName) {
    final boolean oldValid = isFieldValid(fieldName);
    final Field field = getField(fieldName);
    boolean valid = true;
    if (!field.isFieldValid()) {
        final String message = field.getFieldValidationMessage();
        setFieldInvalid(fieldName, message);
        valid = false;
    }
    if (valid) {
        final Set<String> requiredFieldNames = getRequiredFieldNames();
        if (requiredFieldNames.contains(fieldName)) {
            boolean run = true;
            if (this.record.getState() == RecordState.NEW) {
                final RecordDefinition recordDefinition2 = getRecordDefinition();
                if (this.recordDefinition.isIdField(fieldName)) {
                    run = false;
                }
            }
            if (run) {
                final Object value = getFieldValue(fieldName);
                if (!Property.hasValue(value)) {
                    valid = addFieldError(fieldName, "Required");
                }
            }
        }
    }
    if (oldValid != valid) {
        final int tabIndex = getTabIndex(fieldName);
        updateTabValid(tabIndex);
    }
    return valid;
}
Also used : NumberTextField(com.revolsys.swing.field.NumberTextField) Field(com.revolsys.swing.field.Field) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 60 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition in project com.revolsys.open by revolsys.

the class LayerRecordForm method propertyChange.

@Override
public void propertyChange(final PropertyChangeEvent event) {
    final String propertyName = event.getPropertyName();
    final AbstractRecordLayer layer = getLayer();
    if (layer != null) {
        final LayerRecord record = getRecord();
        if (record != null) {
            final RecordState state = record.getState();
            if (!state.equals(RecordState.DELETED)) {
                final Object source = event.getSource();
                if (this.geometryCoordinatesPanel != null && source == this.geometryCoordinatesPanel.getTable().getModel()) {
                    if (propertyName.equals("geometry")) {
                        record.setGeometryValue((Geometry) event.getNewValue());
                    }
                } else if (source == layer) {
                    if (AbstractRecordLayer.RECORDS_CHANGED.equals(propertyName)) {
                        setRecord(record);
                    } else if (AbstractRecordLayer.RECORDS_DELETED.equals(propertyName)) {
                        @SuppressWarnings("unchecked") final List<Record> deletedRecords = (List<Record>) event.getNewValue();
                        if (layer.isDeleted(record) || record.contains(deletedRecords)) {
                            final Window window = SwingUtilities.getWindowAncestor(this);
                            SwingUtil.setVisible(window, false);
                            setRecord(record);
                            return;
                        }
                    } else if (AbstractRecordLayer.RECORD_UPDATED.equals(propertyName)) {
                        if (record.isDeleted()) {
                            final Window window = SwingUtilities.getWindowAncestor(this);
                            SwingUtil.setVisible(window, false);
                            setRecord(record);
                        }
                    } else if ("editable".equals(propertyName)) {
                        setEditable(layer.isEditable());
                    }
                } else if (source instanceof Field) {
                    final Field field = (Field) source;
                    final String fieldName = field.getFieldName();
                    final Object fieldValue = field.getFieldValue();
                    final Object recordValue = this.record.getValue(fieldName);
                    if (!DataType.equal(recordValue, fieldValue)) {
                        boolean equal = false;
                        if (fieldValue instanceof String) {
                            final String string = (String) fieldValue;
                            if (!Property.hasValue(string) && recordValue == null) {
                                equal = true;
                            }
                        }
                        if (!equal && layer.isEditable() && (state == RecordState.NEW && layer.isCanAddRecords() || layer.isCanEditRecords())) {
                            record.setValueByPath(fieldName, fieldValue);
                        }
                    }
                } else {
                    if (isSame(source)) {
                        if (getRecordDefinition().getIdFieldNames().contains(propertyName)) {
                            Invoke.later(() -> {
                                final String title = getTitle(record);
                                final BaseDialog dialog = (BaseDialog) SwingUtil.getWindowAncestor(this);
                                if (dialog != null) {
                                    dialog.setTitle(title);
                                }
                            });
                        }
                        if (record.isDeleted()) {
                            final Window window = SwingUtilities.getWindowAncestor(this);
                            SwingUtil.setVisible(window, false);
                        } else if (Record.EVENT_RECORD_CHANGED.equals(propertyName)) {
                            setValues(record);
                            return;
                        }
                        final Object value = event.getNewValue();
                        final RecordDefinition recordDefinition = getRecordDefinition();
                        if ("qaMessagesUpdated".equals(propertyName)) {
                            updateErrors();
                        } else if (recordDefinition.hasField(propertyName)) {
                            setFieldValue(propertyName, value, isFieldValidationEnabled());
                        }
                        fireButtonPropertyChanges();
                        repaint();
                    }
                }
            }
        }
    }
}
Also used : Window(java.awt.Window) BaseDialog(com.revolsys.swing.component.BaseDialog) RecordState(com.revolsys.record.RecordState) RecordDefinition(com.revolsys.record.schema.RecordDefinition) NumberTextField(com.revolsys.swing.field.NumberTextField) Field(com.revolsys.swing.field.Field) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Record(com.revolsys.record.Record) List(java.util.List) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Aggregations

RecordDefinition (com.revolsys.record.schema.RecordDefinition)189 FieldDefinition (com.revolsys.record.schema.FieldDefinition)38 Record (com.revolsys.record.Record)34 Geometry (com.revolsys.geometry.model.Geometry)20 CodeTable (com.revolsys.record.code.CodeTable)19 Query (com.revolsys.record.query.Query)18 LineString (com.revolsys.geometry.model.LineString)17 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)16 PathName (com.revolsys.io.PathName)13 ArrayList (java.util.ArrayList)12 DataType (com.revolsys.datatype.DataType)11 Identifier (com.revolsys.identifier.Identifier)11 RecordReader (com.revolsys.record.io.RecordReader)11 RecordStore (com.revolsys.record.schema.RecordStore)11 HashMap (java.util.HashMap)9 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 ArrayRecord (com.revolsys.record.ArrayRecord)8 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)5 RecordWriter (com.revolsys.record.io.RecordWriter)5