ydb-platform / yoj-project

YDB ORM for Java (YOJ) is a lightweight ORM for immutable entities. It has native support for YDB and is battle-tested.
Apache License 2.0
13 stars 12 forks source link

Move projections to separate module #77

Open lavrukov opened 5 months ago

lavrukov commented 5 months ago

The projection feature was originally not designed very well and has a number of issues:

Where we want to go:

How the migration process will look:

  1. First, implement the new MigrationProjectionsCache, which immediately calls the methods table.{save,delete} without waiting for a commit.
  2. Initially, enable it without a flag and run tests for all projects, ensuring they are green.
  3. Then, leave the feature under a flag and release the service, ensuring that the service also works.
  4. Add a method withoutProjections() to the table that sets a property indicating that projections should not be processed.
  5. Remove ProjectionCache, leaving the logic from MigrationProjectionsCache directly in the Table methods under the withoutProjections flag.
  6. Create a ProjectionsTable proxy that accepts Table<E> in the constructor and sets withoutProjections() on the proxied object.
  7. In ProjectionsTable, override only the insert, save, and delete methods with the projection logic and new error handling.
  8. In the Entity class with the base implementation of createProjections, throw a special CreateProjectionNotOverridedException.
  9. In Table, catch the exception and if withoutProjections is set, fail; otherwise, log an error with a requirement to migrate to the new logic.
  10. After all services migrated remove logic from table, withoutProjections flag and method and move all projection code to separate module

TODO: think how to protect services which can call tx.table(MyEntityWithProjections.class).{insert,save,delete} directly