- This topic has 5 replies, 4 voices, and was last updated 14 years, 1 month ago by
jimmywestin982.
-
AuthorPosts
-
PeterMemberHi,
I would like to change the JET customization for CRUD services to return the object that the CRUD operation was performed on.
e.g.
change from:
public void saveAddress(Address address) { Address existingAddress = addressDAO.findAddressByPrimaryKey(address.getId()); if (existingAddress != null) { if (existingAddress != address) { ... ... } address = addressDAO.store(existingAddress); } else { address = addressDAO.store(address); } addressDAO.flush(); }
to:
public Address saveAddress(Address address) { Address existingAddress = addressDAO.findAddressByPrimaryKey(address.getId()); if (existingAddress != null) { if (existingAddress != address) { ... ... } address = addressDAO.store(existingAddress); } else { address = addressDAO.store(address); } addressDAO.flush(); return address; }
I really appreciate any help with this 🙂
May 17, 2011 at 11:20 am #316866
jayperkinsMemberIn order to accomplish this, you will need to customize a couple of different things.
The operation methods that are generated are created by the scaffolding engine. The scaffolding engine creates models based on xml in the com.skyway.scaffolding.crud.spring plugin.xml file. We need to tell the scaffolding engine to add an output model to the saveDataTypeOperation model that will be created. We also need to update the saveCrudServiceImplementation.jet file so that the save method actually returns the data type.
I am attaching a customization project that contains the changes. There are two files that have changed:
1) plugin.xml – contains code to add a model output to the save operation – necessary otherwise you will get a compile error about not being able to return a value from a method that returns void
2) crudCommon/templates/crud/method/saveCrudServiceImplementation.jet – this generates the save method for the service and was changed to return the data type being savedMay 18, 2011 at 5:36 am #316887
PeterMemberthanks for your help… but there is nothing attached?
May 18, 2011 at 10:47 am #316896
jkennedyMemberI know that Jay sent along the file via email but I wanted to post it here for others who may want to see an example of how to customize the code generation in this way.
Attachments:
You must be logged in to view attached files.May 18, 2011 at 5:16 pm #316904
PeterMemberThanks guys!
May 25, 2011 at 7:02 am #317014
jimmywestin982Memberthank you for that helpful link huh…
-
AuthorPosts