Wednesday, May 23, 2012

RigaJUG - demo - instant OPENXAVA app

From the following model called Tranxy

we'll generate instantly an Openxava app.

The interesting part of this demo is the enrichment of the model, it is described Riga demo 2 (The main complexity comes by having 2 tables (language and user) linked by 2 many-to-many).

Actions

There are four simple actions make it happened:
  • Drop TRANXY-OPENXAVA.xml in /mywork/config and run: model-generation.cmd/sh TRANXY-OPENXAVA.xml
  • In /output/OPENXAVA set the 2 environment variables
    • set OX_HOME=../openxava-4.4.1 (export on unix)
    • set MP_HOME=../minuteProject-0.8.1 (export on unix)
  • execute >build-tranxy.cmd/sh
And that's it!
Last action will 
  • create an Openxava project
  • build it (portlet included ready for Liferay)
  • start Openxava embedded tomcat server
  • add connection datasource
  • deploy the build application on tomcat
  • start a browser connection at  http://localhost:8080/tranxy/xava/homeMenu.jsp where the menu is.

The application works on an empty database, you can use the Openxava-Minuteproject-generated-app to
populate it...
Enjoy!

Prerequisits

MinuteProject installed 
Openxava installed 
Ant installed
Model Tranxy (script) installed on an up-and-running Mysql server
Java 1.6

Configuration

TRANXY-OPENXAVA.xml
<!DOCTYPE root>
<generator-config xmlns="http://minuteproject.sf.net/xsd/mp-config" 
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
xs:noNamespaceSchemaLocation="../config/mp-config.xsd">
    <configuration>
        <conventions>
            <target-convention type="enable-updatable-code-feature" />
        </conventions>
        <model name="tranxy" 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/tranxy</url>
                    <username>root</username>
                    <password>mysql</password>
                </dataSource>
                <primaryKeyPolicy oneGlobal="false" >
                    <primaryKeyPolicyPattern name="autoincrementPattern"></primaryKeyPolicyPattern>
                </primaryKeyPolicy>
            </data-model>
            <business-model>
                <business-package default="tranxy">
                    <condition type="package" startsWith="trans" result="translation"></condition>
                </business-package>
            <enrichment>
             <conventions>
              <!-- manipulate the structure and entities BEFORE manipulating the 
               entities -->
              <column-naming-convention type="apply-fix-primary-key-column-name-when-no-ambiguity" 
                      default-value="ID"/>  
              <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" />
              <reference-naming-convention type="apply-many-to-many-aliasing" is-to-plurialize="true"/>
             </conventions>
                  <entity name="language_x_translator">
                      <field name="language_id" linkReferenceAlias="translating_language" linkToTargetEntity="LANGUAGE"/>
                      <field name="user_id" linkReferenceAlias="translator" linkToTargetEntity="USER"/>
                  </entity>
                  <entity name="LANGUAGE_X_SPEAKER">
                      <field name="LANGUAGE_ID" linkToTargetEntity="LANGUAGE"
                          linkToTargetField="IDLANGUAGE" linkReferenceAlias="spoken_language" />
                      <field name="user_id" linkReferenceAlias="speaker" linkToTargetEntity="USER"/>
                  </entity>
                  <entity name="APPLICATION" alias="registered application">
                      <field name="TYPE" alias="obedience">
                          <property tag="checkconstraint" alias="application_type">
                              <property name="OPENSOURCE"/>
                              <property name="COPYRIGHT" />
                          </property>
                      </field>
                  </entity>
                  <entity name="LANGUAGE" content-type="reference-data"/>
            </enrichment>
            </business-model>
        </model>
        <targets>
        
            <target refname="OpenXava" 
               name="OpenXava" 
               fileName="mp-template-config-openxava-last-features.xml" 
               outputdir-root="../../dev/latvianjug/output/OPENXAVA"
               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="CACHE-LIB" 
               fileName="mp-template-config-CACHE-LIB.xml" 
               templatedir-root="../../template/framework/cache">
            </target>
            <target refname="LIB" 
               fileName="mp-template-config-bsla-LIB-features.xml" 
               templatedir-root="../../template/framework/bsla">
            </target>

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

Screenshots

Add an application

Customise Translation Column




No comments:

Post a Comment