Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    RestHandler queueing / transactions

    I'm sure I should see this in the docs somewhere, but maybe I've misunderstood what I can and cannot do with RestHandler. The short of it is that I just want to expose my SGWT datasources (+DMIs and associated goodness) to some legacy application.

    I've read the QuickStart, the RestHandler and RestDataSource javadocs, and it's not obvious to me how I'd post a request to RestHandler for a multi-datasource add or update operation.

    I thought I might try

    Code:
    <request>
    	<data>
    		<countryDS>
    			<countryCode>US</countryCode>
    			<countryName>Edited Value</countryName>
    			<capital>Edited Value</capital>
    			<continent>Edited Value</continent>
    		</countryDS>
    		<someOtherDS>
    			<foo>EditedValue</foo>
    		</someOtherDS>
    	</data>
      <dataSource>countryDS</dataSource>
      <dataSource>someotherDS</dataSource>
      
      <operationType>update</operationType>
    </request>
    but what when I'm doing some sort of queuing - e.g., update countryDS and adding a someOtherDS?

    #2
    The built-in RestHandler doesn't have a format for a queue of operations. There's a few options:

    1. Feature Sponsorship to have this capability added

    2. just represent the combined operation as a single operation and merge all the data together (a mild hack, but it may come up only a couple of times)

    3. write your own RestHandler-style servlet and just use the server-side DataSource APIs to implement the operations. DataSource APIs can be used in a standalone application with no servlets/http involved at all, so they also work in this use case.

    Comment


      #3
      From the previous reply, we are interested in implementing the third suggestion below:

      "3. write your own RestHandler-style servlet and just use the server-side DataSource APIs to implement the operations. DataSource APIs can be used in a standalone application with no servlets/http involved at all, so they also work in this use case."

      How do we add / update multiple SQL datasources with multiple requests such that if the second request throws a validation or other error, the RPCManager will ROLLBACK the entire transaction?

      We have also tried using
      requestOne.setRPCManager(manager);
      requestOne.setPartOfTransaction(true);

      and manager.addAssociatedRequest(requestOne);

      but without success.

      Thanks in advance,

      Code:
      <DataSource  ID="ExampleCustomDS">	
      <fields>	 
              <field name="JOB_ID" type="float"/>        
              <field name="ORDER_ID" type="text"/>
      </fields>
          <operationBindings>  
              <operationBinding operationType="add">  
                  <serverObject className="MyCustomDS"/>  
                  <serverMethod>customAdd</serverMethod>  
              </operationBinding>  
          </operationBindings> 	
      </DataSource>
      
      
      
      public final class MyCustomDS extends SQLDataSource {
      
      
      public void customAdd(RPCManager manager, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
      			throws Exception {
      
      	DSRequest request = null;			
      	request = manager.getDSRequest();
              manager.doCustomResponse();						
      	if (manager != null) {
      		clientValues = request.getClientSuppliedValues();
      		jobId = (String) clientValues.get("JOB_ID");
      		orderId = (String) clientValues.get("ORDER_ID");
      
      		DSRequest requestOne = new DSRequest("OtherSQLDatasourceOne",DataSource.OP_ADD);				
      		HashMap<String, Object> values = new HashMap<String, Object>();
      
                       values.put("JOB_ID",jobId);						
      		requestOne.setValues(values);
      		DSResponse responseOne = requestOne.execute();
      
      
      		DSRequest requestTwo = new DSRequest("OtherSQLDatasourceTwo", DataSource.OP_ADD);				
      		HashMap<String, Object> values = new HashMap<String, Object>();
      
                      values.put("ORDER_ID",orderId);						
      		requestTwo.setValues(values);
      		DSResponse responseTWO = requestTwo.execute();					
      
      	}	
      
         return;
       }
      }

      Comment


        #4
        The previous poster went with #1 (sponsorship) so this is now built into the framework as of 3.0, no need to implement it yourself.

        Comment

        Working...
        X