Updates are quite straight forward in Aspire. An update is initiated by a user submitting a form. A form can be submitted using either a get method or a post method. Or you can even use a javascript function to collect the relevent fields and fire of a URL to the server along with the parameters.
Either way all of the suggested methods will conceptually resolve to sending a url to the server side with parameters. By knowing this structure you can understand the update process in Aspire better
http://your-host:yourport/your-webapp/servlet/UpdateServlet?request_name=UpdateRequest&arg1=10&arg2=20 etc.
The target of an update request in Aspire is the "UpdateServlet". This UpdateServlet requires one mandatory parameter called "request_name". This parameter or argument points to a symbolic name in the configuration file. In this example this symbolic name is "UpdateRequest". The rest of the arguments are optional.
Based on the symbolic name for the update request, Aspire will kick off things based on how this symbolic name is defined in a configuration file. Let us take a look at this definition.
#*****************************************************
#Have a business class responsible for this request
#*****************************************************
request.updateRequest.classname=com.ai.db.DBRequestExecutor2
request.updateRequest.db=(my-database-name)
request.updateRequest.query_type=update
request.updateRequest.stmt=\
insert into table1 (a,b,c) values ('literal',{arg1},{arg2.quote})
#*****************************************************
#Based on sucess or failure redirect the user to a display page
#*****************************************************
request.updateRequest.redirectURL=\
/your-webapp/servlet/DisplayServlet?url=Page1&arg1={any-key}
request.updateRequest.failureRedirectURL=\
/your-webapp/servlet/DisplayServlet?url=Page1&arg1={any-key}&result=error
The above definition allows Aspire to do the following. Invoked by Aspire "com.ai.db.DBRequestExecutor2" will execute the insert statement on the specified database. The values from the incoming url are accordingly substituted into the insert statement before execution. These arguments can be literals, integers, or string representations. Once this statement is executed Aspire will commit or roleback based on an exception. If there is no exception, then the results are commited and the user redirected to the URL specified by the "redirectURL".If there is an exception then the results are rolled back and the user redirected to the failureRedirectURL. There is a sophisticated redirection mechanism availabe but not discussed here as I am focusssing on the simple case to aid understanding in the first pass. Values from the URL can be used in the redirect urls using Aspire substitution syntax. That is all there is to it
The case above is a specialized case where the business logic is a pre-fabricated part that knows how to execute SQL statements. These pre-fabricated parts saves you writing any Java code when appplicable. Some relevent pre-fabricated business parts are:
When these parts does not satisfy the update need you can create your own part. Let us call this part mycom.mypkg.MyPart. Then you can change the updateRequest definition as follows:
#*****************************************************
#Have a business class responsible for this request
#*****************************************************
request.updateRequest.classname=mycom.mypkg.MyPart
#*****************************************************
#Based on sucess or failure redirect the user to a display page
#*****************************************************
request.updateRequest.redirectURL=\
/your-webapp/servlet/DisplayServlet?url=Page1&arg1={any-key}
request.updateRequest.failureRedirectURL=\
/your-webapp/servlet/DisplayServlet?url=Page1&arg1={any-key}&result=error
See how the control is transferred over to your business component. It is upto your component to do whatever is necessary. Essentially your part will receive a Map of input values and what you do with them is upto you. Hidden in the hashtable some reserved values such as request, response, session, and may be connection under some circumstances
More than often you may need to update more than one table in response to a single incoming URL. And sometimes you may have to retrieve additional values from the database before an update. Such things are possible using a pre-fabricated part called PreTranslateArgsMultiRequestExecutor. Here is how you use this part to start an update pipeline.
#*****************************************************
#Have a business class responsible for this request
#*****************************************************
request.updateRequest.classname=com.ai.db.PreTranslateArgsMultiRequestExecutor
request.updateRequest.db=(my-database-name)
request.updateRequest.query_type=update
request.updateRequest.request.1=Update1
request.updateRequest.request.2=Update2
#*****************************************************
#Based on sucess or failure redirect the user to a display page
#*****************************************************
request.updateRequest.redirectURL=\
/your-webapp/servlet/DisplayServlet?url=Page1&arg1={any-key}
request.updateRequest.failureRedirectURL=\
/your-webapp/servlet/DisplayServlet?url=Page1&arg1={any-key}&result=error
#*****************************************************
#Define individual requests
#*****************************************************
request.Update1.classname=com.ai.db.DBRequestExecutor2
request.Update1.db=(my-database-name)
request.Update1.query_type=update
request.Update1.stmt=\
insert into table1 (a,b,c) values ('literal',{arg1},{arg2.quote})
request.Update2.classname=com.ai.db.DBRequestExecutor2
request.Update2.db=(my-database-name)
request.Update2.query_type=update
request.Update2.stmt=\
insert into table1 (a,b,c) values ('literal',{arg1},{arg2.quote})
You can also use selects in this pipeline. The output from the select statements can be used downstream to mine values for those update statements.
aspire - Tuesday, July 18, 2006 7:22:54 PM
How to collect fields from a web form to submit it to server side