Go Back   SmartClient Forums > Smart GWT Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13th Apr 2012, 15:32
Blama Blama is offline
Registered Developer
 
Join Date: Sep 2009
Posts: 930
Default Simple Serverside Datasource CRUD Operations

Hi Isomorphic,

I just started using SmartGWT Server today and am impressed once more!

My usecase was: on Buttonclick add a record to a DS, get the new (sequence-generated) ID and set this ID in some FK-column of another DS.

I did this with stacked DSCallBacks first, which worked, but felt wrong as the data is transferred to the client and back to the server. Also, I couldn't get SQL-Transaction to work with this.

Doing it the right way was some research, but now it works. For everyone interested here some pointers:
http://forums.smartclient.com/showthread.php?t=14488
http://www.smartclient.com/smartgwte..._specific_data
http://www.smartclient.com/smartgwtee/showcase/#dmi
(http://www.smartclient.com/smartgwte...validation_dmi)
Operation Bindings, Data Integration, Smart GWT Server Framework chapters in Quick Start Guide.
http://www.smartclient.com/smartgwte...DSRequest.html
http://www.smartclient.com/smartgwte...SResponse.html

For me, following code worked. Having the possibility to interfere before and or after some DS-operation is great!
Clientcode:
Code:
DSRequest requestProperties = new DSRequest();
requestProperties.setOperationId("addFromKind");
guestDS.addData(r,null,requestProperties);
DS operation binding:
Code:
<operationBinding operationType="add" operationId="addFromKind">
	<serverObject lookupStyle="new" className="com.acme.server.worker.AddGuest" methodName="addGuest"/>
	<values fieldName="MODIFIED_AT" value="$currentDate" />
</operationBinding>
ServerCode:
Code:
public class AddGuest {
	public DSResponse addGuest(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception {
		SQLTransaction.startTransaction(dsRequest.getRPCManager());
		DSResponse guestResponse = dsRequest.execute();

		if (guestResponse.getStatus() == DSResponse.STATUS_SUCCESS) {
			// Get new ID
			BigDecimal newGuestID = (BigDecimal) guestResponse.getDataField("ID");

			// Prepare Update for T_KIND
			DSRequest updateKindRequest = new DSRequest("T_KIND", "update");
			updateKindRequest.setCriteria("ID", dsRequest.getFieldValue("KIND_ID"));
			Map<String, String> m = new HashMap<String, String>();
			m.put("GUEST_ID", newGuestID.toString());
			updateKindRequest.setValues(m);
			updateKindRequest.setRPCManager(dsRequest.getRPCManager());
			DSResponse kindResponse = updateKindRequest.execute();
			guestResponse.addRelatedUpdate(kindResponse);
	
			SQLTransaction.commitTransaction(dsRequest.getRPCManager());
		} else {
			SQLTransaction.rollbackTransaction(dsRequest.getRPCManager());
			guestResponse.setFailure();
		}
		SQLTransaction.endTransaction(dsRequest.getRPCManager());
		return guestResponse;
	}
};
Perhaps this posts helps some users to get started with the server framework.

I for myself have only one question left. I send 1 request and change 2 rows in different tables with this (=2 DSResponses). Is the way I do the Chaining correct (guestResponse.addRelatedUpdate has no Javadoc).

Thanks & HF using SmartGWT,
Blama
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
Download a File error RHill Technical Q&A 12 5th Mar 2012 11:07
JPADataSource - transaction problem when using queueing dejan Smart GWT Technical Q&A 7 13th Feb 2012 14:22
JPADataSource and ManyToMany relationship dejan Smart GWT Technical Q&A 8 9th Feb 2012 09:27
Filter on foreign table valbosoft Smart GWT Technical Q&A 22 4th Jan 2012 13:50
java.lang.NoClassDefFoundError: com/smartgwt/client/data/DSCallback on server side maksymg Smart GWT Technical Q&A 1 6th Oct 2011 17:30

© 2010,2011 Isomorphic Software. All Rights Reserved