Hello, everyone!
I tried to implement concurrency saving in the GWT 2.4.
There is a user case:
1. Users John and Jim open one entity to editing
2. John saves his changes. All is OK.
3. Jim saves his changes. System asked about overwrite
a. Jim does not want to overwrite, system just refreshes entity at the
page
b. Otherwise, if Jim wants to save his changes, changes must be
persisted and John's changes will be destroyed. (left only in the history
of changes)
So I have problem with 3.b.
*public* *void* save(MyEntityProxy entity){
MyRequest rContext = (MyRequest) driver.flush();
MyProxy myEntity = (MyProxy) rContext.edit(entity);
entitySave(rContext, (MyProxy) myEntity, *false*);
}
*private* *void* entitySave(MyRequest rContext, *final* MyProxy myEntity, *
boolean* overwrite){
GWT.*log*("SAVE ENTITY WITH NAME = " + myEntity.getName());
rContext.persist(myEntity, entityVersion,
overwrite).fire(*new*Receiver<MyProxy>() {
@Override
*public* *void* onSuccess(MyProxy response) {
goToList();
}
@Override
*public* *void* onFailure(ServerFailure error) {
*if*(isConcurency(error)){
entitySave((MyRequest)getNewRequestContext(), myEntity,*true*);
}
}
});
}
/*This is a method from MyService for persisting*/
*public* MyProxy persist(MyProxy entity, Long version, *boolean* overwrite)
{
LOG.info("PERSISTS ENTITY NAME=" + entity.getName());
*if*(!overwrite && !checkVersionChanged(entity, version)){ System.*out*
.println("RAISE CHANGED_BY_OTHER EXCEPTION");
*throw* *new*
RuntimeException(ServerFailureCode.*CHANGED_BY_OTHER*.name());
}
entity = getEntityManager().merge(entity);
getEntityManager().flush();
*return* entity;
}
isConcurrency is a method for checking concurrency issue and returns true
when user choose “overwrite” point in the dialog.
GWT log:
SAVE ENTITY WITH NAME = John //There is John changed name of entity
SAVE ENTITY WITH NAME = Jim //There is John changed name of entity
SAVE ENTITY WITH NAME = Jim //There is John overwrites entity
Server Log:
[INFO] PERSISTS ENTITY NAME=John //There is John changed name of
entity
[INFO] SAVE ENTITY NAME=John //Persisting of John's changes.
John finished his work
[INFO] PERSISTS ENTITY NAME=*Jim* //There is Jim changed name of
entity
[INFO] RAISE CHANGED_BY_OTHER EXCEPTION //Exception raises and dialog shows
for Jim
[INFO] PERSISTS ENTITY NAME=*John* //Second iteration of saving. *Look
at the name!*.
I do not understand what happened. When Jim overwrites his changes, at the
client layer all is correct, but server layer works with data saved by
previous user.
Is anybody knows how can I correctly overwrite changes in this situation?
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/-rAfaiBJUrMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.