use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class Domain method getIdentifier.
@Override
public Identifier getIdentifier(final List<Object> values, final boolean loadMissing) {
if (values.size() == 1) {
final Object value = values.get(0);
if (value == null) {
return null;
} else if (this.idValueMap.containsKey(value)) {
return Identifier.newIdentifier(value);
} else if (this.stringIdMap.containsKey(value.toString())) {
return this.stringIdMap.get(value.toString());
} else {
final String lowerValue = ((String) value).toLowerCase();
final Identifier id = this.valueIdMap.get(lowerValue);
return id;
}
} else {
throw new IllegalArgumentException("Expecting only a single value " + values);
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class Domain method addCodedValue.
public synchronized Domain addCodedValue(final Object code, final String name) {
final Identifier identifier = Identifier.newIdentifier(code);
final CodedValue value = new CodedValue(code, name);
this.codedValues.add(value);
final List<Object> values = Collections.<Object>singletonList(name);
this.idValueMap.put(identifier, values);
this.stringIdMap.put(code.toString(), identifier);
this.valueIdMap.put(name.toLowerCase(), identifier);
if (code instanceof Number) {
final int id = ((Number) code).intValue();
if (this.maxId < id) {
this.maxId = id;
}
}
return this;
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStore method newRecord.
default Record newRecord(RecordDefinition recordDefinition, final Map<String, ? extends Object> values) {
final PathName typePath = recordDefinition.getPathName();
recordDefinition = getRecordDefinition(recordDefinition);
if (recordDefinition == null) {
throw new IllegalArgumentException("Cannot find table " + typePath + " for " + this);
} else {
final Record record = newRecord(recordDefinition);
if (record != null) {
record.setValues(values);
final String idFieldName = recordDefinition.getIdFieldName();
if (Property.hasValue(idFieldName)) {
if (values.get(idFieldName) == null) {
final Identifier id = newPrimaryIdentifier(typePath);
record.setIdentifier(id);
}
}
}
return record;
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStore method newRecordWithIdentifier.
default Record newRecordWithIdentifier(final RecordDefinition recordDefinition) {
final Record record = newRecord(recordDefinition);
if (record != null) {
final String idFieldName = recordDefinition.getIdFieldName();
if (Property.hasValue(idFieldName)) {
final PathName typePath = recordDefinition.getPathName();
final Identifier id = newPrimaryIdentifier(typePath);
record.setIdentifier(id);
}
}
return record;
}
use of com.revolsys.identifier.Identifier 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);
}
}
}
}
}
}
}
Aggregations