Yes, the default scaffold save doesn't return the saved object. In the client
the generated code is:
libraryService.save(createServiceContext(), updatedLibrary);
if (isNew) {
// new object, INSERT, but we don't have an id, so we need to
refresh
DataEvent event =
new DataEvent(richLibrary, DataEvent.Action.REFRESH);
notifyView(event);
This will trigger a reload from the client. Not very efficient.
However, if the save method returns the saved object the generated code in
the client is:
Library savedLibrary =
libraryService.saveNew(createServiceContext(), updatedLibrary);
richLibrary.fromModel(savedLibrary);
this.richLibraries.put(savedLibrary.getKey(), richLibrary);
DataEvent event =
new DataEvent(richLibrary,
(isNew ? DataEvent.Action.INSERT :
DataEvent.Action.UPDATE));
notifyView(event);
Which is much better.
It is easy to define such a save method.
model.design:
Service LibraryService {
@Library saveNew(@Library library);
LibraryServiceImpl:
public Library saveNew(ServiceContext ctx, Library library) {
save(ctx, library);
// now the id has been assigned
return library;
}
JUnit test:
public void testSaveNew() throws Exception {
Date now = new Date();
String name = "TestSaveNewLibrary " + now;
Library library = new Library(name);
Library savedLibrary = libraryService.saveNew(getServiceContext(),
library);
Library foundLibrary =
libraryService.findLibraryByName(getServiceContext(), name);
assertNotNull(foundLibrary);
assertEquals(foundLibrary.getId(), savedLibrary.getId());
assertEquals(foundLibrary, savedLibrary);
}
model.guidesign:
CreateTask for Library {
createWith LibraryService.saveNew
}
I think we should consider to always return the saved object from the
default scaffold save method.
/Patrik
Steffen Stundzig wrote:
>
> Hi all,
>
> I'm using parts of the generated ui code as base for my RAP UI. There
> I've a dialog with an entity, which I need to save. The save method in
> the service, can do that.
>
> But now, how could i get the id of the saved object or the object
> itself? The problem is, i could call the save method with the same
> entity instance twice and the service stores 2 rows in the database.
>
> The service doesnt return the primary key (id) or something else, nor
> the uuid contains the as parameter specified entity.
>
> There are any thoughts on that? My first idea is to enrich the
> SaveAccessImpl to return the generated primary key of the entity,
> similar to the save(Object)-method in the hibernate session.
>
> regards
> Steffen...
>
--
View this message in context:
http://www.nabble.com/-sculptor--Save-API-tp21086454s17564p21086464.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fornax-developer