Search in sources :

Example 51 with FieldDefinition

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

the class AbstractBinaryQueryValue method appendParameters.

@Override
public int appendParameters(int index, final PreparedStatement statement) {
    if (this.left != null) {
        if (this.right instanceof Column && !(this.left instanceof Column)) {
            final FieldDefinition rightFieldDefinition = ((Column) this.right).getFieldDefinition();
            this.left.setFieldDefinition(rightFieldDefinition);
        }
        index = this.left.appendParameters(index, statement);
    }
    if (this.right != null) {
        if (this.left instanceof Column && !(this.right instanceof Column)) {
            final FieldDefinition rightFieldDefinition = ((Column) this.left).getFieldDefinition();
            this.right.setFieldDefinition(rightFieldDefinition);
        }
        index = this.right.appendParameters(index, statement);
    }
    return index;
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Example 52 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition 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);
        }
    }
}
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) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) ObjectException(com.revolsys.beans.ObjectException) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 53 with FieldDefinition

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

the class SwingUtil method newField.

@SuppressWarnings("unchecked")
static <T extends Field> T newField(final RecordDefinition recordDefinition, final String fieldName, final boolean editable) {
    Field field;
    final FieldDefinition fieldDefinition = recordDefinition.getField(fieldName);
    if (fieldDefinition == null) {
        throw new IllegalArgumentException("Cannot find field " + fieldName);
    } else {
        final boolean required = fieldDefinition.isRequired();
        final int length = fieldDefinition.getLength();
        CodeTable codeTable;
        if (recordDefinition.getIdFieldNames().contains(fieldName)) {
            codeTable = null;
        } else {
            codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
        }
        final DataType type = fieldDefinition.getDataType();
        int columns = length;
        if (columns <= 0) {
            columns = 10;
        } else if (columns > 50) {
            columns = 50;
        }
        final Class<?> javaClass = type.getJavaClass();
        if (codeTable != null) {
            if (editable) {
                final JComponent component = codeTable.getSwingEditor();
                if (component == null) {
                    field = newComboBox(fieldName, codeTable, required, -1, false);
                } else {
                    field = ((Field) component).clone();
                }
            } else {
                field = new ObjectLabelField(fieldName, columns, codeTable);
            }
        } else if (!editable) {
            final TextField textField = newTextField(fieldName, columns);
            textField.setEditable(false);
            field = textField;
        } else if (Number.class.isAssignableFrom(javaClass)) {
            final int scale = fieldDefinition.getScale();
            final Number minValue = fieldDefinition.getMinValue();
            final Number maxValue = fieldDefinition.getMaxValue();
            final NumberTextField numberTextField = new NumberTextField(fieldName, type, length, scale, minValue, maxValue);
            field = numberTextField;
        } else if (Date.class.isAssignableFrom(javaClass)) {
            field = newDateField(fieldName);
        } else if (Geometry.class.isAssignableFrom(javaClass)) {
            field = new ObjectLabelField(fieldName);
        } else {
            field = newTextField(fieldName, columns);
        }
    }
    if (field instanceof JTextField) {
        final JTextField textField = (JTextField) field;
        final int preferedWidth = textField.getPreferredSize().width;
        textField.setMinimumSize(new Dimension(preferedWidth, 0));
        textField.setMaximumSize(new Dimension(preferedWidth, Integer.MAX_VALUE));
    }
    ((JComponent) field).setFont(FONT);
    return (T) field;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) NumberTextField(com.revolsys.swing.field.NumberTextField) FieldDefinition(com.revolsys.record.schema.FieldDefinition) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) Point(java.awt.Point) Date(java.util.Date) NumberTextField(com.revolsys.swing.field.NumberTextField) DateField(com.revolsys.swing.field.DateField) JTextField(javax.swing.JTextField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) ColorChooserField(com.revolsys.swing.field.ColorChooserField) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField) DataType(com.revolsys.datatype.DataType) NumberTextField(com.revolsys.swing.field.NumberTextField) JTextField(javax.swing.JTextField) TextField(com.revolsys.swing.field.TextField) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField)

Example 54 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition 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 55 with FieldDefinition

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

the class QueryWhereConditionField method actionAddInCondition.

private void actionAddInCondition() {
    final FieldDefinition fieldDefinition = this.fieldNamesList.getSelectedItem();
    if (fieldDefinition != null) {
        Object fieldValue = ((Field) this.searchField).getFieldValue();
        if (Property.hasValue(fieldValue)) {
            int position = this.whereTextField.getCaretPosition();
            DataType fieldType = fieldDefinition.getDataType();
            if (fieldValue != null) {
                if (this.codeTable == null) {
                    try {
                        fieldValue = fieldDefinition.toFieldValue(fieldValue);
                    } catch (final Throwable e) {
                        setInvalidMessage("'" + fieldValue + "' is not a valid " + fieldType.getValidationName());
                        return;
                    }
                } else {
                    fieldValue = this.codeTable.getValue(fieldValue);
                    if (fieldValue != null) {
                        fieldType = DataTypes.STRING;
                    }
                }
                if (fieldValue != null) {
                    final StringBuilder text = new StringBuilder();
                    try {
                        final Document document = this.whereTextField.getDocument();
                        final String currentText = document.getText(0, position);
                        final Matcher matcher = Pattern.compile("(?:.+ )?" + fieldDefinition.getName() + " IN \\((?:.+,\\s*)*'?((?:[^']|'')*)'?\\) $").matcher(currentText);
                        if (matcher.matches()) {
                            final String previousValue = matcher.group(1).replace("''", "'");
                            if (!DataType.equal(fieldValue, previousValue)) {
                                position -= 2;
                                text.append(", ");
                                appendValue(text, fieldType, fieldValue);
                            }
                        } else {
                            if (position > 0) {
                                text.append(" ");
                            }
                            text.append(fieldDefinition.getName());
                            text.append(" IN (");
                            appendValue(text, fieldType, fieldValue);
                            text.append(") ");
                        }
                        document.insertString(position, text.toString(), null);
                    } catch (final BadLocationException e) {
                        Logs.error(this, "Error inserting text: " + text, e);
                    }
                }
            }
        }
    }
}
Also used : ValueField(com.revolsys.swing.component.ValueField) Matcher(java.util.regex.Matcher) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

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