Showing posts with label reverse-engineering. Show all posts
Showing posts with label reverse-engineering. Show all posts

Thursday, October 3, 2013

minuteproject 4 propel motivations

Propel is based on some forward engineering technics that creates your Php Object Domain and ORM classes for your based on a file describing your model.

Propel ORM also offers reverse-engineering facilities to generate this input file.
Minuteproject meanwhile creates a track for propel. Why? What are the motivations?

Minuteproject 4 propel track will be delivered in version 0.8.5.

Polyglot generator


Minuteproject was essentially generating java framework oriented artifact but the php tracks with propel and soon doctrine offers another perspective.
Whatever your language and your framework, minuteproject can offer you reverse-engineering facilities.


Get Php knowledge

Testing with php was quite easy and interesting.

Propel specifics

As mentionned previously Propel offers reverse-engineering solution.

Interesting points

Their solutions is interesting because for each database Propel support the tool issue database query-specific-data-dictionnary lookup. It is the same philosophy that JOOQ framework with JOOQ meta is following.

Minuteproject 4 propel advantages

Propel reverse-engineering solution propose raw reverse-engineering, while minuteproject offers you the possibility to make a reverse-analysis before.

Enrichment

All the enrichment facilities are available for Propel track. Which means that you can have smart reverse-engineering aspects:
  • Alias for tables (DB table naming convention can differ from you Php classes conventions)
    • In schema.xml 'name' is filled by DB name and phpName by your given name.
  • Alias for columns same principle as above
  • Apply alias (column or view) globally by conventions or individually
    • Ex tables starting with T_ such as T_USER can get User in php.
    • Ex field ending with FK (ex PRODUCT_FK) have the variable $product.
  • Granularity select only tables or views you need
    • No need to reverse-engineer all the entities

Multiple artifacts

Minuteproject 4 propel generate other artifacts such as
  • runtime-conf.xml
  • build.properties
  • command line scripts
  • setup.php

Updatable code

Generator tools are often see as generate once and no more...
It is not the case of minuteproject!

The code that you generate is updatable! 
If you do not like it change it! 
If it misses something add it!

Next time you generate YOUR ALTERATIONS WILL BE KEPT!


This is call updatable code feature. And all the minuteproject 4 propel templates have this feature!


Which means that if you do not like what  you have in the schema.xml node you can change them. If your model changes add couples of db object (table/view), change cardinality between objects, the next time you generate, new object and relationship will be added BUT your modification (ex table phpName) will be kept!

Thursday, May 10, 2012

Statement driven development

Today most methodologies used model oriented approach.
It can be domain-driven or reverse-engineering, one common point is that they start from a static definition of a model. For domain-driven, it is the domain issued by the development language itself. For the reverse-engineering it starts from a static model structure definition ex: a xsd, wsdl, database schema.
Statement driven development focuses on the actions the developer can run on some models and not the models themselves.
Example: a select statement fetching all the group members a user with group-administrator-role can manage.
Here the statement can be materialized into a search query with sql as implementation.
The important thing for the developer is the query and its I/O not really the underneath model and ... not the decorative technology.

Why Statement-Driven-Development

Couple of articles and limitations make me think that statement driven approach can be a flexible and fast alternative for developpers.
Usually after defining an abstract model such as ORM, the user have to write his UC statements. This means that there is still this second step to perform.


The model is sometimes/often overkill. As a developer, you do not have to apprehend the entire model complexity before yielding productivity.

Limitation on standard

Like in the JOOQ article about function and stored procedure extracting the meta-information can reach some limits when entering in vendor specific particularities.

Native DSL

There is a trend that states that SQL is the only DSL you need.
Why should you wrap it with other technology abstraction that limit its power?

Bye-Bye Domain Objects

...Welcome DTO.
I/O are by essence DTO (why should they be the exact reflection of a persistence layer?). This situation is just a specific exception.
This exception is widely used by multiple apps/framework (strong resuability but limitations).
Remark:
This article is not there to cover the 'everlasting-debate' DO vs. DTO.
SDD just brings a new approach that do not exclude but complement the DDD/Rev-Eng one.

Concretely

MinuteProject for release 0.8.1+ (mid-may-2012) will offer Statement-Driven-Development facilities.

  • The user will focus one SQL statement.
  • The output will be deduce by the execution of it.
  • The input will be easily configurable.

Example

Here is a simple configuration. Statement-model is the new node.

  <model>
    ...
      <statement-model>
           <queries>
               <query name="get address street">
                  <query-body><value><![CDATA[select * from address where addressid > ?]]></value></query-body>
                  <query-params>
                      <query-param name="identifier_Address" is-mandatory="false" type="INT" sample="1"></query-param>
                  </query-params>
               </query>
           </queries>
      </statement-model>
  </model>

This configuration should be enough to get:
  • Input bean
  • Output bean
  • Output list bean
  •  All the technology decoration ex for 
    • REST CXF: 
      • Resource bean with REST path
      • spring config
      • Native DAO
Demonstration will be shipped in Minuteproject next release (0.8.1).

Integrating with REST is pretty much statement-driven: basically you just need to know the URL + its I/O.

Conclusion

  • With SDD you focus on the statement and the I/O.
  • Minuteproject simplifies the rest (technology wrapper).






