private void updateStateInDB(T stateful, State<T> current, State<T> next,
			StateDocumentImpl stateDoc) throws IllegalAccessException,
			StaleStateException {
		// Entity is in the database - perform qualified update based off
		// the current State value
		//
		Query query = buildQuery(stateDoc, current);
		Update update = buildUpdate(current, next);

		// Update state in DB
		//
		StateDocumentImpl updatedDoc = updateStateDoc(query, update);
		if (updatedDoc != null) {

			// Success, update in memory
			//
			setStateDocument(stateful, updatedDoc);

		} else {

			// If we aren't able to update - it's most likely that we are out of sync.
			// So, fetch the latest value and update the Stateful object.  Then throw a RetryException
			// This will cause the event to be reprocessed by the FSM
			//
			updatedDoc = findStateDoc(stateDoc.getId());

			if (updatedDoc != null) {
				String currentState = stateDoc.getState();
				setStateDocument(stateful, updatedDoc);
				throwStaleState(currentState, updatedDoc.getState());
			} else {
				throw new RuntimeException("Unable to find StateDocument with id=" + stateDoc.getId());
			}
		}
	}
private void updateStateInDB ( T stateful , State < T > current , State < T > next , StateDocumentImpl stateDoc ) throws IllegalAccessException , StaleStateException { Query query = buildQuery ( stateDoc , current ) ; Update update = buildUpdate ( current , next ) ; StateDocumentImpl updatedDoc = updateStateDoc ( query , update ) ; if ( updatedDoc != null ) { setStateDocument ( stateful , updatedDoc ) ; } else { updatedDoc = findStateDoc ( stateDoc . getId ( ) ) ; if ( updatedDoc != null ) { String currentState = stateDoc . getState ( ) ; setStateDocument ( stateful , updatedDoc ) ; throwStaleState ( currentState , updatedDoc . getState ( ) ) ; } else { throw new RuntimeException ( "Unable to find StateDocument with id=" + stateDoc . getId ( ) ) ; } } }
@param stateful
@param current
@param next
@param stateDoc
@throws IllegalAccessException
@throws StaleStateException