Skip to content

remove is not supported for LazyList? #906

Closed

Description

@XilinJia

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();
    }

Activity

  1. XilinJia commented on Aug 28, 2020

    @XilinJia
    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?

  2. greenrobot-team commented on Aug 31, 2020

    @greenrobot-team
    Member

    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

  3. XilinJia commented on Aug 31, 2020

    @XilinJia
    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?

  4. greenrobot commented on Aug 31, 2020

    @greenrobot
    Member

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

  5. XilinJia commented on Aug 31, 2020

    @XilinJia
    Author

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

  6. greenrobot commented on Aug 31, 2020

    @greenrobot
    Member

    You do. And LazyList does not keep a reference.

  7. greenrobot-team commented on Sep 15, 2020

    @greenrobot-team
    Member

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

  8. added this to the 3.0 milestone on Sep 15, 2020
  9. modified the milestones: 3.0, 2.8.0 on Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions