return null;
}
public static TokenContext rollbackAndContinue(TokenContext contextArg, int rollbackDataBehavior, int rollbackPositionBehavior, Engine engine)
{
TokenContext memContext = contextArg;
Object contextId = memContext.getId();
// Save variable values before we perform the rollback
NodeSocket memCurrentSocket = memContext.getCurrentSocket();
int memPriority = memContext.getPriority();
String memQueueType = memContext.getQueueType();
CallStack memCallStack = null;
ProgressInfo memProgressInfo = null;
Map memProcessVariables = null;
try
{
if (rollbackPositionBehavior == RollbackPositionBehavior.MAINTAIN_POSITION)
{
memCallStack = (CallStack) CopyUtil.copyObject(memContext.getCallStack(), Copyable.COPY_DEEP, null);
memProgressInfo = (ProgressInfo) CopyUtil.copyObject(memContext.getProgressInfo(), Copyable.COPY_DEEP, null);
}
}
catch (CloneNotSupportedException e)
{
String msg = LogUtil.error(EngineUtil.class, "Error cloning token. [{0}]", memContext, e);
throw new EngineException("NoDefaultExitSocket", msg);
}
if (rollbackDataBehavior == RollbackDataBehavior.UPDATE_VARIABLES || rollbackDataBehavior == RollbackDataBehavior.ADD_VARIABLES)
{
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
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;
}
}
}
}