Say I have a webflow with N states. How can I persist a user's state to a database so that if he leaves the flow somewhere in the middle, he can start where he le开发者_开发百科ft off, next time he logs into the system, no matter what machine he uses when he does.
General question, you're essentially dealing with a long transaction. This is generally a really hard problem, as you have to deal with concurrency issues. However, if you wanted to do this, you'd probably have to have Domain objects that correspond to the entities involved
class ShoppingCart
{
static belongsTo = [ person : Person ]
static hasMany = [ item : ShoppingCartItem ]
static hasOne = [state : ShoppingCartState ]
}
You could use the State pattern to encapsulate the state, and save it to the DB at the end of every web flow transition.
If your use case is simpler, you may be able to do something with Audit Logging.
精彩评论