I suggest you ...

Create a container that can load lazily from sources

With huge datasets it is not good to load everything into the jvm at once. We need a container that can load lazily from various sources. I suggest that the container should take in an interface implementation telling it how to get more entries and telling it the size of the whole data set. getObjectById, sorting possibilities, filters etc would also be nice.

214 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Jens JanssonJens Jansson shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    9 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Noisy BoyNoisy Boy commented  ·   ·  Flag as inappropriate

        I was trying like this
        public void addCustomListener2(ILazyLoadingComboboxCallBack callBack, ValueChangeListener sheetChangedListener) {
        this.addFocusListener(event -> {
        if (!loaded) {
        showLoadingIcon();
        this.removeValueChangeListener(sheetChangedListener);
        try {
        List<String> dataList = callBack.loadComboBox();
        Object selectedValue = this.getValue();
        if (selectedValue != null && !dataList.contains(selectedValue)) {
        dataList.add(selectedValue.toString());
        }

        populateComboBox(dataList);
        this.select(selectedValue);
        loaded = true;
        } catch (Exception e) {
        LOGGER.debug("Exception while loading lazy combobox {}", e);
        }
        this.addValueChangeListener(sheetChangedListener);
        removeLoadingIcon();
        }
        });
        }

        It worked for me. I was showing the icon of loading inside combobox.
        Call can be converted to asynchronous.

      • GuillermoGuillermo commented  ·   ·  Flag as inappropriate

        I suppose Jens is talking about tables, since they are the only ones that can handle huge number of elements.

        As far as I know, they already do handle lazy loading. At least they do in my app. The problem in my case is that Hibernate is not able to handle huge number of elements without becoming incredibly slow. Even when twiked to perform lazy loading, the programming model changes so much that I desperately need Java 8 for having closures (aka lambdas) so that executions (functions) can be applied lazily.

        By the way I think that doing what Jens suggests is not that hard. Simply implement an interface LazyLoad that has 3 methods ( + one utilility method that could be implemented with a trait) :

        int numberOfItems() // returns the size of the full collection
        int numberOfItemsPerPage() // returns the size to be loaded at once
        void load(int begin, int end) // loads only those items in memory
        void load(int begin) { load( begin, begin + numberOfItemsPerPage() ); }

        And then it is already done.

        You only need the Table object to understand that protocol and load elements on demand.

      • walidwalid commented  ·   ·  Flag as inappropriate

        Ideally a container to do the fetch array, As the context is saved, the database query not fetched for all rows, but when the user scroll in the table, and the table need to fetch next rows from the app server, this event can be catched and the query rows fetched,

      • livotovlivotov commented  ·   ·  Flag as inappropriate

        SO probably we just need to rework the container interface to make it simplier for understanding and implementation for every particular need by the developer ?

      • Joonas LehtinenJoonas Lehtinen commented  ·   ·  Flag as inappropriate

        Designing an abstract lazy container that suits everyones needs is a tricky business. In theory Container interface itself is the thing you are requesting, but in practice it would be great if one would be have to implement all the methods. The crucial question is - which methods should be left for the developer to implement?

        All concept prototypes are welcome!

        Fully functioning implementations are even better :)

      • Henrik PaulHenrik Paul commented  ·   ·  Flag as inappropriate

        I disagree. I think it should be up to the implementation of the 'streamer' to decide which interfaces it wants to implement.

      • Kim LKim L commented  ·   ·  Flag as inappropriate

        This container would need to implement Container.Sortable, Container.Indexed and Container.Filterable for it to actually be usefull

      Feedback and Knowledge Base