use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class AbstractCodeTable method getIdentifier.
@Override
public Identifier getIdentifier(final List<Object> values, final boolean loadMissing) {
if (values.size() == 1) {
final Object id = values.get(0);
if (id == null) {
return null;
} else {
final Identifier cachedId = this.idIdCache.get(id);
if (cachedId != null) {
return cachedId;
} else {
String lowerId = id.toString();
if (!this.caseSensitive) {
lowerId = lowerId.toLowerCase();
}
if (this.stringIdMap.containsKey(lowerId)) {
return this.stringIdMap.get(lowerId);
}
}
}
}
processValues(values);
Identifier id = getIdByValue(values);
if (id == null && loadMissing) {
synchronized (this) {
id = loadId(values, true);
if (id != null && !this.idValueCache.containsKey(id)) {
addValue(id, values);
}
}
}
return id;
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class CodeTableProperty method addValue.
public void addValue(final Record code) {
final String idFieldName = getIdFieldName();
final Identifier id = code.getIdentifier(idFieldName);
if (id == null) {
throw new NullPointerException(idFieldName + "=null for " + code);
} else {
final List<Object> values = new ArrayList<>();
for (final String fieldName : this.valueFieldNames) {
Object value = code.getValue(fieldName);
if (value instanceof SingleIdentifier) {
final SingleIdentifier identifier = (SingleIdentifier) value;
value = identifier.getValue(0);
}
if (value == null) {
if (!this.allowNullValues) {
throw new NullPointerException(this.valueFieldNames + "=null for " + code);
}
}
values.add(value);
}
addValue(id, values);
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class CodeTableProperty method loadId.
@Override
protected synchronized Identifier loadId(final List<Object> values, final boolean createId) {
if (this.loadAll && !this.loadMissingCodes && !isEmpty()) {
return null;
}
Identifier id = null;
if (createId && this.loadAll && !isLoaded()) {
loadAll();
id = getIdentifier(values, false);
} else {
final Query query = new Query(this.typePath);
final And and = new And();
if (!values.isEmpty()) {
int i = 0;
for (final String fieldName : this.valueFieldNames) {
final Object value = values.get(i);
if (value == null) {
and.and(Q.isNull(fieldName));
} else {
final FieldDefinition fieldDefinition = this.recordDefinition.getField(fieldName);
and.and(Q.equal(fieldDefinition, value));
}
i++;
}
}
query.setWhereCondition(and);
final Reader<Record> reader = this.recordStore.getRecords(query);
try {
final List<Record> codes = reader.toList();
if (codes.size() > 0) {
final CategoryLabelCountMap statistics = this.recordStore.getStatistics();
if (statistics != null) {
statistics.getLabelCountMap("query").addCount(this.typePath, -codes.size());
}
addValues(codes);
}
id = getIdByValue(values);
Property.firePropertyChange(this, "valuesChanged", false, true);
} finally {
reader.close();
}
}
if (createId && id == null) {
return newIdentifier(values);
} else {
return id;
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class CodeTableProperty method loadValues.
@Override
protected List<Object> loadValues(final Object id) {
if (this.loadAll && !isLoaded()) {
loadAll();
} else {
try {
final Record code;
if (id instanceof Identifier) {
final Identifier identifier = (Identifier) id;
code = this.recordStore.getRecord(this.typePath, identifier);
} else {
code = this.recordStore.getRecord(this.typePath, id);
}
if (code != null) {
addValue(code);
}
} catch (final Throwable e) {
return null;
}
}
return getValueById(id);
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class SimpleCodeTable method newCodeTable.
public static CodeTable newCodeTable(final String name, final Resource resource) {
final SimpleCodeTable codeTable = new SimpleCodeTable(name);
try (final RecordReader reader = RecordReader.newRecordReader(resource)) {
for (final Record record : reader) {
final Identifier id = record.getIdentifier(0);
final List<Object> values = new ArrayList<>();
final int fieldCount = record.getRecordDefinition().getFieldCount();
for (int i = 1; i < fieldCount; i++) {
final Object value = record.getValue(i);
values.add(value);
}
codeTable.addValue(id, values);
}
}
return codeTable;
}
Aggregations