meixuesong / aggregate-persistence Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
聚合根Order中包含OrderItem如果在一个Request中去删除某一个聚合根Order里的OrderItem,是不是得先把聚合根Order全部从数据库里取出来然后和Request里的OrderItem进行对比然后找出删除的数据再去Order里删除对应的OrderItem。
假设这样一个场景:
如果一个 usercase 要求把 a1 的 b1 和 a2 的 b3 进行交换,如何处理呢?
此时 b1、b3 并没有被删除,而是更换了所属聚合根
在系统初始设计时,可以通过 A、B 都是聚合根的方式,来规避此问题。
但功能是不断演变的,假如一开始为了高内聚把 B 作为 A 的实体,产品提出交换 B 的需求,产品会认为很简单,一个 update 就可以了,但在 DDD 场景下就很复杂。
在创建聚合根时,将verison 设置成了Versionable.NEW_VERSION
也就是0,然后在仓储的save()方法中通过verison判断该聚合根是不是新的,以执行insert或者update。
对于乐观锁而言,在update的时候更新它的值为version + 1
也是很正常的操作。
我看了simple中Order的insert,是直接将verison设置成了1, 这里就觉得特别的别捏。个人认为isNew()
不应该直接用乐观锁的值来判断,但是又没有想到其他的办法,不知道作者有没有其他的想法。
<insert id="insert" parameterType="com.github.meixuesong.order.dao.OrderDO">
insert into sale_order (id, create_time, customer_id,
total_price, total_payment, status, version
)
values (#{id,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{customerId,jdbcType=VARCHAR},
#{totalPrice,jdbcType=DECIMAL}, #{totalPayment,jdbcType=DECIMAL}, #{status,jdbcType=TINYINT}, 1
)
</insert>
感谢,之前还想自己实现呢!
请问这有在生产用过吗?
另外, 聚合根需要实现Versionable
, 然后实现getVerison()
方法.
看了simple,对于这个verison没有看懂,需要手动更新它的值以及需要持久化它吗?
比如例子中的OrderItem中有一个List 这样子可以找出它的差异吗
对于一个聚合根A包含聚合根B,聚合根B包含实体C,更新C中的某条数据,该如何操作?
传统方法:给定参数1( B和C的标识id),给定参数2(C的数据),根据参数1和参数2更新该条数据。
如何采用更新聚合根的方法,是不是过于复杂了?
如果构造一个聚合根对象A,只包含各级实体的id(聚合根B ID), 以及最后一级实体的 数据和标识ID(实体C), 更新该对象 的方法是否可行?而不是更新整个“聚合根A”
你好!
如果一个 用户 聚合根里包含一个 地址 实体. 对应数据表是 用户表和地址表.
如果地址实体发生变更. 这种场景如何只单独更新地址数据表,而不更新用户表呢
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.