Search in sources :

Example 36 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class GeometryFieldDefinition method getValue.

@Override
public Object getValue(final Row row) {
    final String name = getName();
    final byte[] bytes;
    synchronized (getSync()) {
        if (row.isNull(name)) {
            return null;
        } else {
            bytes = row.getGeometry();
        }
    }
    final ByteBuffer buffer = ByteBuffer.wrap(bytes);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    final int geometryType = buffer.getInt();
    if (geometryType == 0) {
        final DataType dataType = getDataType();
        if (DataTypes.POINT.equals(dataType)) {
            return this.geometryFactory.point();
        } else if (DataTypes.MULTI_POINT.equals(dataType)) {
            return this.geometryFactory.point();
        } else if (DataTypes.LINE_STRING.equals(dataType)) {
            return this.geometryFactory.lineString();
        } else if (DataTypes.MULTI_LINE_STRING.equals(dataType)) {
            return this.geometryFactory.lineString();
        } else if (DataTypes.POLYGON.equals(dataType)) {
            return this.geometryFactory.polygon();
        } else if (DataTypes.MULTI_POLYGON.equals(dataType)) {
            return this.geometryFactory.polygon();
        } else {
            return null;
        }
    } else {
        final Geometry geometry = this.readFunction.apply(this.geometryFactory, buffer, MINUS1);
        return geometry;
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) DataType(com.revolsys.datatype.DataType) ByteBuffer(java.nio.ByteBuffer)

Example 37 with DataType

use of com.revolsys.datatype.DataType 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 38 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class PostgreSQLGeometryFieldAdder method newField.

@Override
public JdbcFieldDefinition newField(final AbstractJdbcRecordStore recordStore, final JdbcRecordDefinition recordDefinition, final String dbName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
    final JdbcRecordStoreSchema schema = recordDefinition.getSchema();
    final PathName typePath = recordDefinition.getPathName();
    String dbSchemaName = schema.getDbName();
    if (!Property.hasValue(dbSchemaName)) {
        dbSchemaName = "public";
    }
    final String tableName = recordDefinition.getDbTableName();
    final String columnName = name.toLowerCase();
    try {
        int srid = 0;
        String type = "geometry";
        int axisCount = 3;
        try {
            final String sql = "select SRID, TYPE, COORD_DIMENSION from GEOMETRY_COLUMNS where UPPER(F_TABLE_SCHEMA) = UPPER(?) AND UPPER(F_TABLE_NAME) = UPPER(?) AND UPPER(F_GEOMETRY_COLUMN) = UPPER(?)";
            final Map<String, Object> values = JdbcUtils.selectMap(this.recordStore, sql, dbSchemaName, tableName, columnName);
            srid = (Integer) values.get("srid");
            type = (String) values.get("type");
            axisCount = (Integer) values.get("coord_dimension");
        } catch (final IllegalArgumentException e) {
            Logs.warn(this, "Cannot get geometry column metadata for " + typePath + "." + columnName);
        }
        final DataType dataType = DATA_TYPE_MAP.get(type);
        final GeometryFactory storeGeometryFactory = this.recordStore.getGeometryFactory();
        final GeometryFactory geometryFactory;
        if (storeGeometryFactory == null) {
            geometryFactory = GeometryFactory.floating(srid, axisCount);
        } else {
            final double[] scales = storeGeometryFactory.newScales(axisCount);
            geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
        }
        final PostgreSQLGeometryJdbcFieldDefinition field = new PostgreSQLGeometryJdbcFieldDefinition(dbName, name, dataType, sqlType, required, description, null, srid, axisCount, geometryFactory);
        field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
        return field;
    } catch (final Throwable e) {
        Logs.error(this, "Attribute not registered in GEOMETRY_COLUMN table " + dbSchemaName + "." + tableName + "." + name, e);
        return null;
    }
}
Also used : JdbcRecordStoreSchema(com.revolsys.jdbc.io.JdbcRecordStoreSchema) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 39 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class PostgreSQLDdlWriter method writeColumnDataType.

@Override
public void writeColumnDataType(final FieldDefinition attribute) {
    final PrintWriter out = getOut();
    final DataType dataType = attribute.getDataType();
    if (dataType == DataTypes.BOOLEAN) {
        out.print("boolean");
    } else if (dataType == DataTypes.BYTE) {
        out.print("NUMBER(3)");
    } else if (dataType == DataTypes.SHORT) {
        out.print("smallint");
    } else if (dataType == DataTypes.INT) {
        out.print("integer");
    } else if (dataType == DataTypes.LONG) {
        out.print("bigint");
    } else if (dataType == DataTypes.FLOAT) {
        out.print("real");
    } else if (dataType == DataTypes.DOUBLE) {
        out.print("double precision");
    } else if (dataType == DataTypes.DATE) {
        out.print("date");
    } else if (dataType == DataTypes.DATE_TIME) {
        out.print("timestamp");
    } else if (dataType == DataTypes.BIG_INTEGER) {
        out.print("NUMERIC(");
        out.print(attribute.getLength());
        out.print(')');
    } else if (dataType == DataTypes.DECIMAL) {
        out.print("NUMERIC(");
        out.print(attribute.getLength());
        final int scale = attribute.getScale();
        if (scale >= 0) {
            out.print(',');
            out.print(scale);
        }
        out.print(')');
    } else if (dataType == DataTypes.STRING) {
        out.print("varchar(");
        out.print(attribute.getLength());
        out.print(")");
    } else if (Geometry.class.isAssignableFrom(dataType.getJavaClass())) {
        out.print("geometry");
    } else {
        throw new IllegalArgumentException("Unknown data type " + dataType);
    }
}
Also used : DataType(com.revolsys.datatype.DataType) PrintWriter(java.io.PrintWriter)

Example 40 with DataType

use of com.revolsys.datatype.DataType 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

DataType (com.revolsys.datatype.DataType)85 FieldDefinition (com.revolsys.record.schema.FieldDefinition)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 PathName (com.revolsys.io.PathName)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Geometry (com.revolsys.geometry.model.Geometry)10 Record (com.revolsys.record.Record)10 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)10 ArrayList (java.util.ArrayList)8 ArrayRecord (com.revolsys.record.ArrayRecord)6 PrintWriter (java.io.PrintWriter)6 EsriGeodatabaseXmlFieldType (com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)5 MapEx (com.revolsys.collection.map.MapEx)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 Point (com.revolsys.geometry.model.Point)4 IOException (java.io.IOException)4 Map (java.util.Map)4 CollectionDataType (com.revolsys.datatype.CollectionDataType)3 EnumerationDataType (com.revolsys.datatype.EnumerationDataType)3 CodeTable (com.revolsys.record.code.CodeTable)3