@Test @DirtiesContext void testLoadSaga_AssociationValueRemoved() { String identifier = unitOfWork.executeWithResult(() -> { Saga<StubSaga> saga = repository.createInstance(IdentifierFactory.getInstance().generateIdentifier(), StubSaga::new); saga.execute(s -> s.associate("key", "value")); return saga.getSagaIdentifier(); }).getPayload(); entityManager.clear(); startUnitOfWork(); unitOfWork.execute(() -> { Saga<StubSaga> loaded = repository.load(identifier); loaded.execute(s -> s.removeAssociationValue("key", "value")); }); entityManager.clear(); startUnitOfWork(); Set<String> found = unitOfWork.executeWithResult(() -> repository.find(new AssociationValue("key", "value"))) .getPayload(); assertEquals(0, found.size()); }
protected void removeAssociationValue(EntityManager entityManager, Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { int updateCount = entityManager.createNamedQuery(DELETE_ASSOCIATION_NAMED_QUERY) .setParameter("associationKey", associationValue.getKey()) .setParameter("associationValue", associationValue.getValue()) .setParameter("sagaType", getSagaTypeName(sagaType)) .setParameter("sagaId", sagaIdentifier) .executeUpdate(); if (updateCount == 0 && logger.isWarnEnabled()) { logger.warn("Wanted to remove association value, but it was already gone: sagaId= {}, key={}, value={}", sagaIdentifier, associationValue.getKey(), associationValue.getValue()); } }
JpaSagaStore implements SagaStore<Object> { protected void removeAssociationValue(EntityManager entityManager, Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { int updateCount = entityManager.createNamedQuery(DELETE_ASSOCIATION_NAMED_QUERY) .setParameter("associationKey", associationValue.getKey()) .setParameter("associationValue", associationValue.getValue()) .setParameter("sagaType", getSagaTypeName(sagaType)) .setParameter("sagaId", sagaIdentifier) .executeUpdate(); if (updateCount == 0 && logger.isWarnEnabled()) { logger.warn("Wanted to remove association value, but it was already gone: sagaId= {}, key={}, value={}", sagaIdentifier, associationValue.getKey(), associationValue.getValue()); } } }
JpaSagaStore implements SagaStore<Object> { protected void removeAssociationValue(EntityManager entityManager, Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { int updateCount = entityManager.createNamedQuery(DELETE_ASSOCIATION_NAMED_QUERY) .setParameter("associationKey", associationValue.getKey()) .setParameter("associationValue", associationValue.getValue()) .setParameter("sagaType", getSagaTypeName(sagaType)) .setParameter("sagaId", sagaIdentifier) .executeUpdate(); if (updateCount == 0 && logger.isWarnEnabled()) { logger.warn("Wanted to remove association value, but it was already gone: sagaId= {}, key={}, value={}", sagaIdentifier, associationValue.getKey(), associationValue.getValue()); } } protected  JpaSagaStore(Builder builder); }
JpaSagaStore implements SagaStore<Object> { protected void removeAssociationValue(EntityManager entityManager, Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { int updateCount = entityManager.createNamedQuery(DELETE_ASSOCIATION_NAMED_QUERY) .setParameter("associationKey", associationValue.getKey()) .setParameter("associationValue", associationValue.getValue()) .setParameter("sagaType", getSagaTypeName(sagaType)) .setParameter("sagaId", sagaIdentifier) .executeUpdate(); if (updateCount == 0 && logger.isWarnEnabled()) { logger.warn("Wanted to remove association value, but it was already gone: sagaId= {}, key={}, value={}", sagaIdentifier, associationValue.getKey(), associationValue.getValue()); } } protected  JpaSagaStore(Builder builder); static Builder builder(); @Override Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier); @Override Set<String> findSagas(Class<?> sagaType, AssociationValue associationValue); @Override void deleteSaga(Class<?> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues); @Override void updateSaga(Class<?> sagaType, String sagaIdentifier, Object saga, AssociationValues associationValues); @Override void insertSaga(Class<?> sagaType, String sagaIdentifier, Object saga,
                           Set<AssociationValue> associationValues); void setUseExplicitFlush(boolean useExplicitFlush); }
JpaSagaStore implements SagaStore<Object> { protected void removeAssociationValue(EntityManager entityManager, Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { int updateCount = entityManager.createNamedQuery(DELETE_ASSOCIATION_NAMED_QUERY) .setParameter("associationKey", associationValue.getKey()) .setParameter("associationValue", associationValue.getValue()) .setParameter("sagaType", getSagaTypeName(sagaType)) .setParameter("sagaId", sagaIdentifier) .executeUpdate(); if (updateCount == 0 && logger.isWarnEnabled()) { logger.warn("Wanted to remove association value, but it was already gone: sagaId= {}, key={}, value={}", sagaIdentifier, associationValue.getKey(), associationValue.getValue()); } } protected  JpaSagaStore(Builder builder); static Builder builder(); @Override Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier); @Override Set<String> findSagas(Class<?> sagaType, AssociationValue associationValue); @Override void deleteSaga(Class<?> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues); @Override void updateSaga(Class<?> sagaType, String sagaIdentifier, Object saga, AssociationValues associationValues); @Override void insertSaga(Class<?> sagaType, String sagaIdentifier, Object saga,
                           Set<AssociationValue> associationValues); void setUseExplicitFlush(boolean useExplicitFlush);  }