@Override public void insertSaga( Class<?> sagaType, String sagaIdentifier, Object saga, TrackingToken token, Set<AssociationValue> associationValues) { EntityManager entityManager = entityManagerProvider.getEntityManager(); SagaEntry<?> entry = new SagaEntry<>(saga, sagaIdentifier, serializer); entityManager.persist(entry); for (AssociationValue associationValue : associationValues) { storeAssociationValue(entityManager, sagaType, sagaIdentifier, associationValue); } if (logger.isDebugEnabled()) { logger.debug( "Storing saga id {} as {}", sagaIdentifier, new String(entry.getSerializedSaga(), Charset.forName("UTF-8"))); } if (useExplicitFlush) { entityManager.flush(); } }
@Override public void updateSaga( Class<?> sagaType, String sagaIdentifier, Object saga, TrackingToken token, AssociationValues associationValues) { EntityManager entityManager = entityManagerProvider.getEntityManager(); SagaEntry<?> entry = new SagaEntry<>(saga, sagaIdentifier, serializer); if (logger.isDebugEnabled()) { logger.debug( "Updating saga id {} as {}", sagaIdentifier, new String(entry.getSerializedSaga(), Charset.forName("UTF-8"))); } int updateCount = entityManager .createNamedQuery(UPDATE_SAGA_NAMED_QUERY) .setParameter("serializedSaga", entry.getSerializedSaga()) .setParameter("revision", entry.getRevision()) .setParameter("sagaId", entry.getSagaId()) .setParameter("sagaType", entry.getSagaType()) .executeUpdate(); for (AssociationValue associationValue : associationValues.addedAssociations()) { storeAssociationValue(entityManager, sagaType, sagaIdentifier, associationValue); } for (AssociationValue associationValue : associationValues.removedAssociations()) { removeAssociationValue(entityManager, sagaType, sagaIdentifier, associationValue); } if (updateCount == 0) { logger.warn("Expected to be able to update a Saga instance, but no rows were found."); } if (useExplicitFlush) { entityManager.flush(); } }