Class Lazy<T>
- java.lang.Object
-
- one.microstream.persistence.lazy.Lazy<T>
-
- Type Parameters:
T-
- All Implemented Interfaces:
LazyReferencing<T>,Referencing<T>
public final class Lazy<T> extends Object implements LazyReferencing<T>
A reference providing generic lazy-loading functionality.Note that the shortened name has been chosen intentionally to optimize readability in class design.
Also note that a type like this is strongly required to implement lazy loading behavior in an architectural clean and proper way. I.e. the design has to define that a certain reference is meant be capable of lazy-loading. If such a definition is not done, a loading logic is strictly required to always load the encountered reference, as it is defined by the normal reference. Any "tricks" of whatever framework to "sneak in" lazy loading behavior where it hasn't actually been defined are nothing more than dirty hacks and mess up if not destroy the program's consistency of state (e.g. antipatterns like secretly replacing a well-defined collection instance with a framework-proprietary proxy instance of a "similar" collection implementation). In proper architectured sofware, if a reference does not define lazy loading capacity, it is not wanted to have that capacity on the business logical level by design in the first place. Any attempts of saying "but I want it anyway in a sneaky 'transparent' way" indicate ambivalent conflicting design errors and thus in the end poor design.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLazy.Checker
-
Constructor Summary
Constructors Constructor Description Lazy()
-
Method Summary
Modifier and Type Method Description static Lazy.CheckerChecker(long millisecondTimeout)Tclear()Clears the reference, leaving the option to re-load it again intact, and returns the subject that was referenced prior to clearing.static voidclear(Lazy<?> reference)static Class<Lazy<?>>genericType()Tget()Returns the original subject referenced by this reference instance.static <T> Tget(Lazy<T> reference)booleanisStored()static booleanisStored(Lazy<?> reference)longlastTouched()static <T> Lazy<T>New(long objectId)static <T> Lazy<T>New(long objectId, PersistenceObjectRetriever loader)static <T> Lazy<T>New(T subject, long objectId, PersistenceObjectRetriever loader)longobjectId()Tpeek()Returns the wrapped reference in its current state without loading it on demand.static <T> Tpeek(Lazy<T> reference)static <T> Lazy<T>Reference(T subject)StringtoString()
-
-
-
Method Detail
-
get
public static final <T> T get(Lazy<T> reference)
-
peek
public static final <T> T peek(Lazy<T> reference)
-
clear
public static final void clear(Lazy<?> reference)
-
isStored
public static final boolean isStored(Lazy<?> reference)
-
Reference
public static final <T> Lazy<T> Reference(T subject)
-
New
public static final <T> Lazy<T> New(long objectId)
-
New
public static final <T> Lazy<T> New(long objectId, PersistenceObjectRetriever loader)
-
New
public static final <T> Lazy<T> New(T subject, long objectId, PersistenceObjectRetriever loader)
-
Checker
public static final Lazy.Checker Checker(long millisecondTimeout)
-
objectId
public final long objectId()
-
lastTouched
public final long lastTouched()
-
isStored
public final boolean isStored()
-
peek
public final T peek()
Returns the wrapped reference in its current state without loading it on demand.- Specified by:
peekin interfaceLazyReferencing<T>- Returns:
- the current reference withouth on-demand loading.
-
clear
public final T clear()
Clears the reference, leaving the option to re-load it again intact, and returns the subject that was referenced prior to clearing.- Returns:
- the subject referenced prior to clearing the reference.
-
get
public final T get()
Returns the original subject referenced by this reference instance. If the subject has (lazily) not been loaded, an attempt to do so now is made. Any exception occuring during the loading attempt will be passed along without currupting this reference instance's internal state.- Specified by:
getin interfaceLazyReferencing<T>- Specified by:
getin interfaceReferencing<T>- Returns:
- the originally referenced subject, either already-known or lazy-loaded.
-
-