Comments (3)
The introduction of lazy-loading forces adressing a couple of general-nature issues. Most prominently, lazy-loading does not work in conjunction with null values. Imagine a resource model "A" referencing a resource model "B":
a : A {
b : B
}
To signal whether "b" exists or not, "a.b" can be null. However, to determine whether that is the case, one must actually attempt to load and adapt "B" from the persistence layer - which is exactly what we do not want for lazy loading.
Usually, one injects a proxy object for lazily loaded references and loads the actually referenced object when the proxy is accessed. However, this would mean that any lazy reference is never null, and that the (poor) client accessing the proxied reference will find out that the hidden target of the reference is null by means of an NPE when accessing a proxied method. He would have no useful means to find out if the reference is there - or not.
This issue can only be prevented by following the value-holder pattern, like so:
a : A {
b : Optional<B>
}
Here, b is of type Optional, which offers ways to determine if the reference exists. This pattern is employed by languages that strive to abolish null, e.g. in Scala's Option.
The only kind of references that can be made lazy transparantly are collections, since they have a natural empty state - and NEBA guarantees that non - @unmapped collections are not null.
I thus suggest to implement lazy loading like so:
- By default, make collection-valued references, such as @children or @reference with collection-types, lazy
- In addition, provide a ValueHolder interface that can explicitly be used in @ResourceModels to signal that references are lazy-loaded. This also allows declaring:
a : A {
b : Optional<Collection<B>>
}
Thus, users can choose the style of collection lazy-loading: Explicit or implicit.
In addition, I do suggest that we make the value holder interface API compatible to the Java 8 Optional type, to ensure smooth transitioning from older java versions in the future.
from neba.
Feature branch: https://github.com/unic/neba/tree/feature/neba-15
from neba.
Implemented and shipped with 3.4.0
from neba.
Related Issues (20)
- Documentation: Improve IOC /DI description HOT 1
- Upgrade to Spring 5.3.0_1 HOT 1
- BUG: Minor Log File Viewer Display issue in chrome HOT 1
- Enhancement: Remove neba api maven dependency to tldgen HOT 1
- BUG: Exception handling to tolerant: Exceptions in @AfterMapping methods are logged, but not re-thrown HOT 1
- Update to Spring 5.3.1_1 HOT 1
- Update to Spring 5.3.2_1 HOT 2
- Update to Spring 5.3.3_1 HOT 1
- Update to Spring 5.3.7_1
- Update to Spring 5.3.8_1
- Upgrade to travis-ci.com HOT 1
- Update to Spring 5.3.13_1 HOT 1
- Introduce a github action CI/CD workflow as a replacement for the decomissioned travis-ci workflow HOT 1
- Update to Spring 5.3.15_1 HOT 1
- Automate release process using Github actions
- Update Spring version to mitigate CVE-2022-22950 / cve-2022-22965: DoS and RCE HOT 1
- Release an update for Spring CVE-2022-22968
- Log viewer: superfluous use of "/g" regex causes backtracking, potential recusion errors HOT 1
- Update to Spring 5.3.21_1 HOT 1
- Support Jackson-databind 2.13.4 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neba.