Showing posts with label primefaces. Show all posts
Showing posts with label primefaces. Show all posts

Friday, September 20, 2013

nested SDD

SDD (Statement driven development) is a powerfull productivity weapon.

Until now minuteproject SDD configuration was limited to a single statement.
This is enough when you want to query to display a list or graph or even call a store proc.

But often your business need is make of nested action. The output of some query serves as the input for other actions.
This is this capacity to handle multiple successive actions based on statement that is called nested SDD.

Something concrete


Imagine the following scenario
I have DB connections that are stucked and I want to kill them. How I want to do that is via a web application.
And I want to have this application without writing a single LOC and within 1 minute...
Here is the kind of productivity challenge Minuteproject is bound to solve with nested SDD.

Decomposition of the scenario

Infrastructure

Oracle DB.

Queries

I have DB connections that are stucked and I want to kill them.
http://appsdbanew.wordpress.com/2007/11/05/how-to-find-blocking-session-and-kill-the-session-from-database/
It can be reduced in writing 2 queries:

Retrieve the connections (and stucked ones)
select process,sid, serial#, blocking_session from v$session where blocking_session is not null

Kill collections
alter system kill session '#SID,#SERIAL' immediate

Nesting

The output of the first query (sid and serial#) serves as input of the second.


Minuteproject

Those two queries show be enough to get a application in Primefaces for quite handy for the help desked.



Friday, August 9, 2013

Reviewing primefaces starter

I have been contacted to review Primefaces starter book, and here are my impressions as a Primefaces user and with a 'minuteproject' perspective.


This book is a starter targeting developers with JSF knowledge, and it is very rewarding. 
It covers Primefaces (PF) core features as well cool ones that make your application look great! such as Calendar, Google map, interactive chat, reporting diagram.
It is based on concrete data model with a github source code ready to clone and package seamlessly. All the installation procedure and tooling is described making your environment setup easy. This starter spurs up you curiosity to dive in to the code while the chapter provides you the substantial insights of PF JSF components. The result is a comprehensive advanced application based on non-trivial model spanning from CRUD, JEE (JPA/CDI) to advanced PF component.
Another aspect that I liked was the density of information: it sticks to the essential, no fuss, no dozens-of-API-page syndrome.


From a minuteproject perspective, and seeing Primefaces as a major actor in the presentation framework, I am always interested to grab extra bits of info on the subject.
I was particularly interested in the cool features (Calendar, Maps) since I think that with SDD (Statement Driven Development ) some of those could be generated. SDD can be already used in PF to produce graphs

So it was quite an enjoyable review.


Monday, April 29, 2013

How-to cloudbees minuteproject 4 primefaces

Introduction

Cloudbees offers JEE app and Mysql DB storage.
Minuteproject generates CRUD and reporting application for Primefaces based on a database model.

This article is based on upon the petshop mysql database.
The result can be show on cloudbees at http://petshopapp.minuteproject.cloudbees.net

The application, minuteproject configuration and DB model can be found on google code at https://code.google.com/p/minuteproject/downloads/detail?name=petshop-mp4primeface-cloudbees.zip

Prerequisits

Download and install Minuteproject set MP_HOME
Download and install Cloudbees SDK set BEES_HOME
Create a cloudbees account
Mysql local DB running with a schema.

Steps

In order to get Cloudbees Primefaces application quickly follow the next steps.

Cloudbees setups

Cloudbees setup can be done on the website, but also by the following command lines

Cloudbees app

$bees app:create petshopapp

Cloudbees  DB

$bees db:create petshopappDB -u username -p password

Cloudbees binding

$bees app:bind -db petshopappDB -a petshopapp -as petshopAppDS

Deployment on Cloudbees

$bees app:deploy -a account/petshopapp -t tomcat7 path-to-your-app.war
This step is performed after you have build your app.

Install you DB schema

Get the server connection information:
  • server
  • port
  • user_name
  • pass_word

$mysql --user=user_name --password=pass_word --host=server --port=port < schema.sql

Minuteproject 4 Primefaces app

To create a primefaces application, minuteproject can generate one based on a database structure.
Minuteproject runs with a command line.
The configuration file used is petshop-mp4primeface-cloudbees.zip 

Configuration

The configuration file can be found in the zip under mp-config-JSF-Spring.xml
The main points of the file are
<!DOCTYPE root>
<generator-config xmlns="http://minuteproject.sf.net/xsd/mp-config" 
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
xs:noNamespaceSchemaLocation="mp-config.xsd">
    <configuration>
  <conventions>
   <target-convention type="enable-updatable-code-feature" />
  </conventions> 
  <model name="petshop" version="1.0" package-root="net.sf.mp.demo">   
   <data-model>
                <driver name="mysql" version="5.1.16" groupId="mysql"
                    artifactId="mysql-connector-java"></driver>
                <dataSource>
                    <driverClassName>org.gjt.mm.mysql.Driver</driverClassName>
                    <url>jdbc:mysql://127.0.0.1:3306/petshop</url>
                    <username>root</username>
                    <password>mysql</password>
                </dataSource>
                <primaryKeyPolicy oneGlobal="false">
                    <primaryKeyPolicyPattern name="autoincrementPattern"></primaryKeyPolicyPattern>
                </primaryKeyPolicy>
   </data-model>
   <business-model>
    <generation-condition>
     <condition type="exclude" startsWith="DUAL"></condition>
     <condition type="exclude" startsWith="ID_GEN"></condition>
     <condition type="exclude" startsWith="SEQUENCE"></condition>
    </generation-condition>  
    <business-package default="pet">
     <condition type="package" startsWith="PRODUCT" result="product"></condition>
     <condition type="package" startsWith="ITEM" result="product"></condition>
    </business-package> 
    <enrichment>
       <conventions>
          <entity-naming-convention type="apply-strip-table-name-prefix" pattern-to-strip="SYS,FIN"/>
          <reference-naming-convention type="apply-referenced-alias-when-no-ambiguity" is-to-plurialize="true"></reference-naming-convention>
       </conventions>
        <package name="product">
         <entity-group entities="PRODUCT"></entity-group>
         <entity-group entities="ITEM"></entity-group>
        </package>
     <entity name="PRODUCT" alias="MY_GOOD_PRODUCT">    
     </entity>        
     <entity name="ITEM" alias="MY_GOOD_ITEM" comment="my item table">
      <field name="PRODUCTID" alias="THIS_IS_MY_PRODUCT" comment="my product field reference"></field>     
     </entity>        
     <entity name="CATEGORY" content-type="reference-data" >
        <field name="DESCRIPTION" ordering="asc" label="my description" is-searchable="true"></field>
        <field name="NAME" ordering="asc" ></field>
        <semantic-reference>
          <sql-path path="NAME"/>
        </semantic-reference>
     </entity>
    </enrichment>     
   </business-model>
            <statement-model>
                <queries>
                     <query name="get address abstract" id="dashAddress" type="dashboard" category="pie-chart">
                         <query-body> <!-- dimensions column first -->
                         <value>
<![CDATA[select city, count(*) as nb from address group by city order by count(*) desc limit ? ]]>
                            </value>
                         </query-body>
                         <query-params>
                             <query-param name="top city" is-mandatory="false" type="INT" sample="37" default="10"></query-param>
                         </query-params>
                     </query>
                     <query name="get address summary" id="dashCity" type="dashboard" category="bar-chart">
                         <query-body> <!-- dimensions column first -->
                         <value>
<![CDATA[select city, count(*) as nb, count(*) as nb2 from address group by city order by count(*) desc]]>
                            </value>
                         </query-body>
                     </query>
                     <query name="get addresses by criteria" id="c">
                         <query-body><value>
<![CDATA[select * from address where lcase(city) like ?]]>
                            </value>
                         </query-body>
                         <query-params>
                             <query-param name="city" type="STRING" sample="'S'" convert="lowercase,append%" default="%">
                             </query-param>
                         </query-params>
                     </query>
                </queries>
            </statement-model>
  </model> 
The database driver is mysql and the primary key strategy is autoincrement for not natural primary key
Product and Item tables have been aliased
Product and Item tables goes in product package, which means graphically a distinct menu access.
Category is a reference-data table, which means caching and access via drop down list

Statement:
Misc statement queries can be used to produce report in forms of list, pie-chart, bar-chart.

Generate

Copy the file in $MP_HOME/mywork/config From a prompt run
$model-generation mp-config-JSF-Spring.xml

Build

The generation result is in $MP_HOME/dev/JSF/petshop From a prompt run
$mvn clean package

Customise package for cloudbees


Cloudbees context

Optional step to perform if your not creating the binding between the Application and DB.

Add a Cloudbees file context.xml

In /WEB-INF/lib add context.xml in war/META-INF
<Context>
<Resource name="jdbc/petshopAppDS"
            auth="Container"
            type="javax.sql.DataSource"

            url="jdbc:${DATABASE_URL}"
            username="${USER_NAME}"
            password="${PASS_WORD}"

            driverClassName="com.mysql.jdbc.Driver"

            maxActive="20"
            maxIdle="1"
            maxWait="10000"
            removeAbandoned="true"
            removeAbandonedTimeout="60"
            logAbandoned="true"

            validationQuery="SELECT 1"
            testOnBorrow="true"
            />
</Context>

The ${DATABASE_URL} is retrieved from 

$bees db:info petshopapp

Persistence.xml

adapt persistence.xml with Cloudbees binding alias
change non-jta-data-source node with java:comp/env/jdbc/petshopAppDS
remove properties hibernate connection info

The persistence.xml is located in petshopBackEnd-1.0-SNAPSHOT.jar!/META-INF

<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
<!--MP-MANAGED-UPDATABLE-BEGINNING-DISABLE @PERSISTENCE-UNIT-petshop@-->
    <persistence-unit name="petshop">
<!--MP-MANAGED-UPDATABLE-ENDING-->
<non-jta-data-source>java:comp/env/jdbc/petshopAppDS</non-jta-data-source>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <!-- pet --> 
        <class>net.sf.mp.demo.petshop.domain.pet.Address</class>
        <class>net.sf.mp.demo.petshop.domain.pet.Category</class>
        <class>net.sf.mp.demo.petshop.domain.pet.Sellercontactinfo</class>
        <class>net.sf.mp.demo.petshop.domain.pet.Tag</class>
        <class>net.sf.mp.demo.petshop.domain.pet.Ziplocation</class>

        <!-- product --> 
        <class>net.sf.mp.demo.petshop.domain.product.MyGoodItem</class>
        <class>net.sf.mp.demo.petshop.domain.product.MyGoodProduct</class>


        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" />
            <property name="net.sf.ehcache.configurationResourceName" value="/ehcache.xml" />
            <property name="hibernate.cache.use_query_cache" value="true" />
            <property name="hibernate.cache.use_second_level_cache" value="true" />
<!--MP-MANAGED-ADDED-AREA-BEGINNING @properties@-->
<!--MP-MANAGED-ADDED-AREA-ENDING @properties@-->
        </properties> 


<!--MP-MANAGED-ADDED-AREA-BEGINNING @persistence-unit@-->
<!--MP-MANAGED-ADDED-AREA-ENDING @persistence-unit@-->
    </persistence-unit>

<!--MP-MANAGED-ADDED-AREA-BEGINNING @persistence@-->
<!--MP-MANAGED-ADDED-AREA-ENDING @persistence@-->

</persistence>


Deploy

$bees app:deploy -a account/petshopapp -t tomcat7 JSF/target/petshopApp.war
where account is the account you created

Tomcat7 target ensure the EL libraries are present.

Result


Improvements

For those who think it's a bit long, they are right!
Most of the step could be simplified since most of it could be generated!

Minuteproject will add a cloud track with cloudbees for that in the next release.


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