Wednesday, May 16, 2012

Statement driven development WYSIWYG for REST

In my previous article, I mentioned that minuteproject will have statement driven development features.
This page I disclose the potential of SDD while developing REST application.
Regarding the technologies I take:
  • REST with CXF
  • Spring Bean for DAO
  • JPA2 as persistence layer
Original WYSIWYG is revisited into What You STATE Is What You Get.

As fundamentals you need a Statement with is surrounding I/O.
The model against which the statement is applied is important but secundary.

As example for SQL, I take 3 queries:
  • select * from address where latitude between ? and ? and longitude between ? and ? and lcase(city) like ?
  • select * from address where addressid between ? and ?
  • select * from address where lcase(city) like ?
Those queries must be given 
  • a name
  • an input (replace question marks by sample value and provide name)
  • an output (deduce from the metadata recieved after executing the query)
And basically that's it.


This information is translated into minuteproject inside the statement-model node.
                     <query name="get addresses by criteria">
<![CDATA[select * from address where latitude between ? and ? and longitude between ? and ? and lcase(city) like ?]]>
                             <query-param name="latitude_lower_limit" is-mandatory="false" type="DOUBLE" sample="37"></query-param>
                             <query-param name="latitude_upper_limit" is-mandatory="false" type="DOUBLE" sample="38"></query-param>
                             <query-param name="longitude_lower_limit" is-mandatory="false" type="DOUBLE" sample="-122"></query-param>
                             <query-param name="longitude_upper_limit" is-mandatory="false" type="DOUBLE" sample="-123"></query-param>
                             <query-param name="city" is-mandatory="false" type="STRING" sample="'S'"></query-param>
                     <query name="get address street">
                         <query-body><value><![CDATA[select * from address where addressid between ? and ?]]></value></query-body>
                             <query-param name="identifier_Address" is-mandatory="false" type="INT" sample="1"></query-param>
                             <query-param name="identifier_Address2" is-mandatory="false" type="INT" sample="1"></query-param>
                     <query name="get address">
                            <![CDATA[select * from address where lcase(city) like ?]]>
                             <query-param name="city" is-mandatory="false" type="STRING" sample="'S'"></query-param>

What you can expect after generating for the REST CXF track and deploying on Tomcat is to have for each statement 2 REST URL (one for XML format, one for JSON format).
So 6 paths altogether:










This feature is provided in the release 0.8.1 of minuteproject.


  • Java version = 1.6+
  • Maven installed
  • Tomcat installed 
  • download MP 0.8.1+
  • start sample database 
    • In /sample 
    • > start-petshop.cmd/sh
  • Generate
    • In /demo/config
    • >demo-JSF-Spring-primefaces.cmd/sh
  • Package
    • Add dependency: There is a maven dependency to install
      • In /target/bsla
      • >maven_install.cmd/sh
    • Generated code goes to /demo/output/cxf
    • >mvn package
  • Deploy
    • Start tomcat 
    • Drop generated artifact into /webapps


The generated artefacts for SDD are similar to those generated by minuteproject as a reverse engineering for track CXF.


Why use JPA2 if you go native?
MinuteProject already have a track available for REST CXF with Spring and JPA2 as backend so it was less changes to adapt this track, and then issue JDBC statements.

Is SDD limited to JPA2?
No, SDD can be spread to other tracks of minuteproject so it is not linked to JPA2.

I want this a little more complex?
You are write!
In future release, some input parameters can be considered as mandatory or not and have some validation.

No comments:

Post a Comment