@Override protected void updateSaga(Saga saga) { SagaEntry sagaEntry = new SagaEntry(saga, serializer); mongoTemplate .sagaCollection() .findAndModify( SagaEntry.queryByIdentifier(saga.getSagaIdentifier()), sagaEntry.asDBObject()); }
@Override protected Set<String> findAssociatedSagaIdentifiers( Class<? extends Saga> type, AssociationValue associationValue) { final BasicDBObject value = associationValueQuery(type, associationValue); DBCursor dbCursor = mongoTemplate.sagaCollection().find(value, new BasicDBObject("sagaIdentifier", 1)); Set<String> found = new TreeSet<String>(); while (dbCursor.hasNext()) { found.add((String) dbCursor.next().get("sagaIdentifier")); } return found; }
@Override public Saga load(String sagaIdentifier) { DBObject dbSaga = mongoTemplate.sagaCollection().findOne(SagaEntry.queryByIdentifier(sagaIdentifier)); if (dbSaga == null) { return null; } SagaEntry sagaEntry = new SagaEntry(dbSaga); Saga loadedSaga = sagaEntry.getSaga(serializer); if (injector != null) { injector.injectResources(loadedSaga); } return loadedSaga; }
@Override protected void removeAssociationValue( AssociationValue associationValue, String sagaType, String sagaIdentifier) { mongoTemplate .sagaCollection() .update( new BasicDBObject("sagaIdentifier", sagaIdentifier).append("sagaType", sagaType), new BasicDBObject( "$pull", new BasicDBObject( "associations", new BasicDBObject("key", associationValue.getKey()) .append("value", associationValue.getValue())))); }
@Override protected <T extends Saga> T loadSaga(Class<T> type, String sagaIdentifier) { DBObject dbSaga = mongoTemplate.sagaCollection().findOne(SagaEntry.queryByIdentifier(sagaIdentifier)); if (dbSaga == null) { throw new NoSuchSagaException(type, sagaIdentifier); } SagaEntry sagaEntry = new SagaEntry(dbSaga); Saga loadedSaga = sagaEntry.getSaga(serializer); if (!type.isInstance(loadedSaga)) { return null; } T storedSaga = type.cast(loadedSaga); if (injector != null) { injector.injectResources(storedSaga); } return storedSaga; }
@Override protected void storeSaga(Saga saga) { SagaEntry sagaEntry = new SagaEntry(saga, serializer); DBObject sagaObject = sagaEntry.asDBObject(); mongoTemplate.sagaCollection().save(sagaObject); }
@Override protected void deleteSaga(Saga saga) { mongoTemplate .sagaCollection() .findAndRemove(SagaEntry.queryByIdentifier(saga.getSagaIdentifier())); }