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;
}
}
}
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);
}
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;
}
}
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);
}
}
}
}
}
}
}
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);
}
}
}
}
Aggregations