Tuesday, November 22, 2011

MinuteProject Telosys impedance matching

This article is to review couple of technical points of both generators, and see the different possibilities of integration.
My perception of Telosys is for the moment limited to what I learned at Devoxx presentation and what I've tried, so if I miss things, be keen to notify.

Telosys
  • Code generator
  • Based on DB
  • Performs enrichment via GUI(Eclispe plugin) in a phase called repository
  • Generates for a target framework (JEE, Ajax) developped by Telosys Team
  • Generates artefacts for entities (table) 
  • Metadata of template (name, ...) are store in text file
  • Use Velocity as a template rendering engine
Telosys goodies
  • JPA2 artefacts handle one2one relationship (not yet covered by minuteproject)
  • Telosys Plugin makes enrichment easy
Telosys neural
  • Targeting a specific 'Telosys Framework' solution as pros and cons
    • Pros 
      • fully customized
      • all in one inside IDE
    • Cons 
      • dev. burden on a team
      • no market place recognition
      • reusability of templates might be poor
Minuteproject
  • Code generator
  • Based on DB and WSDL based (next release: 0.7)
  • Performs enrichment via Configuration file or via a console
  • Generates for a range of market-place technologies
    • Spring/hibernate/ibatis/JPA1/JPA2
    • Openxava
    • Play
    • Grails
    • Roo
    • REST
    • Primefaces
    • FitNesse
    • ...
  • Generate for artifacts at 6 levels
    • Entity (tables/views)
    • Field
    • Package
    • Model
    • StoredProc
    • Application
  • Generated code can be updated and modifications are kept over consecutive generation
  • Metadata of template (name, 20 other attributes) are store in xml file 
  • Possibility to define convention:
    • Ex: view do not have PK but it is possible to define some individually or globally by applying a convention called 'apply-default-primary-key-otherwise-first-one'.
  • Use Velocity as a template rendering engine
Integration investigation tracks
Here are couple of feasible tracks under investigation:
  • Integrate Minuteproject tracks into Telosys
  • Add Telosys target as a MinuteProject 4 Telosys track
  • Add Telosys Plugin over Minuteproject generator

Monday, October 31, 2011

FitNessize your JEE dev with minuteproject


This article shows you how-to setup FitNesse in your development environment when dealing with Relation Database CRUD operations. MinuteProject 4 FitNesse generates entire set of FitNesse wiki pages and associated java fixtures allowing you to reset the database as well as performing intuitively CRUD operations on top of tables and Select on top of views.
To illustrate this MinuteProject track, the Database used comes from the Lazuly showcase.
The sources can be found under lazuly-fitnesse.
This page will show you:
  • FitNesse + Minuteproject operating mechanism in Agile development
  • How-to Generate CRUD fixture
  • Integrate then in your own scenario to gain QA
Overview




Install FitNesse and Generate A Custom CRUD wiki for you model
Prerequisites
  • Use Java 6
  • Install Lazuly DB (sql script here)
Installation
Download FitNesse
Execute java -jar fitnesse.jar
On a browser go to http://localhost to view the FitNesse wiki
Generate a FitNesse wiki for your model
  • Download MinuteProject
  • Generate using the following minuteproject configuration script: mp-config-LAZULY-FITNESSE.xml
  • Set this script in /mywork/config and run generate-model.(cmd/sh) mp-config-LAZULY-FITNESSE.xml
The mp-config-LAZULY-FITNESSE.xml configuration file
<!DOCTYPE root>
<generator-config>
 <configuration>
  <conventions>
   <target-convention type="enable-updatable-code-feature" />
  </conventions> 
  <model name="conference" version="1.0" package-root="net.sf.mp.demo">
   <data-model>
    <dataSource>
     <driverClassName>org.gjt.mm.mysql.Driver</driverClassName>
     <url>jdbc:mysql://127.0.0.1:3306/conference</url>
     <username>root</username>
     <password>mysql</password>
    </dataSource>
   </data-model>
   <business-model>
         <business-package default="conference">
             <condition type="package" startsWith="STAT" result="statistics"></condition>
             <condition type="package" startsWith="COUNTRY" result="admin"></condition>
             <condition type="package" startsWith="ROLE" result="admin"></condition>        
         </business-package>   
    <enrichment>
     <conventions>
         <view-primary-key-convention 
            type="apply-default-primary-key-otherwise-first-one" 
            default-primary-key-names="ID" >
         </view-primary-key-convention>
     </conventions>
    </enrichment>
   </business-model>
  </model>
  <targets> 
   <target refname="FitNesse" 
      name="default" 
      fileName="mp-template-config-fitnesse.xml" 
      outputdir-root="D:/DEV/LAZULY/lazuly-fitnesse"
      templatedir-root="../../template/framework/fitnesse">
   </target> 
   <target refname="LIB" 
      fileName="mp-template-config-bsla-LIB-features.xml" 
      templatedir-root="../../template/framework/bsla">
   </target>
  </targets>  

 </configuration>
</generator-config>
What is generated
Wiki Fixtures for CRUD operations


Wiki source to be copied in your FitNesse Root Directory
















