objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

Support observing multiple boxes

Open FabianTerhorst opened this issue 7 years ago • 8 comments

Maybe support an store.boxFor(Class[]).query()?

FabianTerhorst avatar Mar 16 '17 12:03 FabianTerhorst

You can use one of the BoxStore.subscribe() methods to achieve that. Does that work for you?

greenrobot avatar Apr 05 '17 10:04 greenrobot

Does the method only triggers one time after an transaction with multiple types involved?

FabianTerhorst avatar Apr 05 '17 10:04 FabianTerhorst

No, it invokes per Class passing the Class as an parameter.

greenrobot avatar Apr 05 '17 10:04 greenrobot

Ok, what would be the best practice to get all objects from 3 boxes?

FabianTerhorst avatar Apr 05 '17 11:04 FabianTerhorst

@FabianTerhorst Getting all objects (box.getAll()) or getting notifications? The latter would involve BoxStore.subscribe() and check the class in the callback. The callback is called 3 times for three boxes. If you want just a single call being made, we may consider an additional method to be implemented. In that case it would help to see the use case. If that may be useful for other users, we will consider it.

greenrobot avatar Apr 06 '17 07:04 greenrobot

@greenrobot i have a list of objects inside an recyclerview, the list is containing 3 different types of objects.

FabianTerhorst avatar Apr 06 '17 07:04 FabianTerhorst

Thinking about changing the callback to receive a list of changed entity classes...

greenrobot avatar Apr 06 '17 18:04 greenrobot

If you have an entity with a list of other entities, shouldnt the other entities changing also trigger the parents change?

E.g.:

  1. ExerciseEntity has a list of BodypartEntity
  2. A BodypartEntity changes
  3. BodypartEntity gets notified, but not ExerciseEntity

I understand that this makes it far more complex, but a hint on whether you are planning to incorporate it or not would be great!

zoltish avatar Mar 29 '18 07:03 zoltish