Skip to content

Commit b46f863

Browse files
committed
[DataStore] Add loadifAbsent and lazyGet to Store Accessors
1 parent c0bea27 commit b46f863

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

vertigo-datastore/src/main/java/io/vertigo/datastore/impl/entitystore/StoreListVAccessor.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
import io.vertigo.datamodel.data.model.ListVAccessor;
2525
import io.vertigo.datastore.entitystore.EntityStoreManager;
2626

27+
/**
28+
* This class is a way to access a list of foreign entities defined by a relationship.
29+
* It's a kind of box (aka optional) that offers a small list of methods.
30+
*
31+
* @author pchretien, mlaroche, npiedeloup *
32+
* @param <E> the type of entity
33+
*/
2734
public class StoreListVAccessor<E extends Entity> extends ListVAccessor<E> {
2835

2936
private static final long serialVersionUID = -4840484505809842010L;
@@ -52,4 +59,26 @@ public final void set(final DtList<E> dtList) {
5259
throw new VSystemException("StoreListVAccessor cannot be set, you can only load it");
5360
}
5461

62+
/**
63+
* Loads the value if needed.
64+
*/
65+
public void loadIfAbsent() {
66+
if (getSourceUID() != null && !isLoaded()) {
67+
load();
68+
}
69+
}
70+
71+
/**
72+
* Loads the value if needed.
73+
* @deprecated This usage is discouraged : prefer explicit loading by using load() then get()
74+
*/
75+
@Deprecated
76+
public DtList<E> lazyGet() {
77+
if (getSourceUID() == null) {
78+
return null;
79+
}
80+
loadIfAbsent();
81+
return get();
82+
}
83+
5584
}

vertigo-datastore/src/main/java/io/vertigo/datastore/impl/entitystore/StoreVAccessor.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* This class is a way to access an entity defined by a relationship.
2727
* It's a kind of box (aka optional) that offers a small list of methods.
2828
*
29-
* @author pchretien
29+
* @author pchretien, mlaroche, npiedeloup
3030
*
3131
* @param <E> the type of entity
3232
*/
@@ -54,4 +54,26 @@ public void load() {
5454
}
5555
}
5656

57+
/**
58+
* Loads the value if needed.
59+
*/
60+
public void loadIfAbsent() {
61+
if (getUID() != null && !isLoaded()) {
62+
load();
63+
}
64+
}
65+
66+
/**
67+
* Loads the value if needed.
68+
* @deprecated This usage is discouraged : prefer explicit loading by using load() then get()
69+
*/
70+
@Deprecated
71+
public E lazyGet() {
72+
if (getUID() == null) {
73+
return null;
74+
}
75+
loadIfAbsent();
76+
return get();
77+
}
78+
5779
}

0 commit comments

Comments
 (0)