GithubHelp home page GithubHelp logo

Comments (3)

olaf-otto avatar olaf-otto commented on June 16, 2024

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.

olaf-otto avatar olaf-otto commented on June 16, 2024

Feature branch: https://github.com/unic/neba/tree/feature/neba-15

from neba.

olaf-otto avatar olaf-otto commented on June 16, 2024

Implemented and shipped with 3.4.0

from neba.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.