Friday, August 17, 2012

sql query to primefaces app with sdd

Intro

Primefaces provides cool rendering facilities on one hand.
Minuteproject provides reverse-engineering facilities base on relational database but also on sql statement, on the other hand.

Now you have a query and you want to have a primefaces app!... without writing any (ANY) line of code.
This article is for YOU.

If you download Minuteproject 0.8.2+ you can have an example on how-to do it (delivered as a demo).
This article tracks the steps to follow as well as explaining the demo.

Enrichment

You can consult the entire configuration in /demo/config/mp-config-JSF-Spring.xml

statement-driven-development

Minuteproject provides a enrichment area where you can set up your sql queries.
Here is the snippet part correspondinng to the query enrichment inside the statement-model node.

        ....
   <statement-model>
                <queries>
                     <query name="get addresses by criteria" id="c">
                         <query-body><value>
<![CDATA[select * from address where latitude between ? and ? and longitude between ? and ? and lcase(city) like ?]]>
                            </value></query-body>
                         <query-params>
                             <query-param name="latitude_lower_limit" is-mandatory="false" type="DOUBLE" sample="37"></query-param>
                             <query-param name="latitude_upper_limit" type="DOUBLE" sample="38"></query-param>
                             <query-param name="longitude_lower_limit" type="DOUBLE" sample="-122"></query-param>
                             <query-param name="longitude_upper_limit" type="DOUBLE" sample="-123"></query-param>
                             <query-param name="city" type="STRING" sample="'S'" convert="lowercase,append%" default="%"/>
                         </query-params>
                     </query>
                </queries>
            </statement-model>
  </model> 

You specify the name of the query which will be used to create
  • DTO class
  • JSF menu entry
  • JSF URL
  • JSF form name
You specify in question marks the input parameters you want and in query-param what is the name to give them. Those name with be used to create
  • DTO variable
  • JSF form entries with validation

Empower primefaces with minuteproject sdd templates

Primefaces needs to have new templates about what to generate coming from SDD.
This is given in the track 
            <target refname="SDD-beans" 
                outputdir-root="../output/JSF-Spring/JPA2"
               fileName="mp-template-config-SDD-beans.xml" 
               templatedir-root="../../template/framework/bean">
            </target> 

 

Steps

Set-up

  • Download last version of Minuteproject.
  • Unzip in directory
  • Start sample petshop DB: /sample/start-petshop-database.cmd/sh
  • Go to /config/demo
    • Run demo-JSF-Spring-primefaces.cmd/sh
  • Go to /target/mp-bsla
    • Run install-maven.cmd (it installs a MVN dependency for spring DAO that is not yet (sic) in mvn-central)
  • Go to /demo/output/JSF-Spring
    • Run 'mvn clean package'
Alternative run all demos

 

Generated code

You have a JSF primeface 3.3 app with cupertino theme offering Create, List, Delete on entities and with I/O screen of each query here (GetAddressesByCriteriaInput).

The generated code is decomposed into 3 maven project:
  • You have JPA2 backend+ DTOs for each SDD query I/O
  • You have Spring 3 integration with CRUD DAO on top of entity and DAO for SDD query DTOs.  
  • You have a JSF front-end integrated with spring
This way you can easily work with minuteproject Updatable Code feature to get what you customize your artifact without losing the power of consecutive generations.

Deployment

Setup

The resulting application is petshopApp.war in /demo/output/JSF-Spring/JSF/target
It is ready to be dropped on tomcat or other JEE container.
 
But before take care that your EL (expression language jar spec and impl) are 2.2.
On tomcat (check that /lib contains 
  • el-api-2.2.jar
  • el-impl-2.2.jar
Check the stackoverflow entries
Note: that there is no connection pool dependency on the container. By default in nothing is specified in the JPA2 target 'environment' property. The environment is considered has local so no reference to a JNDI CP.

Deploy

Start tomcat (/bin/startup.cmd/sh)
Drop petshopApp.war in /webapps

 

Result

Here is a little UC where we create an address and we retrieve it base on the ad-hoc sdd query.

Create address

List addresses

SDD in action: Use specific criteria to address

Check validation

 

Future

This is not enough...
Why not having multiple statement that works together to produce for example a master-detail or dashboard-master-detail?... primefaces provides nice toolset for that.

Break current limitations
  • SDD in the current form is sql oriented, but nothing prevent from having it REST URL resource oriented.
  • Add validations, mapping, convertions on I/O params.
  • Provide presentation defaulting
  • Provide navigation between SDD components
  • Add filtering and improved query builder

1 comment:

  1. You have to mention your previous job names as well as organization names in your resume.


    Sample Resume Template

    ReplyDelete