Spring-Data-JPA Observable "findAll"-Results

50 Views Asked by At

The CrudRepository.findAll(Specification<EntityType>) method returns a "snapshot" kind of result List of entities that represents the resultset of the given query by the time the findAll method was executed (roughly speaking). However assuming, I'd like to write a collaborative note-taking app where multiple users can simultaneously create/edit/delete notes while being presented a list of old and recent notes that match customizable filter criteria. A newly created (or modified) note would pop up in every clients/users list if it matches their filter criteria. Upon deletion or modification, a note could disappear respectively. (I guess you get the point.)

So what I'd like to achieve is, in more general terms, an extended version of findAll(spec) that returns an observable list / observable set that gets updated upon creation, removal or update of entities (of the type it holds). A beefed-up version of findAll(spec) that keeps its result set/list updated upon future changes would be a different way to put it.

As a backend, I'd like to use a RDBMS like MYSQL or Postgres, etc. Relevant for those updates would be only data manipulations achieved through Spring/JPA's EntityManager instance that handles the CrudRepository the findAll operation was performed on.

Question #1: Is this kind of functionality already provided by JPA, Spring Data, or some other library or framework? (Which one?/How to use it?)

Question #2: If I were to implement it myself by using EntityListeners etc. I need to also be able to match entity instances to a given Specification or Predicate. Does JPA support matching entities against Specifications? How is it done?

0

There are 0 best solutions below