Git Product home page Git Product logo

aggregate-persistence-sample's Introduction

aggregate-persistence-sample

这是Aggregate-Persistence 的示例项目。

Aggregate-Persistence为DDD落地时,提供一种优雅的、轻量级聚合持久化方案。该方案简单易行,可以真正做到领域对象是干净的对象模型,只处理业务逻辑。而Repository持久化层完全与业务无关,只负责聚合的持久化。

本项目以订单聚合为例,演示了如何采用Aggregate-Persistence如何帮助简单聚合的持久化工作。项目采用SpringBoot和Mybatis框架。你可以从OrderControllerTest了解已经实现的功能,也可以直接到OrderRepository了解持久化具体细节。

aggregate-persistence-sample's People

Contributors

dependabot[bot] avatar meixuesong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

aggregate-persistence-sample's Issues

Aggregate变更字段与DO变更字段的映射

代码中只支持对Aggregate进行快照并比对变更字段,但在更新数据表时实际需要的是持久化对象(DO)的变更字段,如何映射?
例如:

// OrderRepository.java

    private void updateAggregateRoot(Aggregate<Order> orderAggregate) {
        //only update changed fields, avoid update all fields
        OrderDO newOrderDO = new OrderDO(orderAggregate.getRoot());
        // 这里获取到的是Aggregate Root的变更字段
        Set<String> changedFields = DataObjectUtils.getChangedFields(orderAggregate.getRootSnapshot(), orderAggregate.getRoot());
        // orderMapper实际需要的是持久化对象OrderDO的变更字段 
        if (orderMapper.updateByPrimaryKeySelective(newOrderDO, changedFields) != 1) { 
            throw new OptimisticLockException(String.format("Update order (%s) error, it's not found or changed by another user",
                    orderAggregate.getRoot().getId()));
        }
    }

以上逻辑只有在满足以下条件之一时才能正常工作:

  • 持久化对象DO与Aggregate的字段名称严格保持一致
  • OrderMapper的实现中维护了Aggregate与DO字段的映射关系

请问实际项目中,是采用了以上哪种方法?具体是如何实现的?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.