Search in sources :

Example 1 with CodeTable

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

the class RecordCodeTableValueFilter method test.

/**
 * Match the fieldName on the data object with the required value.
 *
 * @param object The object.
 * @return True if the object matched the filter, false otherwise.
 */
@Override
public boolean test(final Record object) {
    final Object propertyValue = object.getValue(this.fieldName);
    if (this.values.contains(propertyValue)) {
        return true;
    } else {
        final RecordDefinition recordDefinition = object.getRecordDefinition();
        final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(this.fieldName);
        if (codeTable != null) {
            final Object codeValue = codeTable.getValue(Identifier.newIdentifier(propertyValue));
            if (this.values.contains(codeValue)) {
                this.values.add(propertyValue);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 2 with CodeTable

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

the class RecordDefinitionImpl method addField.

public synchronized void addField(final FieldDefinition field) {
    final int index = this.fieldNames.size();
    final String name = field.getName();
    String lowerName;
    if (name == null) {
        lowerName = null;
    } else {
        lowerName = name.toLowerCase();
    }
    this.internalFieldNames.add(name);
    this.fieldNames = Lists.unmodifiable(this.internalFieldNames);
    this.fieldNamesSet = Sets.unmodifiableLinked(this.internalFieldNames);
    this.internalFields.add(field);
    this.fields = Lists.unmodifiable(this.internalFields);
    this.fieldMap.put(lowerName, field);
    this.fieldIdMap.put(lowerName, this.fieldIdMap.size());
    final DataType dataType = field.getDataType();
    if (dataType == null) {
        Logs.debug(this, field.toString());
    } else {
        final Class<?> dataClass = dataType.getJavaClass();
        if (Geometry.class.isAssignableFrom(dataClass)) {
            this.geometryFieldDefinitionIndexes.add(index);
            this.geometryFieldDefinitionNames.add(name);
            if (this.geometryFieldDefinitionIndex == -1) {
                this.geometryFieldDefinitionIndex = index;
                final GeometryFactory geometryFactory = field.getProperty(FieldProperties.GEOMETRY_FACTORY);
                if (geometryFactory == null && this.geometryFactory != null) {
                    field.setProperty(FieldProperties.GEOMETRY_FACTORY, this.geometryFactory);
                }
            }
        }
    }
    field.setIndex(index);
    field.setRecordDefinition(this);
    final CodeTable codeTable = field.getCodeTable();
    addFieldCodeTable(name, codeTable);
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType)

Example 3 with CodeTable

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

the class RecordDefinitionImpl method getCodeTableByFieldName.

@Override
public CodeTable getCodeTableByFieldName(final CharSequence fieldName) {
    if (fieldName == null) {
        return null;
    } else {
        final RecordStore recordStore = getRecordStore();
        CodeTable codeTable;
        final FieldDefinition fieldDefinition = getField(fieldName);
        if (fieldDefinition != null) {
            codeTable = fieldDefinition.getCodeTable();
            if (codeTable != null) {
                return codeTable;
            }
        }
        codeTable = this.codeTableByFieldNameMap.get(fieldName.toString().toUpperCase());
        if (codeTable == null && recordStore != null) {
            codeTable = recordStore.getCodeTableByFieldName(fieldName);
        }
        if (codeTable instanceof CodeTableProperty) {
            @SuppressWarnings("resource") final CodeTableProperty property = (CodeTableProperty) codeTable;
            if (property.getRecordDefinition() == this) {
                return null;
            }
        }
        if (fieldDefinition != null && codeTable != null) {
            fieldDefinition.setCodeTable(codeTable);
        }
        return codeTable;
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) CodeTableProperty(com.revolsys.record.code.CodeTableProperty)

Example 4 with CodeTable

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

the class Value method setFieldDefinition.

@Override
public void setFieldDefinition(final FieldDefinition field) {
    if (field != null) {
        this.fieldDefinition = field;
        if (field instanceof JdbcFieldDefinition) {
            this.jdbcField = (JdbcFieldDefinition) field;
        } else {
            this.jdbcField = JdbcFieldDefinition.newFieldDefinition(this.queryValue);
        }
        CodeTable codeTable = null;
        if (field != null) {
            final RecordDefinition recordDefinition = field.getRecordDefinition();
            if (recordDefinition != null) {
                final String fieldName = field.getName();
                codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
                if (codeTable instanceof CodeTableProperty) {
                    final CodeTableProperty codeTableProperty = (CodeTableProperty) codeTable;
                    if (codeTableProperty.getRecordDefinition() == recordDefinition) {
                        codeTable = null;
                    }
                }
                if (codeTable != null) {
                    final Identifier id = codeTable.getIdentifier(this.queryValue);
                    if (id == null) {
                        this.displayValue = this.queryValue;
                    } else {
                        setQueryValue(id);
                        final List<Object> values = codeTable.getValues(id);
                        if (values.size() == 1) {
                            this.displayValue = values.get(0);
                        } else {
                            this.displayValue = Strings.toString(":", values);
                        }
                    }
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) TypedIdentifier(com.revolsys.identifier.TypedIdentifier) Identifier(com.revolsys.identifier.Identifier) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) CodeTableProperty(com.revolsys.record.code.CodeTableProperty) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 5 with CodeTable

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

the class CopyValues method process.

@Override
public void process(final Record source, final Record target) {
    for (final Entry<String, String> entry : this.fieldNames.entrySet()) {
        final String sourceName = entry.getKey();
        final String targetName = entry.getValue();
        final Object value;
        if (sourceName.startsWith("~")) {
            value = sourceName.substring(1);
        } else {
            value = source.getValueByPath(sourceName);
        }
        if (value != null) {
            final RecordDefinition targetRecordDefinition = target.getRecordDefinition();
            final CodeTable codeTable = targetRecordDefinition.getCodeTableByFieldName(targetName);
            if (codeTable == null) {
                target.setValue(targetName, value);
            } else {
                final Object codeId = codeTable.getIdentifier(value);
                target.setValue(targetName, codeId);
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

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