developing jspresso

12 posts / 0 new
Last post
henrik.b
Offline
Joined: 08/02/2010
developing jspresso

using svn checkout as mentioned on http://www.jspresso.org/page/jspresso-download-area

I checked out 3.5-rc1 as of yesterday.

In an attempt to teach jspresso to use legacy tables I have ventured out and are trying to fix the sources.

What is the best way to integrate my own-build jspresso version into build of the helloworld application ?

 

If I add new parameters for the Entity, do I need to change the groovy generator or is it enough to add the new stuff to the class AbstractcomponentDescriptor.java ?

 

I would be interested in feedback to my current plan:

Add legacyTable and legacyPrimarykeysto entity properties:
Entity('T1', legacyTable:'T1_DBA', legacyPrimarykeys:['a','b']
  )
{ String a
  String b
  String c
}

should generate:

Entity T1 with ID,VERSION,a,b,c

DB table T1_jspresso with columns( ID, VERSION, a,b) primary key(ID)
DB view T1 as select j.ID,j.VERSION,j.a,j.b,d.c from T1_jspresso j inner join T1_DBA d on j.a=d.a and j.b=d.b
DB triggers on view T1
  - INSTEAD of INSERT,UPDATE,DELETE
DB foreign keys on T1_jspresso Referencing T1_DBA on (a,b)
  - ON DELETE cascade
DB index on T1_jspresso columns (a,b)

Probably also need an option to populate the T1_jspresso table.

 

thanks for your help

Henrik

vvandens
Offline
Joined: 05/29/2008
developing jspresso

Hi Henrik,

You don't have to change anything in Jspresso itself to use your custom extended entity descriptor. However, you won't be able to directly leverage their use in SJS since the DSL is not (yet) extensible. However, you can bypass SJS, at least to test your extensions and then submit them so that they can find a way to the codebase and get included in the DSL. To achieve that, you will directly use Spring to configure your entity descriptor (as it was achieved before 3.5).

So here are the steps :

1/ Create your custom entity descriptor

In the core module of your test project, create a subclass of org.jspresso.framework.model.descriptor.entity.basic.BasicEntityDescriptor (lets call it your.custom.package.ExtendedEntityDescriptor) and add your new properties along with their accessors (legacyTable and legacyPrimaryKeys).

 

2/ Use the custom entity descriptor in your Spring model context

Describe entities using your new extended descriptor in the core/src/main/resources/org/jspresso/hrsample/model/model.xml Spring context file. The definitions placed here can override/extend the SJS definitions. As a starting point, you can start from what's generated by SJS in core/target/generated-resources/dsl/org/jspresso/hrsample/model/dsl-model.xml and copy/paste/modify the entities descriptions. Here is an example using the City entity description of HR Sample (directly taken from generated dsl-model.xml). In bold red, the customizations :

  <bean id="City" class="org.jspresso.framework.model.descriptor.entity.basic.BasicEntityDescriptor">
<bean id="City" class="your.custom.package.ExtendedEntityDescriptor">
<constructor-arg value="org.jspresso.hrsample.model.City" />
<property name="ancestorDescriptors">
<list>
<ref bean="Nameable" />
</list>
</property>
<property name="iconImageURL" value="classpath:org/jspresso/hrsample/images/city-48x48.png" />
<property name="propertyDescriptors">
<list>
<bean class="org.jspresso.framework.model.descriptor.basic.BasicStringPropertyDescriptor">
<property name="name" value="zip" />
<property name="maxLength" value="10" />
</bean>
</list>
</property>
<property name="legacyTable" value="T1_DBA">
<property name="legacyPrimaryKeys">
<list>
<value>a</value>
<value>b</value>
</list>
</property>

</bean>

Now you have your custom description available for custom generation.

 

3/ Leverage your customizations using an extended Freemarker template to generate the new XDoclet tags

You can change the template used to generate the entity classes and then leverage the new properties you've added into your ExtendedEntityDescriptor.

Create a new template into your project core module (for instance core/src/main/resources/my/template/ExtendedEntityTemplate.ftl). Copy/paste the content of the default one. Modify the template to generate the new XDoclet tags based on the values of the legacyTable and legacyPrimaryKeys.

 

4/ Instruct the build to use the customized template

mvn -Dgenerator.templateResourcePath=/my/template -Dgenerator.templateName=ExtendedEntityTemplate.ftl clean package

 

 

Let us know how it goes !

Vincent

henrik.b
Offline
Joined: 08/02/2010
ExtendedEntityDescriptor ...

Ok, trying this, but something is not correct.

 

1) Ok.

package ext.legacytables;
import org.jspresso.framework.model.descriptor.entity.basic.*;

public class ExtendedEntityDescriptor extends BasicEntityDescriptor

{ private String legacyTable;
  public ExtendedEntityDescriptor(String name) {   super(name);  }
  public void setLegacyTable(String tb)  { this.legacyTable=tb; }
  public String getLegacyTable()   { return this.legacyTable; }
}

 

2) model.xml

Here something is not working as expected. In the resulting entity generation the Event entity is not included. Probably due to errors in the bean or some where else. The output from maven does not give any obvious hints where the error could be.

Is it possible to enable a trace to see what could be wrong ?

   <bean
      id="Event"
      class="ext.legacytables.ExtendedEntityDescriptor">
      <constructor-arg
         value="com.example.helloworld.model.Event" />
      <property
         name="ancestorDescriptors">
         <list>
            <ref
               bean="Traceable" />
         </list>
      </property>
      <property
         name="propertyDescriptors">
         <list>
            <bean
               class="org.jspresso.framework.model.descriptor.basic.BasicStringPropertyDescriptor">
               <property
                  name="name"
                  value="name" />
               <property
                  name="maxLength"
                  value="255" />
            </bean>
            <bean
               class="org.jspresso.framework.model.descriptor.basic.BasicStringPropertyDescriptor">
               <property
                  name="name"
                  value="objecttype" />
               <property
                  name="maxLength"
                  value="255" />
            </bean>
         </list>
      </property>
      <property name="legacyTable" value="YY_TABLE"/>
   </bean>

 

3) Ok. Works

4) Ok. Works

 

thanks for your help

Henrik

vvandens
Offline
Joined: 05/29/2008
ExtendedEntityDescriptor ...

Hi Henrik,

You are right, my bad. You can't define the ExtendedEntityDescriptor class in the SAME module where you use it for entity generation (your project "core" module). This is due to the fact that the generator must have the ExtendedEntityDescriptor in its execution classpath. But the entity generation occurs BEFORE the "compile" phase, i.e. in the "generate-sources" phase, meaning that the ExtendedEntityDescriptor class is not yet available to the entity generator. So your "Event" entity is simply ignored since the generator can't know that this is an entity, since it doesn't now it's descriptor implementation class...

The solution is the following. You have to make your ExtendedEntityDescriptor either part of another maven project, e.g. a Jspresso extension project, which is the preferred way since it makes it independent and re-useable from your actual Jspresso projects, or you have to make another module in your exiting project. In both cases, the "core" module has to declare a Maven dependency towards the new Jspresso extension artifact (either project or module) so that it gets included in the classpath.

 

HTH,

Vincent

henrik.b
Offline
Joined: 08/02/2010
ExtendedEntityDescriptor ...

Here is how I did it, but since I am fairly new to maven and pom.xml, there must be a better way to include the class path.

1) create helloworld/ext directory
2) edit helloworld/pom.xml, add     <module>ext</module>
3) create helloworld/ext/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>ext.legacytables</groupId>
  <artifactId>ext</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Build LegacyTables extension</name>
  <dependencies>
    <dependency>
      <groupId>org.jspresso.framework</groupId>
      <artifactId>jspresso-tools</artifactId>
    <version>3.5-SNAPSHOT</version>
      <optional>true</optional>
    </dependency>
  </dependencies>
</project>

4) edit helloworld/core/pom.xml
under
            <id>generate-entities</id>
under <path id="spring.beans.classpath"> add
                  <dirset dir="helloworld/ext" >
                     <include name="**/target/classes" />
                  </dirset>

5) verify helloworld/core/target/generated-sources/Event.java
YES... it worked...

next step is to use the JPA or Hibernate annotations...

thanks, Henrik

vvandens
Offline
Joined: 05/29/2008
ExtendedEntityDescriptor ...

Hi Henrik,

Regarding what you did, you could have declared a dependency on the "ext" module instead of adding ext/target/classes in the generator classpath (more Maven oriented ;-).

Regarding switching to annotations, I would definitely head for Hibernate ones.

 

Best,

Vincent

henrik.b
Offline
Joined: 08/02/2010
pom.xml for hibernate annotation...

The java code is now using hibernate annotation.

But my maven-fy is not strong enough to get the annotation translated into DDL.

Can anyone send an updated pom.xml ?

thanks Henrik

vvandens
Offline
Joined: 05/29/2008
pom.xml for hibernate annotation...

Hi Henrik,

Never worked with Hibernate annotations myself. But this post on the Hibernate forum might help. The user gives a complete configuration of the Hibernate3 maven plugin we're using in Jspresso, but generating the schema from annotations.

 

Best,

Vincent

henrik.b
Offline
Joined: 08/02/2010
upgrade hibernate to version 3.5?

Hi Vincent,

 

thanks for the link. I will give it a try.

Would you consider to upgrade the Hibernate version in jspresso-SNAPSHOT ?

 

thanks Henrik

vvandens
Offline
Joined: 05/29/2008
Upgrade hibernate to version 3.5

Hi Henrik,

Upgrading Hibernate for your project should be as simple as inserting the following lines in your project root pom.xml. This will bring you forward in your tests :

  <properties>
<hibernate.version>3.5.5-Final</hibernate.version>
</properties>

 

As for ugrading Hibernate generally for Jspresso, I want to release the 3.5.1 maintenance release first.

 

HTH,

Vincent

henrik.b
Offline
Joined: 08/02/2010
upgrade hibernate to version 3.5?

HEY a new release already !

You guys ROCKS !!

 

The repository for hibernate 3.5.5-Final:

    <repository>
      <id>jboss-repository</id>
      <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>

 

while learning maven and reading the hbm2ddl goal, I noticed that hbm2ddl invokes the process-resources lifecycle phase, so this explains why the grovy execution fires a number of times.

 

keep hacking

Henrik

vvandens
Offline
Joined: 05/29/2008
new JBoss repo

Thanks Henrik !

I forgot to deploy the Jspresso root pom including the new JBoss maven repo. This is done now.

 

Best,

Vincent