Search in sources :

Example 6 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class SetCodeTableId method process.

@Override
public void process(final Record source, final Record target) {
    final Map<String, Object> codeTableValues = new HashMap<>();
    for (final Entry<String, Converter<Record, Object>> entry : this.codeTableValueConverters.entrySet()) {
        String codeTableFieldName = entry.getKey();
        final Converter<Record, Object> sourceAttributeConverter = entry.getValue();
        Object sourceValue = sourceAttributeConverter.convert(source);
        if (sourceValue != null) {
            final RecordDefinition targetRecordDefinition = target.getRecordDefinition();
            String codeTableValueName = null;
            final int dotIndex = codeTableFieldName.indexOf(".");
            if (dotIndex != -1) {
                codeTableValueName = codeTableFieldName.substring(dotIndex + 1);
                codeTableFieldName = codeTableFieldName.substring(0, dotIndex);
            }
            final CodeTable targetCodeTable = targetRecordDefinition.getCodeTableByFieldName(codeTableFieldName);
            if (targetCodeTable != null) {
                if (codeTableValueName == null) {
                    sourceValue = targetCodeTable.getIdentifier(sourceValue);
                } else {
                    sourceValue = targetCodeTable.getIdentifier(Collections.singletonMap(codeTableValueName, sourceValue));
                }
            }
        }
        codeTableValues.put(codeTableFieldName, sourceValue);
    }
    final Object codeId = this.codeTable.getIdentifier(codeTableValues);
    target.setValue(this.targetFieldName, codeId);
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) HashMap(java.util.HashMap) Converter(org.springframework.core.convert.converter.Converter) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 7 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class MapValues method process.

@Override
public void process(final Record source, final Record target) {
    final Object sourceValue = Records.getFieldByPath(source, this.sourceFieldName);
    if (sourceValue != null) {
        final Object targetValue = this.valueMap.get(sourceValue);
        if (targetValue != null) {
            final RecordDefinition targetRecordDefinition = target.getRecordDefinition();
            final CodeTable codeTable = targetRecordDefinition.getCodeTableByFieldName(this.targetFieldName);
            if (codeTable == null) {
                target.setValue(this.targetFieldName, targetValue);
            } else {
                final Object codeId = codeTable.getIdentifier(targetValue);
                target.setValue(this.targetFieldName, codeId);
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 8 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class Record method equalValue.

default boolean equalValue(final CharSequence fieldName, Object value) {
    final FieldDefinition fieldDefinition = getFieldDefinition(fieldName);
    if (fieldDefinition == null) {
        return false;
    } else {
        final int fieldIndex = fieldDefinition.getIndex();
        final Object fieldValue = getValue(fieldIndex);
        final CodeTable codeTable = fieldDefinition.getCodeTable();
        if (codeTable != null) {
            value = codeTable.getIdentifier(value);
        }
        return fieldDefinition.equals(fieldValue, value);
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Example 9 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method newTableRecordDefinition.

private RecordDefinitionImpl newTableRecordDefinition(final DETable deTable) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase == null) {
                return null;
            } else {
                try {
                    String schemaCatalogPath = deTable.getParentCatalogPath();
                    SpatialReference spatialReference;
                    if (deTable instanceof DEFeatureClass) {
                        final DEFeatureClass featureClass = (DEFeatureClass) deTable;
                        spatialReference = featureClass.getSpatialReference();
                    } else {
                        spatialReference = null;
                    }
                    PathName schemaPath = toPath(schemaCatalogPath);
                    final RecordStoreSchema schema = newSchema(schemaPath, spatialReference);
                    if (schemaPath.equals(this.defaultSchemaPath)) {
                        if (!(deTable instanceof DEFeatureClass)) {
                            schemaCatalogPath = "\\";
                            deTable.setCatalogPath("\\" + deTable.getName());
                        }
                    } else if (schemaPath.equals("")) {
                        schemaPath = this.defaultSchemaPath;
                    }
                    for (final Field field : deTable.getFields()) {
                        final String fieldName = field.getName();
                        final CodeTable codeTable = getCodeTableByFieldName(fieldName);
                        if (codeTable instanceof FileGdbDomainCodeTable) {
                            final FileGdbDomainCodeTable domainCodeTable = (FileGdbDomainCodeTable) codeTable;
                            field.setDomain(domainCodeTable.getDomain());
                        }
                    }
                    final String tableDefinition = EsriGdbXmlSerializer.toString(deTable);
                    try {
                        final Table table = geodatabase.createTable(tableDefinition, schemaCatalogPath);
                        geodatabase.closeTable(table);
                        table.delete();
                        final RecordDefinitionImpl recordDefinition = getRecordDefinition(PathName.newPathName(schemaPath), schemaCatalogPath, tableDefinition);
                        initRecordDefinition(recordDefinition);
                        schema.addElement(recordDefinition);
                        return recordDefinition;
                    } catch (final Throwable t) {
                        throw new RuntimeException("Unable to create table " + deTable.getCatalogPath(), t);
                    }
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) CodeTable(com.revolsys.record.code.CodeTable) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable) Table(com.revolsys.gis.esri.gdb.file.capi.swig.Table) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) DEFeatureClass(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) Field(com.revolsys.record.io.format.esri.gdb.xml.model.Field) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) PathName(com.revolsys.io.PathName)

Example 10 with CodeTable

use of com.revolsys.record.code.CodeTable 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)

Aggregations

CodeTable (com.revolsys.record.code.CodeTable)30 RecordDefinition (com.revolsys.record.schema.RecordDefinition)15 FieldDefinition (com.revolsys.record.schema.FieldDefinition)9 Identifier (com.revolsys.identifier.Identifier)6 ArrayList (java.util.ArrayList)5 Geometry (com.revolsys.geometry.model.Geometry)4 DataType (com.revolsys.datatype.DataType)3 PathName (com.revolsys.io.PathName)3 BetweenOperatorNode (com.akiban.sql.parser.BetweenOperatorNode)2 BinaryArithmeticOperatorNode (com.akiban.sql.parser.BinaryArithmeticOperatorNode)2 BinaryLogicalOperatorNode (com.akiban.sql.parser.BinaryLogicalOperatorNode)2 BinaryOperatorNode (com.akiban.sql.parser.BinaryOperatorNode)2 CastNode (com.akiban.sql.parser.CastNode)2 ColumnReference (com.akiban.sql.parser.ColumnReference)2 ConstantNode (com.akiban.sql.parser.ConstantNode)2 InListOperatorNode (com.akiban.sql.parser.InListOperatorNode)2 IsNullNode (com.akiban.sql.parser.IsNullNode)2 LikeEscapeOperatorNode (com.akiban.sql.parser.LikeEscapeOperatorNode)2 NotNode (com.akiban.sql.parser.NotNode)2 NumericConstantNode (com.akiban.sql.parser.NumericConstantNode)2