use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStoreLayer method updateCachedRecords.
private void updateCachedRecords(final RecordStore recordStore, final Query query) {
try (Transaction transaction = recordStore.newTransaction(Propagation.REQUIRES_NEW);
RecordReader reader = recordStore.getRecords(query)) {
for (final Record record : reader) {
final Identifier identifier = record.getIdentifier();
final RecordStoreLayerRecord cachedRecord = this.recordsByIdentifier.get(identifier);
if (cachedRecord != null) {
cachedRecord.refreshFromRecordStore(record);
}
}
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class RecordStoreLayer method getRecordsCached.
@Override
public List<LayerRecord> getRecordsCached(final Label cacheId) {
synchronized (getSync()) {
final List<LayerRecord> records = super.getRecordsCached(cacheId);
final Set<Identifier> recordIds = this.recordIdentifiersByCacheId.get(cacheId);
if (recordIds != null) {
for (final Identifier recordId : recordIds) {
final LayerRecord record = getRecordById(recordId);
if (record != null) {
records.add(record);
}
}
}
return records;
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class Record method setValueByPath.
@SuppressWarnings("rawtypes")
default boolean setValueByPath(final CharSequence path, final Object value) {
boolean updated = false;
final String name = path.toString();
final int dotIndex = name.indexOf(".");
String codeTableFieldName;
String codeTableValueName = null;
final RecordDefinition recordDefinition = getRecordDefinition();
if (dotIndex == -1) {
if (recordDefinition.isIdField(name)) {
codeTableFieldName = null;
} else {
codeTableFieldName = name;
}
} else {
codeTableFieldName = name.substring(0, dotIndex);
codeTableValueName = name.substring(dotIndex + 1);
}
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(codeTableFieldName);
if (codeTable == null) {
if (dotIndex != -1) {
Logs.debug(this, "Cannot get code table for " + recordDefinition.getPath() + "." + name);
return false;
}
updated = setValue(name, value);
} else if (!Property.hasValue(value)) {
updated = setValue(codeTableFieldName, null);
} else {
Object targetValue;
if (codeTableValueName == null) {
Identifier id;
if (value instanceof List) {
final List list = (List) value;
id = codeTable.getIdentifier(list.toArray());
} else {
id = codeTable.getIdentifier(value);
}
if (id == null) {
targetValue = value;
} else {
targetValue = Value.getValue(id);
}
} else {
targetValue = codeTable.getIdentifier(Collections.singletonMap(codeTableValueName, value));
}
if (targetValue == null) {
targetValue = value;
}
updated = setValue(codeTableFieldName, targetValue);
}
return updated;
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class Record method setIdentifier.
default void setIdentifier(final Identifier identifier) {
final RecordDefinition recordDefinition = getRecordDefinition();
final RecordState state = getState();
if (state == RecordState.NEW || state == RecordState.INITIALIZING) {
final List<String> idFieldNames = recordDefinition.getIdFieldNames();
Identifier.setIdentifier(this, idFieldNames, identifier);
} else {
final Identifier oldIdentifier = getIdentifier();
if (!DataTypes.IDENTIFIER.equals(oldIdentifier, identifier)) {
throw new IllegalStateException("Cannot change the ID on a persisted record: " + identifier + "!=" + oldIdentifier);
}
}
}
use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.
the class CodeTable method getValues.
default <V> List<V> getValues() {
final List<V> values = new ArrayList<>();
for (final Identifier identifier : getIdentifiers()) {
final V value = getValue(identifier);
values.add(value);
}
return values;
}
Aggregations