Skip to content

Commit

Permalink
Performs lookups in the force events
Browse files Browse the repository at this point in the history
Moves the actual lookup to the "forced" methods, making the calls a bit more natural

Fixes: SIRI-1039
  • Loading branch information
idlira committed Dec 16, 2024
1 parent a7f240b commit dc8f9b9
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/main/java/sirius/db/mixing/types/BaseEntityRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,10 @@ public E fetchValue() {
* @return the entity being referenced or <tt>null</tt> if no entity is referenced.
*/
public E fetchCachedValue() {
if (value == null && id != null) {
Optional<E> entity = find(type, id);
if (entity.isPresent()) {
value = entity.get();
} else {
id = null;
}
if (value != null) {
return value;
}
return value;
return forceFetchValue();
}

/**
Expand All @@ -199,23 +194,30 @@ public E fetchCachedValue() {
* @return the entity being referenced or <tt>null</tt> if no entity is referenced.
*/
public E forceFetchValue() {
value = null;
return fetchCachedValue();
Optional<E> entity = find(type, id);
if (entity.isPresent()) {
value = entity.get();
} else {
id = null;
value = null;
}
return value;
}

/**
* Returns the effective entity object which is referenced using a secondary node of a DB cluster.
* <p>
* Note, this values returned by this method will never be cached and a new lookup is always performed.
* If a value has already been loaded via {@link #forceFetchValue()} or indirectly via {@link #fetchCachedValue()},
* it will be delivered. Otherwise, a lookup is performed using secondary nodes, but the value retrieved
* id will not be cached and subsequent calls will always perform a fresh lookup.
*
* @return the entity being referenced or <tt>null</tt> if no entity is referenced.
*/
public E fetchCachedValueFromSecondary() {
if (value == null && id != null) {
Optional<E> entity = findInSecondary(type, id);
return entity.orElse(null);
if (value != null) {
return value;
}
return value;
return forceFetchValueFromSecondary();
}

/**
Expand All @@ -225,8 +227,7 @@ public E fetchCachedValueFromSecondary() {
* @return the entity being referenced or <tt>null</tt> if no entity is referenced.
*/
public E forceFetchValueFromSecondary() {
value = null;
return fetchCachedValueFromSecondary();
return findInSecondary(type, id).orElse(null);
}

/**
Expand Down

0 comments on commit dc8f9b9

Please sign in to comment.