FitNesse CRUD Wiki generated for you model.
Pick-up the snippet you need to:
  • SetUp you DB model
  • Perform sanity check 
    • after X UCs in a scenario, are my data correctly stored?
Lazuly FitNesse subwiki for select operations













Details of Select wiki fixtures for view 'stat_mb_by_role'
 
















Lazuly FitNesse subwiki for insert update delete operations











Details of Insert, Update, Delete wiki fixtures for table 'address'















Associated Java Fixture 























Assemble for your need
Build Java Fixture Project
Compile the code in an IDE
  • add src-generated to your source directories
  • add MP 4 FitNesse depencies libraries
    • For the moment they are provided in MP package under /target/fitnesse/ and /target/fitnesse/dep
  • Lazuly-fitnesse is shipped with an eclipse project that compiles the code to /bin
  • The compilation directory is to be reference by the FitNesse wiki path directives.
SetUp FitNesse Lazuly Wiki
Althought MinuteProject provides CRUD wiki ready to use, the purpose of this section is to setup a custom wiki that will be used for your UC.
  • Create your FitNesse Application Wiki HomePage
    • Edit main page add a section called 'FitNesseLazulyScenario'
      • Add snippet [[Lazuly][FitNesse.LazulyScenario]]
  • Click on Lazuly ? or go to http://localhost/FitNesse.LazulyScenario
  • Compose a simple structure
    • Simple structure proposal
      • HomePage section (define the path to use)
      • Setup section (Used to reset DB)
      • Data Definition section (Used to define common variables referenced in scenario)
      • Populate section (Used to initialize DB with data)
      • Couple of UC section
Write a sample scenario
This scenario will populate couple of tables of the Lazuly DB and check if the result expected in the views is correct.
HomePage section
Defines 
  • different pages (SetUp, VariableDefinition, UC sections) 
  • classpath

 
Setup section 
  • Reset Database
    • Reference Reset script executed by Scriptella (etl.xml)
      • Adapt the variable resetfilepathvar to point to your file path.
    • etl.xml references 3 sql script
      • reset_db.sql that proposed a Delete statement per table
        • It can be altered since the delete order might not be correct
        • In this case please add -- MP-MANAGED-STOP-GENERATING to prevent your modification to be lost for consecutive generation
      • insert_reference_data.sql
        • Add the data you wish
      • commit.sql that just perform a commit
  • Connection parameter to point to the database that include
    • DB URL
    • JDBC driver
    • Username
    • Password
  • All this code is generate in /ConferenceFitnesseWikiSetup/content.txt. It can also be copied from http://localhost/ConferenceFitnesseWikiSetup
 
Variable Definition section
Use Fitnesse directive !define to add relevant variable name for your scenario
Those variables will be later refered in your UCs

Populate section 
The SetUp page is automatically included at the beginning of your scenario.
But you have to reference the Variable Definition section. For that use the FitNesse directive !include (!include VariableDefinition)

Pick-up CRUD snippet from MP generated FitNesse Wiki to create you own customed DB initialization.
Insert reference data Country, Role
Insert business data: Address, Conference, ConferenceMember






 

















UC Check section
Pick-up CRUD snippet from MP generated FitNesse Wiki to create you own customed DB initialization.
In this case, I simply check that the data are stored correctly.
There is a view that gather BI information and I use it to validate the correctness of the information.


















Conclusion
This example shows that you can have use very easily CRUD fitnesse fixture (Zero LOC of development are required) customized for your data model.
To sum-up, here are the main points:
  • Reset DB
  • Initialize DB
  • Perform sanity check
  • Set-up FitNesse for your hadoc UCs for JEE data centric application


MinuteProject Spin-offs
At this point on you can guarante that the data retrieved from the view are correct.
That means that you have QA on your model.
If the views have a field containing unique values then you can benefit of MinuteProject spin-off i.e. use other track to generate out-of-the-box:
  • Web2.0 application in Openxava on top of views. See on this blog the following article 
  • REST application.
  • Web service application.
For Real UCs
Here the UCs demonstrated concern only CRUD operations on top of DB entities.
2 next articles in prepartion will show how to integrate with:
  • JPA2 ORM backend
  • Spring/JPA/Hibernate backend
Additional information
MinuteProject 4 FitNesse

Monday, July 11, 2011

JPA2 simple reverse-engineering via MP console

This article shows how quickly you can reverse-engineering for JPA2 via minuteproject console.

The console is just find to have a quick look at what you can expect.

The console has two catalogs:
  • One for the target DB (for the moment there are 4 of them Oracle, DB2, mysql, hsqldb)
  • One for the target technologies (there are couples such as JPA2, spring/hibernate/Jpa/DAO, grails, playframework, vaadin).
The DB catalog holds for each db parameters corresponding to its default configurations such as:
  • primary key (Oracle use sequence, Mysql autoincrement)
  • dialect (for hibernate or orm vendor specific)
  • jdbc driver class
  • maven driver artifacts
To add new DB just add some nodes in /catalog/database-catalog.xml and restart the console.
You can share your new configuration for DB with minuteproject to be included in the next release.

The technology catalog holds for each track the set of artifacts for the different level (field, entity, package, model, application) that is to be generated.

Here a little video illustrating how to use the console:

