@Override protected void doSaveWithLock(EventSourcedAggregate<T> aggregate) { super.doSaveWithLock(aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); }
Object cachedItem = cache.get(aggregateIdentifier); if (AggregateCacheEntry.class.isInstance(cachedItem)) { EventSourcedAggregate<T> cachedAggregate = ((AggregateCacheEntry<T>) cachedItem).recreateAggregate( model, eventStore, repositoryProvider, snapshotTriggerDefinition ); cache.put(aggregateIdentifier, new AggregateCacheEntry<>(aggregateRoot));
public EventSourcedAggregate<T> recreateAggregate(AggregateModel<T> model, EventStore eventStore, SnapshotTriggerDefinition snapshotTriggerDefinition) { return recreateAggregate(model, eventStore, null, snapshotTriggerDefinition); }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. If the aggregate is * available in the cache, it is returned from there. Otherwise the underlying persistence logic is called to * retrieve the aggregate. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the aggregate * @return the fully initialized aggregate */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { EventSourcedAggregate<T> aggregate = null; AggregateCacheEntry<T> cacheEntry = cache.get(aggregateIdentifier); if (cacheEntry != null) { aggregate = cacheEntry.recreateAggregate(aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition); } if (aggregate == null) { aggregate = super.doLoadWithLock(aggregateIdentifier, expectedVersion); } else if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; } }
@Override protected void doDeleteWithLock(EventSourcedAggregate<T> aggregate) { super.doDeleteWithLock(aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); }
Object cachedItem = cache.get(aggregateIdentifier); if (AggregateCacheEntry.class.isInstance(cachedItem)) { EventSourcedAggregate<T> cachedAggregate = ((AggregateCacheEntry<T>) cachedItem).recreateAggregate( model, eventStore, repositoryProvider, snapshotTriggerDefinition ); cache.put(aggregateIdentifier, new AggregateCacheEntry<>(aggregateRoot));
public EventSourcedAggregate<T> recreateAggregate(AggregateModel<T> model, EventStore eventStore, SnapshotTriggerDefinition snapshotTriggerDefinition) { return recreateAggregate(model, eventStore, null, snapshotTriggerDefinition); }
@Override protected EventSourcedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception { EventSourcedAggregate<T> aggregate = super.doCreateNewForLock(factoryMethod); CurrentUnitOfWork.get().onRollback(u -> cache.remove(aggregate.identifierAsString())); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); return aggregate; }
Object cachedItem = cache.get(aggregateIdentifier); if (AggregateCacheEntry.class.isInstance(cachedItem)) { EventSourcedAggregate<T> cachedAggregate = ((AggregateCacheEntry<T>) cachedItem).recreateAggregate( model, eventStore, repositoryProvider, snapshotTriggerDefinition ); cache.put(aggregateIdentifier, new AggregateCacheEntry<>(aggregateRoot));
public EventSourcedAggregate<T> recreateAggregate(AggregateModel<T> model, EventStore eventStore, SnapshotTriggerDefinition snapshotTriggerDefinition) { return recreateAggregate(model, eventStore, null, snapshotTriggerDefinition); }
@Override public Aggregate<T> newInstance(Callable<T> factoryMethod) throws Exception { SnapshotTrigger trigger = snapshotTriggerDefinition.prepareTrigger(aggregateFactory.getAggregateType()); EventSourcedAggregate<T> aggregate = EventSourcedAggregate.initialize(factoryMethod, model, eventStore, repositoryProvider, trigger); firstLevelCache.put(aggregate.identifierAsString(), aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); return aggregate; }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. If the aggregate is * available in the cache, it is returned from there. Otherwise the underlying persistence logic is called to * retrieve the aggregate. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the aggregate * @return the fully initialized aggregate */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { EventSourcedAggregate<T> aggregate = null; AggregateCacheEntry<T> cacheEntry = cache.get(aggregateIdentifier); if (cacheEntry != null) { aggregate = cacheEntry.recreateAggregate(aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition); } if (aggregate == null) { aggregate = super.doLoadWithLock(aggregateIdentifier, expectedVersion); } else if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; }
@Override protected void doSaveWithLock(EventSourcedAggregate<T> aggregate) { super.doSaveWithLock(aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. If the aggregate is * available in the cache, it is returned from there. Otherwise the underlying persistence logic is called to * retrieve the aggregate. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the aggregate * @return the fully initialized aggregate */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { EventSourcedAggregate<T> aggregate = null; AggregateCacheEntry<T> cacheEntry = cache.get(aggregateIdentifier); if (cacheEntry != null) { aggregate = cacheEntry.recreateAggregate(aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition); } if (aggregate == null) { aggregate = super.doLoadWithLock(aggregateIdentifier, expectedVersion); } else if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; } }
@Override protected void doSaveWithLock(EventSourcedAggregate<T> aggregate) { super.doSaveWithLock(aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); }
@Override protected void doDeleteWithLock(EventSourcedAggregate<T> aggregate) { super.doDeleteWithLock(aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); }
@Override protected void doDeleteWithLock(EventSourcedAggregate<T> aggregate) { super.doDeleteWithLock(aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); }
@Override public Aggregate<T> newInstance(Callable<T> factoryMethod) throws Exception { SnapshotTrigger trigger = snapshotTriggerDefinition.prepareTrigger(aggregateFactory.getAggregateType()); EventSourcedAggregate<T> aggregate = EventSourcedAggregate.initialize(factoryMethod, model, eventStore, repositoryProvider, trigger); firstLevelCache.put(aggregate.identifierAsString(), aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); return aggregate; }
@Override protected EventSourcedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception { EventSourcedAggregate<T> aggregate = super.doCreateNewForLock(factoryMethod); CurrentUnitOfWork.get().onRollback(u -> cache.remove(aggregate.identifierAsString())); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); return aggregate; }
@Override protected EventSourcedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception { EventSourcedAggregate<T> aggregate = super.doCreateNewForLock(factoryMethod); CurrentUnitOfWork.get().onRollback(u -> cache.remove(aggregate.identifierAsString())); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); return aggregate; }