{
memProcessVariables = copyProcessVariables(memContext, engine.getPersistenceContextProvider());
}
// Perform transaction rollback and get rid of the rollback-invalid persistence context
TokenContextService contextService = engine.getTokenContextService();
contextService.evictContext(memContext);
engine.rollback();
// Retrieve the current version of the context
engine.begin();
TokenContext dbContext = contextService.getContextById(contextId);
boolean updateContext = false;
if (rollbackPositionBehavior == RollbackPositionBehavior.MAINTAIN_POSITION)
{
// Maintain the current position, so update the DB context from the memory context.
dbContext.setCurrentSocket (memCurrentSocket);
dbContext.setCallStack (memCallStack);
dbContext.setPriority (memPriority);
dbContext.setQueueType (memQueueType);
dbContext.setProgressInfo (memProgressInfo);
updateContext = true;
}
if (memProcessVariables != null)
{
for (Iterator it = memProcessVariables.entrySet().iterator(); it.hasNext();)
{
Map.Entry entry = (Map.Entry) it.next();
String varName = (String) entry.getKey();
Object value = entry.getValue();
value = PersistenceContextObjectSerializer.resolveSerializableObjectReference(value, dbContext, varName, engine.getPersistenceContextProvider());
if (rollbackDataBehavior == RollbackDataBehavior.UPDATE_VARIABLES)
{
// Update the DB context with the variable value of the memory context
dbContext.setProcessVariableValue(varName, value);
updateContext = true;
}
else
{
// Add new variables of the memory context to the DB context
if (dbContext.getProcessVariableValue(varName) == null)
{
if (value != null)
{
dbContext.setProcessVariableValue(varName, value);
updateContext = true;
}
}
}
}
}
if (updateContext)
{
contextService.saveContext(dbContext);
if (isCommitTokenContextChangesEnabled())
{
engine.commit();
}
}