-1

I wish to have a queryable on-heap mirror of some underlying resource. When using CQEngine to index a class not under our control (*), how can we implement a transactional update (what's the point of all this concurrency if readers lose data because of the remove+add semantics!).

(*) TransactionalIndexedCollection insists on mauling the type's equals method so that equivalent objects are no longer equals()!

Also, the provided equals method covers "all fields" not "pk fields" so causes duplicates. How do I create an atomically updateable collection with my own PK?

drekbour
  • 2,895
  • 18
  • 28

1 Answers1

0

If you want to use TransactionalIndexedCollection for atomic updates, you will have to follow its guidance on how to implement equals() and hashCode() on the objects you will store in it.

However, you don't need to store the objects you don't control directly in the indexed collection. For example you could write a wrapper object which you will store in the collection - and this will implement equals() and hashCode() per the guidance. This way you won't need to modify the objects you don't control.

You can write your attributes so that given a wrapper object, they actually read the fields or call the getter methods from the inner object.

Dharman
  • 30,962
  • 25
  • 85
  • 135
npgall
  • 2,979
  • 1
  • 24
  • 24
  • Hi. I have read and experimented quite a lot before posting and do respect it's all well documented what it does and doesn't do. Thought SO might get your attention (-1 :)) ! I didn't go with the wrapper object as it feels like exactly the kind of work CQE should have taken off my hands. I have dozens of very wide and changeable objects that would need wrapping (proxying?) so this doesn't feel scalable or supportable. I'm currently using a StampedLock to totally redo queries if an update (not solo add() or remove()) occurs. – drekbour Nov 19 '20 at 20:15