MinuteProject 4 JPA2: reverse-engineering via console from minuteproject on Vimeo.


If you want additional feature you have to use Minuteproject with a configuration file.


Monday, June 27, 2011

MinuteProject 4 JPA2: Lazuly showcase

Intro
The goal of this article is to have a working JPA2 layer on top of a data model by writting 0 (yes ZERO) lines of code.
Lazuly-db is a opensource database hosted on googlecode that represents the structure of a database holding conference related informations.
Lazuly-db will be used as a showcase of various MinuteProject technology tracks.
In version 0.1 it has 13 tables, 2 views.

This article explains the different steps to quickly have a working JPA2 backend.
It is furthermore a tutorial on how to enrich the database model to get customized artifacts providing specific behaviour.
The purpose is to give to user enough material to customize it and go on extending your model.

MinuteProject short story
The idea behind minuteproject is to
  • go fast;
  • reduce the technology learning curve by knowledge cristalization;
  • improve the quality of the artifact;
  • shorten drastically the time to market of the product.
Minuteproject acts as a Productivity provider targeting multiple aspects of the reverse-engineering for a target architecture (here JPA2).
While most of existing reverse-engineering solution focus on one part of your architecture (Domain Object), MinuteProject can generate artifacts related to:
  • columns;
  • entities (tables,views);
  • stored procedures;
  • package;
  • model;
  • application.
It allows the developer to achieve 'reproductability' that is a great complement of reusability.
Reusability allows to bundle common behavior into a package/framework/specification in order to use them but not to code them.
Reproductability allows to reach the same quality of artifacts (config/classes...) matching a target architecture (reused) although the context changes (DB model).

JPA2 track
JPA2 is a JEE specification for persisting objects in a database.
MinuteProject 4 JPA2 (release 0.5.5) offers a reverse-engineering solution targeting JPA2 artifacts:
  • Java Entity classes for tables and views;
  • JPA2 metamodel;
  • persistence xml;
  • maven pom.xml;
  • vendor specific implementation;
  • querydsl integration.
More information can be found at minuteproject4jpa2

Operating principle
MinuteProject works with a configuration file.
This file holds the information regarding the model and how to enrich it. It also specifies the target bundle of templates for a technology track.

Datasource
Lazuly DB main entities: The schema below resumes the lazuly DB main entities (tables/views) and theirs relationships.


This part summarizes the different configurations used:

Here is the sample xml configuration that is applied to the model
<!DOCTYPE root>
<generator-config>
<configuration>
<model name="conference" version="1.0" package-root="net.sf.mp.demo">
<!-- <model name="lazuly" version="1.0" package-root="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/conference</url>
<username>root</username>
<password>mysql</password>
</dataSource>
<!-- for Oracle and DB2 please set the schema <schema> </schema> -->
<primaryKeyPolicy oneGlobal="true">
<primaryKeyPolicyPattern name="autoincrementPattern"></primaryKeyPolicyPattern>
</primaryKeyPolicy>
</data-model>
<business-model>
<!-- <generation-condition> <condition type="exclude" startsWith="DUAL"></condition>
</generation-condition> -->
<business-package default="conference">
<condition type="package" startsWith="STAT" result="statistics"></condition>
<condition type="package" startsWith="COUNTRY" result="admin"></condition>
<condition type="package" startsWith="ROLE" result="admin"></condition>
</business-package>
<enrichment>
<conventions>
<column-naming-convention type="apply-strip-column-name-suffix"
pattern-to-strip="_ID" />
<reference-naming-convention
type="apply-referenced-alias-when-no-ambiguity" is-to-plurialize="true" />
</conventions>

<entity name="PRESENTATION">
<field name="STATUS">
<property tag="checkconstraint" alias="presentation_status">
<property name="PROPOSAL" value="PROPOSAL" />
<property name="ACTIVE" value="ACTIVE" />
</property>
</field>
</entity>
<entity name="SPONSOR">
<field name="STATUS">
<property tag="checkconstraint" alias="sponsor_status">
<property name="PENDING" value="PENDING" />
<property name="ACTIVE" value="ACTIVE" />
</property>
</field>
<field name="PRIVILEGE_TYPE">
<property tag="checkconstraint" alias="sponsor_privilege">
<property name="GOLDEN" value="Golden" />
<property name="SILVER" value="Silver" />
<property name="BRONZE" value="Bronze" />
</property>
</field>
</entity>
<!-- views -->
<entity name="stat_mb_per_ctry_conf" alias="MEMBER_PER_COUNTRY_AND_CONFERENCE">
<virtual-primary-key isRealPrimaryKey="true">
<property name="virtualPrimaryKey" value="ID" />
</virtual-primary-key>
</entity>
<entity name="stat_mb_by_role" alias="MEMBER_PER_ROLE_COUNTRY_AND_CONFERENCE">
<virtual-primary-key isRealPrimaryKey="true">
<property name="virtualPrimaryKey" value="id" />
</virtual-primary-key>
<field name="stat_mb_per_ctry_conf_ID" linkToTargetEntity="stat_mb_per_ctry_conf"
linkToTargetField="id"></field>
</entity>
</enrichment>
</business-model>
</model>
<targets>

