Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove is not supported for LazyList? #906

Closed
XilinJia opened this issue Aug 27, 2020 · 7 comments
Closed

remove is not supported for LazyList? #906

XilinJia opened this issue Aug 27, 2020 · 7 comments
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@XilinJia
Copy link

XilinJia commented Aug 27, 2020

Basic info (please complete the following information):

  • ObjectBox version (are you using the latest version?): [e.g. 2.7.0]
  • Reproducibility: [always]
  • Device: [e.g. Lenovo K5]
  • OS: [e.g. Android 6]

To Reproduce
Steps to reproduce the behavior:

List<Word> sList = wordBox.query().build().findLazy();
Word w = sList.get(0);
// do something
sList.remove(0);

Got an exception.

Had a peek in LazyList.java:

    @Override
    public E remove(int location) {
        throw new UnsupportedOperationException();
    }
@XilinJia XilinJia added the bug Something isn't working label Aug 27, 2020
@XilinJia
Copy link
Author

I need to update all records in an entity based on new information. The purpose I use LazyList and do the get and remove is to avoid loading my entire query. Now remove doesn't work, how can I avoid loading the entire entity?

@greenrobot-team
Copy link
Member

greenrobot-team commented Aug 31, 2020

LazyList is an unmodifiable list. See the class documentation. https://objectbox.io/docfiles/java/current/io/objectbox/query/LazyList.html

Entities can be removed using their Box by passing their ID or their instance.
https://docs.objectbox.io/getting-started#basic-box-operations

Edit: ok, maybe I misunderstood. Some other options:

  • Box.get(id) the entities and Box.put(entity),
  • just get all of them Box.getAll(), modify some of them, and Box.put(entities) them.

Note: Please ask usage questions on Stack Overflow.
https://stackoverflow.com/questions/tagged/objectbox

@greenrobot-team greenrobot-team added support / not an issue and removed bug Something isn't working labels Aug 31, 2020
@XilinJia
Copy link
Author

Thank you for responding.

The main point I want to understand is how to work with items one by one on the lazylist without having to load all the list items into memory at the same time. I was hoping to load one by get(0), work with it, then unload it with remove(0), then load in the next one. Now I understand that LazyList is unmodifiable, so I can't remove(0), is there a way to unload the record I loaded before loading in the next record?

@greenrobot
Copy link
Member

greenrobot commented Aug 31, 2020

No need to unload; findLazy() - unlike findLazyCached() - should not hold on to previously fetched objects.

@XilinJia
Copy link
Author

When I do myLazyList.get(0), don't I get the record loaded?

@greenrobot
Copy link
Member

You do. And LazyList does not keep a reference.

@greenrobot-team greenrobot-team self-assigned this Sep 1, 2020
@greenrobot-team
Copy link
Member

Updated JavaDoc in Query and LazyList will be available with the next update.

@greenrobot-team greenrobot-team added this to the 3.0 milestone Sep 15, 2020
@greenrobot-team greenrobot-team modified the milestones: 3.0, 2.8.0 Nov 2, 2020
@greenrobot-team greenrobot-team added documentation Improvements or additions to documentation and removed support / not an issue labels Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants