Liferay is a opensource portal enabling admin to deploy portlets.
Portlets can be generated by minuteproject on the following tracks
  • openxava
  • primefaces (portlet in 0.8.5)
  • vaadin (portlet in 0.8.5)

Liferay proposes also a tool called Service Builder that speed-up portlet creation by generating backend service artifacts (match spring and hibernate technologies).
It works based on an input configuration file called service.xml holding the definition of the persistence unit. It looks like a light ORM definition enriched by Liferay and development facility information. The input file is then processed by a ant task to generate the Liferay compliant artifacts.
The input promotes a Domain-Driven-Approach.

The study shows the feasibility to generate the input file service.xml
MinuteProject 4 Liferay will generate the service builder info using smart reverse-engineering for table and view objects.

Limitations

This track provides a service.xml artifacts to operate with Liferay-plugin and service builder generation.
For certain model you may face service-builder/liferay-plugin limitations (cyclic reference, big model)

Prerequisits

Since Minuteproject generated artifacts are dependent on Liferay. Liferay infrastructure has to be set-up.
  • Liferay server
  • Liferay SDK
  • Liferay IDE (eclipse distrib + Liferay plugin)

Minuteproject Configuration

To use minuteproject 4 liferay track, just add the value 'Liferay' to the attribute catalog-entry' in the node 'targets'

<generator-config>
     <configuration>
      ....
     <targets catalog-entry="Liferay" />
     </configuration>
</generator-config>

Experiment


File mp-config-liferay.xml
<!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>
        <model name="petshop" version="1.0" package-root="net.sf.mp.demo.jpa2">
            <data-model>
                <driver name="hsqldb" version="1.8.0.7" groupId="hsqldb" artifactId="hsqldb"></driver>
                <fileSource name="petshop" dir="c:/MinuteProject/data">
                </fileSource>
                <dataSource>
                    <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
                     <url>jdbc:hsqldb:hsql://127.0.0.1:9001/petshop</url> -->
                    <username>sa</username>
                    <password></password>
                </dataSource>
                <!-- for Oracle and DB2 please set the schema
                <schema> </schema>
                 -->
                <primaryKeyPolicy oneGlobal="true" oneForEachTable="false">
                    <primaryKeyPolicyPattern name="sequencePattern" sequenceName="hibernate_sequence"/>
                </primaryKeyPolicy>
            </data-model>
            <business-model>
                 <generation-condition>
                    <condition type="exclude" startsWith="DUAL"></condition>
                     <condition type="exclude" endsWith="_GEN"></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"/>
                      <column-naming-convention type="apply-fix-primary-key-column-name-when-no-ambiguity" default-value="ID"/>
                      <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" >
                       <semantic-reference>
                         <sql-path path="NAME"/>
                       </semantic-reference>
                    </entity>
                </enrichment>
            </business-model>
        </model>
         <targets catalog-entry="Liferay" >
        </targets>
    </configuration>
</generator-config>

//TODO explanation

Generation

cmd line
model-generation mp-config-liferay.xml

The ouput goes to ../output/liferay/petshop

If you have a liferay project and want the service.xml to goes straight into your Liferay project add outputdir-root attribute to not targets

<generator-config>
     <configuration>
      ....
     <targets catalog-entry="Liferay" outputdir-root="$pathToyourLiferayProject" />
     </configuration>
</generator-config>

Output Results

Place the resulting service.xml file into your liferay project (WEB-INF dir) and open it.

Service builder main view

On petshop DB, notice
  • Many to Many table Tag_Item is not present
  • Table names in DB can differ from your entity name (ex: Item -> MyGoodItem via enrichment)
service-builder-petshop.png

Field mapping

  • simple field, DB column name can differ from Entity attribute (ex: ITEM.ITEM_ID -> MyGoodItem.id)
  • foreign key
  • reference gives collections

liferay-sb-mapping-petshop.png

Primary key strategy

Couple of strategies are available
  • natural
  • uuid
  • sequence
  • autoincrement
  • identity

liferay-sb-aliasing-and-pk-petshop.png

Finder

Some finders can be deduced by enrichment, via the semantic reference of the entity. Ex name for category

liferay-sb-finder-petshop.png

Result

Liferay service builder plugin can generate/compile/package your service.

liferay-sb-result-petshop.png