<target refname="JPA2" fileName="mp-template-config-JPA2.xml"
outputdir-root="../../dev/output/JPA2" templatedir-root="../../template/framework/jpa">
<property name="add-querydsl" value="2.1.2"></property>
<property name="add-jpa2-implementation" value="hibernate"></property>
</target>

<target refname="LIB" fileName="mp-template-config-bsla-LIB-features.xml"
templatedir-root="../../template/framework/bsla">
</target>

</targets>
</configuration>
</generator-config>
The configuration provides:
  • A model name: conference, version and package root;
  • the driver as maven reference;
  • connection parameters;
  • primarykey policy (autoincrement)
  • business packages: entities starting with stat go to 'statistics'...;role, countries goes in administration package
  • convention: strip-column-name-suffix _ID (by convention in the database, I have column naming ending with '_ID' for foreign key. Here the Java naming convention can defer from the DB naming
  • convention: apply-referenced-alias-when-no-ambiguity indicating that when a table has a one2many relationship with other (i.e. has child), if it has not 2 children with the same other side table (no ambiguity) than the name of the variable is based on the other side table, and plurialized (english) collections
  • Entity enrichment: name alias (can have a distinct Java class name than the one derived from the DB);
  • Field enrichment: provide a check constraint that becomes a Java Enum
  • Entity (views) enrichment by providing them a primary key (create a unique key) by adding foreignkey.
The target part of the configuration specifies against which target technology, MinuteProject has to generate. Here the track is JPA2, where it is specified to use querydsl 2.1.2 and a JPA vendor implementation Hibernate.
Those indications are used to generate pom.xml and persistence.xml files.

Sources and installation
Lazuly project
Svn the source as describe on http://code.google.com/p/lazuly/source/checkout

Mysql
Install mysql
run conference-db.0.1.sql on schema conference

Minuteproject
Download and install minuteproject 0.5.5 or higher. Minuteproject is installed in MP_HOME.

Execution
Normally within couple of seconds (1 to 5) the code should be generated (If DB instance and minuteproject run is on same machine)

Alternate execution
  • Open minuteproject console %MP_HOME%/bin/start-console.(cmd/sh)
  • field the connection parameters
  • add package root and model name
  • click generate
This alternative generation works fine to give a first glance at what you can have as output. A better enrichment is available via the xml config as previously described.

Output
The output can be browsed at http://code.google.com/p/lazuly/source/browse/#svn%2Ftrunk%2Flazuly-jpa2

Here are some samples of what has been generated in terms of

Structure
Here the structure open with as an eclipse-maven project


Java class as JPA2 entity with enumeration, OneToMany, ManyToOne, ManyToMany
You can note that the field 'abstract' in the table 'presentation' is converted to 'abstractName' to avoid compilation error. This is true for all the java reserved keywords. The getter and setter are adapted accordingly.
package net.sf.mp.demo.conference.conference;

import java.sql.*;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;

import javax.persistence.*;

import net.sf.mp.demo.conference.conference.Evaluation;
import net.sf.mp.demo.conference.conference.PresentationPlace;
import net.sf.mp.demo.conference.conference.Speaker;
import net.sf.mp.demo.conference.enumeration.conference.PresentationStatusEnum;

/**
*
* <p>Title: Presentation</p>
*
* <p>Description: Domain Object describing a Presentation entity</p>
*
*/
@Entity (name="Presentation")
@Table (name="presentation")
public class Presentation {

@Id @Column(name="id" )
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@Column(name="start_time", nullable=false, unique=false)
private Timestamp startTime;
@Column(name="end_time", nullable=false, unique=false)
private Timestamp endTime;
@Column(name="abstract", length=500, nullable=false, unique=false)
private String abstractName;
@Column(name="title", length=255, nullable=false, unique=false)
private String title;
@Enumerated (EnumType.STRING)
private PresentationStatusEnum status;
@Column(name="proposal_time", nullable=true, unique=false)
private Timestamp proposalTime;

@ManyToOne (fetch=FetchType.LAZY )
@JoinColumn(name="presentation_place_id", referencedColumnName = "id", nullable=true, unique=false )
private PresentationPlace presentationPlaceId;

@OneToMany (targetEntity=net.sf.mp.demo.conference.conference.Evaluation.class, fetch=FetchType.LAZY, mappedBy="presentationId", cascade=CascadeType.REMOVE)//, cascade=CascadeType.ALL)
private Set <Evaluation> evaluations = new HashSet<Evaluation>();

@ManyToMany
@JoinTable(name="SPEAKER_PRESENTATION",
joinColumns=@JoinColumn(name="presentation_id"),
inverseJoinColumns=@JoinColumn(name="speaker_id")
)
private Set <Speaker> speakers = new HashSet <Speaker> ();

/**
* Default constructor
*/
public Presentation() {
}

public Long getId() {
return id;
}

public void setId (Long id) {
this.id = id;
}

public Timestamp getStartTime() {
return startTime;
}

public void setStartTime (Timestamp startTime) {
this.startTime = startTime;
}

public Timestamp getEndTime() {
return endTime;
}

public void setEndTime (Timestamp endTime) {
this.endTime = endTime;
}

public String getAbstractName() {
return abstractName;
}

public void setAbstractName (String abstractName) {
this.abstractName = abstractName;
}

public String getTitle() {
return title;
}

public void setTitle (String title) {
this.title = title;
}

public PresentationStatusEnum getStatus() {
return status;
}

public void setStatus (PresentationStatusEnum status) {
this.status = status;
}

public Timestamp getProposalTime() {
return proposalTime;
}

public void setProposalTime (Timestamp proposalTime) {
this.proposalTime = proposalTime;
}

public PresentationPlace getPresentationPlaceId () {
return presentationPlaceId;
}

public void setPresentationPlaceId (PresentationPlace presentationPlaceId) {
this.presentationPlaceId = presentationPlaceId;
}

public Set<Evaluation> getEvaluations() {
if (evaluations == null){
evaluations = new HashSet<Evaluation>();
}
return evaluations;
}

public void setEvaluations (Set<Evaluation> evaluations) {
this.evaluations = evaluations;
}

public void addEvaluations (Evaluation evaluation) {
getEvaluations().add(evaluation);
}

public Set<Speaker> getSpeakers() {
if (speakers == null){
speakers = new HashSet<Speaker>();
}
return speakers;
}

public void setSpeakers (Set<Speaker> speakers) {
this.speakers = speakers;
}

public void addSpeakers (Speaker speakers) {
getSpeakers().add(speakers);
}
}

Enumeration
You can note the 'equals (string s)' method which is quite handy.
package net.sf.mp.demo.conference.enumeration.conference;

import java.util.ArrayList;
import java.util.List;

public enum SponsorPrivilegeTypeEnum {

GOLDEN("Golden"),
SILVER("Silver"),
BRONZE("Bronze");

private final String value;

SponsorPrivilegeTypeEnum(String v) {
value = v;
}

public String value() {
return value;
}


public static SponsorPrivilegeTypeEnum fromValue(String v) {
for (SponsorPrivilegeTypeEnum c : SponsorPrivilegeTypeEnum.values()) {
if (c.value.equals(v)) {
return c;
}
}
return null;
}


/**
* Return a list that contains all the enumeration values
* @return List<SponsorPrivilegeTypeEnum> the that contains all the enumeration values
*/
public static List<SponsorPrivilegeTypeEnum> getList() {
List<SponsorPrivilegeTypeEnum> list = new ArrayList<SponsorPrivilegeTypeEnum>();
for (SponsorPrivilegeTypeEnum c : SponsorPrivilegeTypeEnum.values()) {
list.add(c);
}
return list;
}

/**
* @param value
* @return boolean : true if the value exist in the enum
*/
public static boolean contains (String value) {
for (SponsorPrivilegeTypeEnum c : SponsorPrivilegeTypeEnum.values()) {
if (c.toString().equals(value))
return true;
}
return false;
}

public static boolean containsValue (String value) {
for (SponsorPrivilegeTypeEnum c : SponsorPrivilegeTypeEnum.values()) {
if (c.value().equals(value))
return true;
}
return false;
}

public boolean equals (String s) {
if (s==null) return false;
return s.equals(value);
}

}
Java class as JPA2 entity for view
You can note the enrichment performed is translated into different Java and DB naming conventions for the entity itself as well as its dependencies.
Now you can use the view for all the JPA2 select operations.
package net.sf.mp.demo.conference.statistics;

import java.sql.*;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;

import javax.persistence.*;

import net.sf.mp.demo.conference.statistics.MemberPerRoleCountryAndConference;

/**
*
* <p>Title: MemberPerCountryAndConference</p>
*
* <p>Description: Domain Object describing a MemberPerCountryAndConference entity</p>
*
*/
@Entity (name="MemberPerCountryAndConference")
@Table (name="stat_mb_per_ctry_conf")
public class MemberPerCountryAndConference {

@Id @Column(name="id" ,length=300)
private String id;

@Column(name="country", length=45, nullable=false, unique=false)
private String country;
@Column(name="conference_name", length=255, nullable=false, unique=false)
private String conferenceName;
@Column(name="number", nullable=false, unique=false)
private Long number;

@OneToMany (targetEntity=net.sf.mp.demo.conference.statistics.MemberPerRoleCountryAndConference.class, fetch=FetchType.LAZY, mappedBy="statMbPerCtryConfId", cascade=CascadeType.REMOVE)//, cascade=CascadeType.ALL)
private Set <MemberPerRoleCountryAndConference> memberPerRoleCountryAndConferences = new HashSet<MemberPerRoleCountryAndConference>();

/**
* Default constructor
*/
public MemberPerCountryAndConference() {
}

public String getId() {
return id;
}

public void setId (String id) {
this.id = id;
}

public String getCountry() {
return country;
}

public void setCountry (String country) {
this.country = country;
}

public String getConferenceName() {
return conferenceName;
}

public void setConferenceName (String conferenceName) {
this.conferenceName = conferenceName;
}

public Long getNumber() {
return number;
}

public void setNumber (Long number) {
this.number = number;
}

public Set<MemberPerRoleCountryAndConference> getMemberPerRoleCountryAndConferences() {
if (memberPerRoleCountryAndConferences == null){
memberPerRoleCountryAndConferences = new HashSet<MemberPerRoleCountryAndConference>();
}
return memberPerRoleCountryAndConferences;
}

public void setMemberPerRoleCountryAndConferences (Set<MemberPerRoleCountryAndConference> memberPerRoleCountryAndConferences) {
this.memberPerRoleCountryAndConferences = memberPerRoleCountryAndConferences;
}

public void addMemberPerRoleCountryAndConferences (MemberPerRoleCountryAndConference memberPerRoleCountryAndConference) {
getMemberPerRoleCountryAndConferences().add(memberPerRoleCountryAndConference);
}

}

Run
Since it generate a pom.xml, download maven and run 'mvn install'
It generates the lazuly backend jar containing the entities, the metamodel and the querydsl classes.

MinuteProject 4 Openxava: Lazuly showcase

Intro
The goal of this article is to have a working Openxava on top of a data model by writting 0 (yes ZERO) lines of code. This application has to run as a standalone webapp or as portlets in a portal.
The model used is the Lazuly-db which is a opensource database hosted on googlecode that represents the structure of a database holding conference related informations.
Lazuly-db will be used as a showcase of various MinuteProject technology tracks.
In version 0.1 it has 13 tables, 2 views.

This article explains the different steps to quickly have a create an Openxava application.
It is furthermore a tutorial on how to enrich the database model to get customized Openxava artifacts providing specific behaviour.
The purpose is to give to user enough material to customize it and go on extending your model.

If you want to see the result quickly, I encourage you to see the videos (downwards on this page).

OpenXava
Is an opensource product that makes CRUD RIA modal application in a very quick way.
It enforces the DRY principle with a comprehensive set of annotations.
Openxava is a generic framework that dynamically generates the presentation layer based on custom annotation.

MinuteProject 4 Openxava offers a reverse-engineering solution targeting OX architecture.
Here are the set of artifacts MinuteProject will generate:
  • JPA2 and OpenXava annotated entities;
  • associated metamodel;
  • drop down list artifacts for enumeration;
  • Navigation menu;
  • build script (windows and unix);
  • tomcat datasouce configuration snippet and context.xml;
  • internationalisation.

Operating principle
MinuteProject works with a configuration file.
This file holds the information regarding the model and how to enrich it. It also specifies the target bundle of templates for a technology track (here Openxava).

Datasource
Lazuly DB main entities: The schema below resumes the lazuly DB main entities (tables/views) and theirs relationships.


Configuration
This part summarizes the different configurations used:

<!DOCTYPE root>
<generator-config>
<configuration>
<model name="conference" 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/conference</url>
<username></username>
<password></password>
</dataSource>
<!--
for Oracle and DB2 please set the schema <schema> </schema>
-->
<primaryKeyPolicy oneGlobal="true">
<primaryKeyPolicyPattern name="autoincrementPattern"></primaryKeyPolicyPattern>
</primaryKeyPolicy>
</data-model>
<business-model>
<!--
<generation-condition> <condition type="exclude"
startsWith="DUAL"></condition> </generation-condition>
-->
<business-package default="conference">
<condition type="package" startsWith="STAT" result="statistics"></condition>
<condition type="package" startsWith="COUNTRY" result="admin"></condition>
<condition type="package" startsWith="ROLE" result="admin"></condition>
</business-package>
<enrichment>
<conventions>
<column-naming-convention type="apply-strip-column-name-suffix"
pattern-to-strip="_ID" />
<reference-naming-convention
type="apply-referenced-alias-when-no-ambiguity" is-to-plurialize="true" />
</conventions>

<entity name="COUNTRY" content-type="reference-data">
<semantic-reference>
<sql-path path="NAME" />
</semantic-reference>
</entity>
<entity name="CONFERENCE_MEMBER">
<semantic-reference>
<sql-path path="FIRST_NAME" />
<sql-path path="LAST_NAME" />
</semantic-reference>
<field name="STATUS">
<property tag="checkconstraint" alias="conference_member_status">
<property name="PENDING" value="PENDING" />
<property name="ACTIVE" value="ACTIVE" />
</property>
</field>
<field name="EMAIL">
<stereotype stereotype="EMAIL" />
</field>
</entity>
<entity name="SPEAKER">
<field name="BIO">
<stereotype stereotype="HTML_TEXT" />
</field>
<field name="PHOTO">
<stereotype stereotype="PHOTO" />
</field>
<field name="WEB_SITE_URL">
<stereotype stereotype="WEBURL" />
</field>
</entity>
<entity name="PRESENTATION">
<field name="STATUS">
<property tag="checkconstraint" alias="presentation_status">
<property name="PROPOSAL" value="PROPOSAL" />
<property name="ACTIVE" value="ACTIVE" />
</property>
</field>
</entity>
<entity name="SPONSOR">
<field name="STATUS">
<property tag="checkconstraint" alias="sponsor_status">
<property name="PENDING" value="PENDING" />
<property name="ACTIVE" value="ACTIVE" />
</property>
</field>
<field name="PRIVILEGE_TYPE">
<property tag="checkconstraint" alias="sponsor_privilege">
<property name="GOLDEN" value="Golden" />
<property name="SILVER" value="Silver" />
<property name="BRONZE" value="Bronze" />
</property>
</field>
</entity>
<!-- views -->
<entity name="stat_mb_per_ctry_conf" alias="MEMBER_PER_COUNTRY_AND_CONFERENCE">
<virtual-primary-key isRealPrimaryKey="true">
<property name="virtualPrimaryKey" value="ID" />
</virtual-primary-key>
</entity>
<entity name="stat_mb_by_role" alias="MEMBER_PER_ROLE_COUNTRY_AND_CONFERENCE">
<virtual-primary-key isRealPrimaryKey="true">
<property name="virtualPrimaryKey" value="id" />
</virtual-primary-key>
<field name="stat_mb_per_ctry_conf_ID" linkToTargetEntity="stat_mb_per_ctry_conf"
linkToTargetField="id"></field>
</entity>
</enrichment>
</business-model>
</model>
<targets>
<!-- openxava -->
<target refname="OpenXava" name="OpenXava"
fileName="mp-template-config-openxava-last-features.xml"
outputdir-root="../../DEV/output/openxava/conference"
templatedir-root="../../template/framework/openxava">
</target>

<target refname="JPA2-LIB" fileName="mp-template-config-JPA2-LIB.xml"
templatedir-root="../../template/framework/jpa">
</target>

<target refname="BSLA-LIB" fileName="mp-template-config-bsla-LIB-features.xml"
templatedir-root="../../template/framework/bsla">
</target>

</targets>
</configuration>
</generator-config>

Errata

Minuteproject and OpenXava are in constant evolution and at some stage there might be some temporary fix to apply in the configuration

This version works for MP version 0.5.x
For version above 0.6 add
   <target refname="CACHE-LIB" 
      fileName="mp-template-config-CACHE-LIB.xml" 
      templatedir-root="../../template/framework/cache">
   </target>
 
On MP 0.8.2 the semantic reference node on 'CONFERENCE_MEMBER' entity is to comment.




Configuration explained
If you have read the minuteproject 4 JPA2 lazuly showcase article on this blog, you would notice that the configuration is similar to the one for JPA2 track. It is the case for everything regarding the model location (same model) and the enrichment, meanwhile it defers regarding the target, since it uses OpenXava.

The configuration provides:
  • A model name: conference, version and package root;
  • the driver as maven reference;
  • connection parameters;
  • primarykey policy (autoincrement)
  • business packages: entities starting with stat go to 'statistics'...;role, countries goes in administration package. Those will be converted into distinct menu tabs.
  • convention: strip-column-name-suffix _ID (by convention in the database, I have column naming ending with '_ID' for foreign key. Here the Java naming convention can defer from the DB naming
  • convention: apply-referenced-alias-when-no-ambiguity indicating that when a table has a one2many relationship with other (i.e. has child), if it has not 2 children with the same other side table (no ambiguity) than the name of the variable is based on the other side table, and plurialized (english) collections
  • Entity enrichment: name alias (can have a distinct Java class name than the one derived from the DB);
  • Field enrichment: provide a check constraint that becomes an Openxava drop down list
  • Entity (views) enrichment by providing them a primary key (create a unique key) by adding foreignkey. In this way we can have an alternative navigation model on top of some BI views.
  • Tag field content-type="reference-data" apply to ROLE and COUNTRY entry will trigger the following navigation behavior: you cannot navigation from a role entry to children CONFERENCE_MEMBER in the application, but form CONFERENCE_MEMBER you can associate roles.
  • stereotype="EMAIL" will be converted in its associated email stereotype on Openxava triggering email format validation, same for WEB_SITE_URL
  • stereotype="HTML_TEXT" applied to SPEAKER.BIO field will be converted in its associated html_text stereotype on Openxava offering a Rich text format facility
  • stereotype="PHOTO" applied to SPEAKER.PHOTO field will be converted in file upload facility by Openxava
Additional information on how to enrich the model can be found at
Sources and installation
Lazuly project
Svn the source as describe on http://code.google.com/p/lazuly/source/checkout

Mysql
Install mysql
run conference-db.0.1.sql on schema conference

Minuteproject
Download and install minuteproject 0.5.5. Minuteproject is installed in MP_HOME.

Openxava
Download and install openxava 4.1.2. Openxava is installed in OX_HOME.
Remark
This demo is based on OX 4.1.2, if you are using a more recent version there may not be foreward compatibility. Release (MP 0.5.6 will be compliant with OX 4.2.1). In fact there is one artifact generated home.jsp that is based on OX module.jsp. If this artifact changes between OX release, there is potentially an error.

Generation
The resulting generated code goes to %MP_HOME%/DEV/output/openxava/conference

Structure of the Openxava project
Here the structure open with as an eclipse project in the openxava workspace


Execution
  • check mysql.jar is in tomcat/lib
  • check that the system variables: ox_home, mp_home are set to Openxava and MinuteProject installation directories.
Open a prompt on /DEV/output/openxava/conference, and execute build-conference.cmd.
It will
  • Create an Openxava project
  • Build openxava web app
  • Build openxava portlets (to be deployed on a portal such as Liferay)
  • Copy context.xml (take care that it overwrite the existing one)
  • Start tomcat
  • Deploy the application
  • Start you default browser to the Conference Home menu.
The enjoy the navigation.

Videos

Video starting from scratch to deployed application




Video of the resulting application