欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

event-sourcing-cqrs的model有哪些

這篇文章主要介紹“event-sourcing-cqrs的model有哪些”,在日常操作中,相信很多人在event-sourcing-cqrs的model有哪些問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”event-sourcing-cqrs的model有哪些”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

創(chuàng)新互聯(lián)建站從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元石拐做網(wǎng)站,已為上家服務(wù),為石拐各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220

Event

public abstract class Event {

  private final UUID aggregateId;
  private final ZonedDateTime timestamp;
  private final int version;

  protected Event(UUID aggregateId, ZonedDateTime timestamp, int version) {
    this.aggregateId = checkNotNull(aggregateId);
    this.timestamp = checkNotNull(timestamp);
    this.version = version;
  }

  public UUID getAggregateId() {
    return aggregateId;
  }

  public ZonedDateTime getTimestamp() {
    return this.timestamp;
  }

  public int getVersion() {
    return version;
  }
}

Event定義了aggregateId、timestamp、version屬性

EventStore

public interface EventStore {

  void store(UUID aggregateId, List<Event> newEvents, int baseVersion)
      throws OptimisticLockingException;

  List<Event> load(UUID aggregateId);

}

EventStore接口定義了store、load方法

Aggregate

public abstract class Aggregate {

  private UUID id;
  private int baseVersion;
  private List<Event> newEvents;

  protected Aggregate(UUID id) {
    this(id, emptyList());
  }

  protected Aggregate(UUID id, List<Event> eventStream) {
    checkNotNull(id);
    checkNotNull(eventStream);
    this.id = id;
    eventStream.forEach(e -> {
      apply(e);
      this.baseVersion = e.getVersion();
    });
    this.newEvents = new ArrayList<>();
  }

  protected void applyNewEvent(Event event) {
    checkArgument(event.getVersion() == getNextVersion(),
        "New event version '%s' does not match expected next version '%s'",
        event.getVersion(), getNextVersion());
    apply(event);
    newEvents.add(event);
  }

  private void apply(Event event) {
    try {
      Method method = this.getClass().getDeclaredMethod("apply", event.getClass());
      method.setAccessible(true);
      method.invoke(this, event);
    } catch (InvocationTargetException e) {
      Throwables.propagate(e.getCause());
    } catch (NoSuchMethodException | IllegalAccessException e) {
      throw new UnsupportedOperationException(
          format("Aggregate '%s' doesn't apply event type '%s'", this.getClass(), event.getClass()),
          e);
    }
  }

  public UUID getId() {
    return id;
  }

  public int getBaseVersion() {
    return baseVersion;
  }

  public List<Event> getNewEvents() {
    return ImmutableList.copyOf(newEvents);
  }

  protected int getNextVersion() {
    return baseVersion + newEvents.size() + 1;
  }
}

Aggregate定義了id、baseVersion、newEvents屬性;其applyNewEvent方法會(huì)執(zhí)行apply(event)及newEvents.add(event);apply方法通過反射執(zhí)行event的apply方法

ValueObject

public abstract class ValueObject {

  @Override
  public boolean equals(Object o) {
    return EqualsBuilder.reflectionEquals(this, o);
  }

  @Override
  public int hashCode() {
    return HashCodeBuilder.reflectionHashCode(this);
  }

  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
  }
}

ValueObject覆蓋了equals、hashCode、toString方法

Specification

public interface Specification<T> {

  boolean isSatisfiedBy(T value);

}

Specification接口定義了isSatisfiedBy方法

到此,關(guān)于“event-sourcing-cqrs的model有哪些”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

網(wǎng)頁標(biāo)題:event-sourcing-cqrs的model有哪些
網(wǎng)站地址:http://chinadenli.net/article16/gisodg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、電子商務(wù)、網(wǎng)站制作、小程序開發(fā)、外貿(mào)建站、

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)