SpineEventEngine / gcloud-java

Support for Spine-based Java apps running under Google Cloud
https://spine.io
Apache License 2.0
3 stars 0 forks source link

Update to 2.x #164

Closed armiol closed 3 years ago

armiol commented 3 years ago

This PR updates this library to the new Storage API introduced in Spine Server 2.0.

Here is a breakdown of the changes made.

Features

Support of new Query DSL

Support of new Query DSL introduced in Spine 2.0, including deep nesting of predicates.

Configuration-over-implementation:

Enabling transactions

It is now possible to select some record types which will be written and read transactionally:

DatastoreStorageFactory.newBuilder()
           // ...
           .enableTransactions(ProjectDetails.class)

Ancestor-child layout

For each type of stored records, it is now possible to configure an ancestor-child Entity Group. This may be handy to leverage additional consistency by running transactions for such Entity Groups.

While Datastore supports multiple level of parents, this changeset now introduces just a single level of nesting, which seems sufficient at this point.

Library users may achieve this by customizing a record layout:

DatastoreStorageFactory.newBuilder()
           // ...
           // Store each `InboxMessage` in an Entity Group under a `ShardIndex` parent:
           .organizeRecords(InboxMessage.class, new InboxStorageLayout())  

Custom storage implementation

Sometimes, it is required to customize how records of some particular type are stored. Previously, library users had to make several steps, including the creation of their own StorageFactory.

Now, it can be achieved as simple as this:

 DatastoreStorageFactory factory = DatastoreStorageFactory.newBuilder()
           // ...
           // Customize how `ProjectDetails` entity state is stored.
           .useEntityStorage(ProjectDetails.class, config -> myProjectionStorageWith(config))
           // ...
           // When dealing with plain Message records of `InboxMessage` type, use another custom storage.
           .useRecordStorage(InboxMessage.class, config -> myRecordStorageWith(config))

Defaults

By default, transactions are disabled for all storages except for DsShardedWorkRegistry.

Also, if not told otherwise, all records are stored in a flat manner (e.g., no ancestor-child nesting is applied).

BREAKING CHANGES

Combined, an ability to enable transactions and organize records into ancestor-child Entity Groups replace the DatastoreMode setting, which was previously available in the library. The idea here is to allow library users to decide whether they really need transactions and grouping in their particular instance of Datastore, rather than having a single switch.

Repackaging

Previously, the package structure was mostly flat, making the root package to over-inflate and collapse soon.

Therefore, in 2.x a major repackaging has been made. However, as to the public API, most of the major types such as DatastoreStorageFactory remained in place.

Along with the repackaging, lots of obsolete types were removed.

Other Changes

Gradle has been updated to 6.9. Build scripts were migrated to Kotlin DSL.

Client SDKs of Google Clould products were updated to their latests versions (sadly, with some conflicts among their dependencies, which was overcome by forcing the most recent versions).

The library version has been set to 2.0.0-SNAPSHOT.1.

codecov[bot] commented 3 years ago

Codecov Report

Merging #164 (16a43b3) into master (11d965d) will increase coverage by 87.14%. The diff coverage is 83.10%.

@@              Coverage Diff              @@
##             master     #164       +/-   ##
=============================================
+ Coverage          0   87.14%   +87.14%     
- Complexity        0      460      +460     
=============================================
  Files             0       74       +74     
  Lines             0     1742     +1742     
  Branches          0       81       +81     
=============================================
+ Hits              0     1518     +1518     
- Misses            0      194      +194     
- Partials          0       30       +30     
armiol commented 3 years ago

@alexander-yevsyukov @dmdashenkov I have either addressed (or replied to) your comments. Please feel free to take another look.