|
| 1 | += Lazy References |
| 2 | + |
| 3 | +Lazy Loading is an essential part of EclipseStore. |
| 4 | +The basic mechanism is best explained in the https://docs.eclipsestore.io/manual/storage/loading-data/lazy-loading/index.html[EclipseStore-Docs]. + |
| 5 | +In essence java objects which are wrapped in a *Lazy-Reference are not loaded with the startup of the EclipseStore-Storage but only if ``get()`` is called* on them. |
| 6 | + |
| 7 | +Lazy References are essential for big data sets that can't get loaded into memory. |
| 8 | +Since {product-name} operates with xref:working-copies.adoc[working copies] using the EclipseStore-Lazy-References is not possible. + |
| 9 | +If you are using the EclipseStore-Lazy-References, all references would be resolved and loaded into memory as soon as a working copy is created, because the ``get()``-Method is called to create a full working copy. |
| 10 | + |
| 11 | +That's why we implemented ``SpringDataEclipseStoreLazy``. + |
| 12 | +The usage is the same as with the EclipseStore-Lazies, but they are handled very differently. |
| 13 | + |
| 14 | +Simply wrap any kind of java object in the SpringDataEclipseStoreLazy-Wrapper and the wrapped object has a lazy loading behaviour. |
| 15 | + |
| 16 | +CAUTION: Lazy-References are not only loaded when needed, but also https://docs.eclipsestore.io/manual/storage/loading-data/lazy-loading/clearing-lazy-references.html#automatically[*cleared when they are no longer needed*]! |
| 17 | + |
| 18 | +Example: ``SpringDataEclipseStoreLazy.build(new HashMap<String, Pet>())`` |
| 19 | + |
| 20 | +[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/owner/Owner.java[Example from complex demo]"] |
| 21 | +---- |
| 22 | +package software.xdev.spring.data.eclipse.store.demo.complex.owner; |
| 23 | +//... |
| 24 | +import software.xdev.spring.data.eclipse.store.repository.lazy.SpringDataEclipseStoreLazy; |
| 25 | +
|
| 26 | +public class Owner extends Person |
| 27 | +{ |
| 28 | + private String address; |
| 29 | +
|
| 30 | + private Lazy<List<Pet>> pets = SpringDataEclipseStoreLazy.build(new ArrayList<>()); |
| 31 | + //... |
| 32 | +---- |
| 33 | + |
| 34 | +== Internas |
| 35 | + |
| 36 | +SpringDataEclipseStoreLazies work as a proxy for the EclipseStore-Lazies. |
| 37 | +As far as EclipseStore is concerned, a SpringDataEclipseStoreLazy-Object is a normal Java object that contains a Lazy-Reference. |
| 38 | + |
| 39 | +But when {product-name} creates the working copy, *the SpringDataEclipseStoreLazy-Reference is not resolved* but instead only a reference to the original Lazy-Object in EclipseStore is loaded. |
| 40 | +As soon as ``get()`` is called on the SpringDataEclipseStoreLazy, a *new working copy of the lazy object* is created. |
0 commit comments