This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
WIP-CRUD on top of Event Sourcing #220
Merged
pvlugter
merged 129 commits into
cloudstateio:master
from
ralphlaude:wip-crud-on-top-of-event-sourcing
Nov 12, 2020
Merged
Changes from 9 commits
Commits
Show all changes
129 commits
Select commit
Hold shift + click to select a range
6d3b2c1
Issue-197: add npm task for preparing node-support to be able to buil…
ralphlaude 0fbd706
Merge remote-tracking branch 'upstream/master'
ralphlaude 27d22ff
Merge remote-tracking branch 'upstream/master'
ralphlaude 2a32aa1
Merge remote-tracking branch 'upstream/master'
ralphlaude 579d1c4
Merge remote-tracking branch 'upstream/master'
ralphlaude 8014961
Merge remote-tracking branch 'upstream/master'
ralphlaude 91f3333
Merge remote-tracking branch 'upstream/master'
ralphlaude 38327d3
Proposal for CRUD on top of Event Sourcing
ralphlaude 6cc25fe
Proposal for CRUD on top of Event Sourcing; Comment code handling events
ralphlaude 9a7a8bf
rollback changes in the proxy and add proto file for the CRUD domain
ralphlaude db2e4a8
Add CrudEntity annotation. Add registration for CrudEntity in CloudSt…
ralphlaude 8aa1e97
Merge remote-tracking branch 'upstream/master'
ralphlaude 2374b7b
change CrudEntity annotation. Change registration for CrudEntity in C…
ralphlaude 82c2377
Merge remote-tracking branch 'upstream/master'
ralphlaude 1f741d9
Merge remote-tracking branch 'upstream/master'
ralphlaude ca6b416
Merge remote-tracking branch 'upstream/master'
ralphlaude 92effcd
Merge remote-tracking branch 'upstream/master'
ralphlaude 473d682
Merge remote-tracking branch 'upstream/master'
ralphlaude 6e23140
Merge remote-tracking branch 'upstream/master'
ralphlaude 3664944
Merge remote-tracking branch 'upstream/master'
ralphlaude c9cc5f6
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude cee69f1
Merge remote-tracking branch 'upstream/master'
ralphlaude 8e951e4
Merge remote-tracking branch 'upstream/master'
ralphlaude 170bb0c
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude 78b7840
Initial version for the CRUD protocol and the implementation
ralphlaude 012c1e3
remove unused import
ralphlaude 5647e15
Merge remote-tracking branch 'upstream/master'
ralphlaude dc810c4
Add comments and change the proto definition
ralphlaude 078517f
Change the protocol to have one reply type for all operations and imp…
ralphlaude 5e8ec79
Merge remote-tracking branch 'upstream/master'
ralphlaude da4a331
add crud command type as proto field option and extend the user funct…
ralphlaude 78345f8
add some documentation and do some small refactoring
ralphlaude d1bdbb1
add java doc for crud protocol. extend the shopping cart example. ref…
ralphlaude d9a5dbd
Merge remote-tracking branch 'upstream/master'
ralphlaude ab73109
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude e906657
Merge branch 'prototype-crud-on-event-sourcing' into wip-crud-on-top-…
ralphlaude 344d8d9
Documents the protocol and add new grpc type for command type. implem…
ralphlaude cda633a
Merge branch 'prototype-crud-on-event-sourcing' into wip-crud-on-top-…
ralphlaude 87d1c4f
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude d0215aa
Provide a definition of the protocol with snapshotting capabilities a…
ralphlaude 9f72587
wording fixed
ralphlaude 866941d
add sample for crud shopping cart and rollback the sample shopping ca…
ralphlaude 6e997f2
remove old crud shopping cart
ralphlaude 9c9e02b
add StreamFailed in the presstart method
ralphlaude 164a650
add tests for crud entity
ralphlaude 9a3cf53
removed obsolete classes
ralphlaude c5de37d
add annotations for update and delete handlers
ralphlaude 0979a9e
fixed scala format
ralphlaude 5169003
fixed unit value
ralphlaude b93a3c0
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude 1321d1e
fixed protobuf attribute index and fixed crud init state handling
ralphlaude c6e162a
fixed shopping cart entity
ralphlaude 0675b17
call command handler only when the command was successful. Make the C…
ralphlaude 1fd017d
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude 928933c
fixed test
ralphlaude 2310fc9
add native CRUD support with slick and integrate the in memory CRUD s…
ralphlaude 919756d
modified markdown
ralphlaude dd2e4c8
add generic to command context and entity handler
ralphlaude bbd5e53
remove the use of sequence number in the GRPC CRUD protocol
ralphlaude 99f8ffc
remove event sourced in memory snapshot store. adapt log for in memor…
ralphlaude 8692f57
first version for checking null on updateEntity
ralphlaude 18ce9c8
add comments
ralphlaude 209648d
add exception handling based on the one in event sourced
ralphlaude 44175e0
add new lines
ralphlaude b866e71
rewrite crud protocol by using oly command handler and passing the st…
ralphlaude 2731570
change entity initialization
ralphlaude 46b54fc
change entity initialization and adapt annotation based support test
ralphlaude 7ec4ab5
change test name
ralphlaude d076e86
ignore CRUD entity test
ralphlaude b05f7aa
remove subsequent invocation checking which is not needed
ralphlaude 11135d7
adapt the init case for the entity
ralphlaude cb282ad
deal with empty schema in the config
ralphlaude 863dfe3
add comment for already initialized entity
ralphlaude e511b4b
integrate native crud support in postgres module
ralphlaude 3bc45a0
save CRUD state as byte array
ralphlaude 93a5962
fixed map on slick dbioaction
ralphlaude dd19ed1
change actor name
ralphlaude e84d4e6
add infra for CRUD tests in testkit. add exception handling test for …
ralphlaude 6243e4d
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude 624afbf
fixed conflicts and compile errors when merging master
ralphlaude 968c332
fixed format error
ralphlaude 29cdd47
add test for the crud java support
ralphlaude 5cf66b7
remove comments and logs
ralphlaude bb98d71
changed java 11 for crud sample and fixed conflicting package name
ralphlaude 6a2cd86
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude 8acd3c9
remove concurrency enforcer
ralphlaude 5a97b74
disabled CRUD native support for now
ralphlaude 1b163b3
Add CRUD to expected protocols in TCK
pvlugter 821fd4c
Add default value for cloudstate.proxy.postgres.schema setting
pvlugter 5d9a193
enabled CRUD for the proxy and add readiness-checks
ralphlaude 0248e53
add hikari connection pool properties
ralphlaude d8f2e9f
fixed protobuf any deserialization
ralphlaude 4c90c02
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude 353b41c
add TCK test for CRUD initial version
ralphlaude 47f7cd3
add TCK test for CRUD and refactoring jdbc store factory
ralphlaude 735257c
Merge remote-tracking branch 'origin/wip-crud-on-top-of-event-sourcin…
ralphlaude e7ae59c
removed class
ralphlaude 41f189a
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude 3f9789e
add metadata
ralphlaude eac2e7f
add table creation readiness in native image
ralphlaude 35e0005
rename CRUD to Value Entity
ralphlaude f820f7f
rename CRUD to Value Entity
ralphlaude f21b7d0
rename CRUD to Value Entity follow up (crud jdbc configuration to val…
ralphlaude f65553c
add entity exceptions factory class. extract grpc entity message crea…
ralphlaude dd30efb
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude 517ee37
integrate tests for entity in circleci
ralphlaude d4b2493
integrate tests for entity in circleci by building the entity image
ralphlaude a6bc7d9
integrate tests for entity in circleci by saving the entity image in …
ralphlaude 375f9f9
add jdbc config tests
ralphlaude a578d6b
Merge branch 'master' into pr/220
pvlugter 87dbd80
Update entity smoke test script
pvlugter 65e5fc8
Fix entity delete in smoke test script
pvlugter 2f6ba27
Add native-image configuration for value entity table
pvlugter 8f1835a
Reduce value entity connection pool size
pvlugter 62f0500
exclude slick dependency from other core persistence module.
ralphlaude f7e27aa
renaming value entity to entity in the java support, the proxy, the t…
ralphlaude a2bf57c
fixed native image configuration for value entity
ralphlaude 469edab
write test for properly accessing the state after passivation
ralphlaude 403aed0
fixed grammar
ralphlaude 10c931e
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude c915048
merge master and refactoring
ralphlaude 5bf6a12
combined readiness checks for eventsourced and value entity
ralphlaude 937084e
fixed readiness check
ralphlaude 5545e6d
removed dedicated readiness check for value entity
ralphlaude 5856394
fixed grammar, remove left crud names and fixed code
ralphlaude 427b538
Merge branch 'master' into pr/220
pvlugter 18cde26
Dynamically create value entity stores
pvlugter dc786ca
adapt the store-api to able to persist the tpye url of the entity
ralphlaude 340325d
add comment for explaining duplicate shoppingcart.proto
ralphlaude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...hopping-cart/src/main/java/io/cloudstate/samples/shoppingcart/ShoppingCartCrudEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package io.cloudstate.samples.shoppingcart; | ||
|
||
import com.example.shoppingcart.Shoppingcart; | ||
import com.example.shoppingcart.persistence.Domain; | ||
import com.google.protobuf.Empty; | ||
import io.cloudstate.javasupport.EntityId; | ||
import io.cloudstate.javasupport.eventsourced.CommandContext; | ||
import io.cloudstate.javasupport.eventsourced.CommandHandler; | ||
import io.cloudstate.javasupport.eventsourced.EventSourcedEntity; | ||
import io.cloudstate.javasupport.eventsourced.Snapshot; | ||
import io.cloudstate.javasupport.eventsourced.SnapshotHandler; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** An event sourced entity. */ | ||
@EventSourcedEntity(snapshotEvery = 1) | ||
public class ShoppingCartCrudEntity { | ||
private final String entityId; | ||
private final Map<String, Shoppingcart.LineItem> cart = new LinkedHashMap<>(); | ||
|
||
public ShoppingCartCrudEntity(@EntityId String entityId) { | ||
this.entityId = entityId; | ||
} | ||
|
||
@Snapshot | ||
public Domain.Cart snapshot() { | ||
return Domain.Cart.newBuilder() | ||
.addAllItems(cart.values().stream().map(this::convert).collect(Collectors.toList())) | ||
.build(); | ||
} | ||
|
||
@SnapshotHandler | ||
public void handleSnapshot(Domain.Cart cart) { | ||
this.cart.clear(); | ||
for (Domain.LineItem item : cart.getItemsList()) { | ||
this.cart.put(item.getProductId(), convert(item)); | ||
} | ||
} | ||
|
||
@CommandHandler | ||
public Shoppingcart.Cart getCart() { | ||
return Shoppingcart.Cart.newBuilder().addAllItems(cart.values()).build(); | ||
} | ||
|
||
@CommandHandler | ||
public Empty addItem(Shoppingcart.AddLineItem item, CommandContext ctx) { | ||
if (item.getQuantity() <= 0) { | ||
ctx.fail("Cannot add negative quantity of to lineItem" + item.getProductId()); | ||
} | ||
|
||
Domain.LineItem lineItem = | ||
Domain.LineItem.newBuilder() | ||
.setProductId(item.getProductId()) | ||
.setName(item.getName()) | ||
.setQuantity(quantity(item)) | ||
.build(); | ||
|
||
List<Domain.LineItem> lineItems = | ||
cart.values().stream() | ||
.map(this::convert) | ||
.filter(someItem -> !someItem.getProductId().equals(item.getProductId())) | ||
.collect(Collectors.toList()); | ||
|
||
ctx.emit(Domain.Cart.newBuilder().addAllItems(lineItems).addItems(lineItem).build()); | ||
return Empty.getDefaultInstance(); | ||
} | ||
|
||
@CommandHandler | ||
public Empty removeItem(Shoppingcart.RemoveLineItem item, CommandContext ctx) { | ||
if (!cart.containsKey(item.getProductId())) { | ||
ctx.fail("Cannot remove item " + item.getProductId() + " because it is not in the cart."); | ||
} | ||
|
||
List<Domain.LineItem> lineItems = | ||
cart.values().stream() | ||
.map(this::convert) | ||
.filter(someItem -> someItem.getProductId().equals(item.getProductId())) | ||
.collect(Collectors.toList()); | ||
|
||
ctx.emit(Domain.Cart.newBuilder().addAllItems(lineItems).build()); | ||
return Empty.getDefaultInstance(); | ||
} | ||
|
||
private Shoppingcart.LineItem convert(Domain.LineItem item) { | ||
return Shoppingcart.LineItem.newBuilder() | ||
.setProductId(item.getProductId()) | ||
.setName(item.getName()) | ||
.setQuantity(item.getQuantity()) | ||
.build(); | ||
} | ||
|
||
private Domain.LineItem convert(Shoppingcart.LineItem item) { | ||
return Domain.LineItem.newBuilder() | ||
.setProductId(item.getProductId()) | ||
.setName(item.getName()) | ||
.setQuantity(item.getQuantity()) | ||
.build(); | ||
} | ||
|
||
private int quantity(Shoppingcart.AddLineItem item) { | ||
Shoppingcart.LineItem lineItem = cart.get(item.getProductId()); | ||
return lineItem == null ? item.getQuantity() : lineItem.getQuantity() + item.getQuantity(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you want to do this? (esp. for all EventSourcedEntities?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@viktorklang I did it this way just to show how it should work for the the eventually new CrudEntity. I would like to have an one to one mapping between snapshot and event. in this case snapshot and event are almost the same.