micronaut-projects / micronaut-projects/micronaut-data
Support change notification
- Dominant language
- Java
- Stars
- 482
- Forks
- 229
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 32
Description
### Feature description
Some databases can inform clients when the results of a query have changed. Oracle is an example of one such database, but there are others. Currently utilizing this feature requires manually working with JDBC and giving up the benefits of Micronaut Data.
https://docs.oracle.com/en/database/oracle/oracle-database/19/jjdbc/continuos-query-notification.html#GUID-8A2BF5CA-CB76-4D88-B467-4A2AE63D89D4
It would be nice to have an integrated support for this. Behind the scenes using the feature is very simple:
1. Create a "registration" object using `OracleConnection.registerDatabaseChangeNotification(properties)` being careful to let the user set the `OracleConnection.DCN_CLIENT_INIT_CONNECTION` property to true as otherwise the DB will try and dial back the client over TCP when there's a notification - efficient, but not compatible with firewall or NATd networks as found in e.g. containers.
2. Add one or more listener/callback objects to the registration.
3. Set the registration object on the `OracleStatement` or `OraclePreparedStatement` object.
4. Do some queries.
5. You can now close the connections and so on, and the driver will call you back on its own thread when the rows that the queries read have changed.
From an integration perspective, it probably makes sense to allow ordinary query methods to be passed an `org.reactivestreams.Subscriber` or `java.util.concurrent.Flow.Subscriber` object. It doesn't make sense to add a new magic name variant like `findAllAndWatch` because you generally want the results of the query you do in any case. Then:
```java
interface MyRepo {
String findFoo(@Id String id, Subscriber changes)
}
```
would work fine as then you can just implement the interface and the `onNext` method to get a stream of values of the FOO column as it changes for that id. The `Subscription` object passed to `Subscriber.onSubscribe` can then be used to cancel the registration.
Contributor guide
Research direction
No repository files or tests are identified. Start by reviewing the repository query-method integration and the OracleConnection, OracleStatement, and Subscriber APIs described in the issue. Done should include a defined change-notification interface, cancellation behavior, and support for the stated Oracle connection property.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, sql
- Domain
- backend-api-design, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100