All posts in Model Driven Development

Ever had to do copy/clone methods in large objects?

Doing it by hand takes a long time, it’s a nightmare to maintain and can lead to some serious bugs.
You could always use some kind of serialization like Java Object Serialization java.io.ObjectInputStream and java.io.ObjectOutputStream, to do it.

But there is and easier way, you can now use Trimm to automatically create a copy method in all your pojos, just use dk.tigerteam.trimm.mdsd.java.generator.extension.CopyMethodEventListener in your yaml configuration like:

# Extensions (note these listeners can also be groovy scripts containing a single class implement the GeneratorEventListener interface (or
# which extend specializations thereof) 
eventListeners:
    - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.CopyMethodEventListener
    - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.SerialVersionUIDGeneratorListener
    - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.PropertySugarMethodsEventListener
    - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.ToStringListener
    - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.HashCodeAndEqualsListener

Read more

The first Maven snapshot of TRIMM 1.0.1 with TrimmMongo is available from our Maven Repository.

The TrimmMongo project has in this first version a Listener (dk.tigerteam.trimm.mdsd.mongo.SpringDataMongoGeneratorListener) that based on stereotypes can use Spring Data Mongo mapping annotation to save your model in MongDB instance.

There’s also an TrimmMongo example project available called TrimmMongoExample

Short introduction to TrimmMongo modeling

In this first version of the SpringDataMongoGeneratorListener there is support for following annotations for mappings of objects to documents. The listener Stereotypes and Tag values to drive the mapping metadata:

  • @Id – applied at the field level to mark the field used for identiy purpose. STEREOTYPE: DOCUMENT_ID
  • @Document – applied at the class level to indicate this class is a candidate for mapping to the database. You can specify the name of the collection where the database will be stored. STEREOTYPE: DOCUMENT
  • @DBRef – applied at the field to indicate it is to be stored using a com.mongodb.DBRef. STEREOTYPE: DBREF
  • @Indexed – applied at the field level to describe how to index the field. STEREOTYPE: INDEX & UNIQUEINDEX
  • @Transient – by default all private fields are mapped to the document, this annotation excludes the field where it is applied from being stored in the database STEREOTYPE: TRANSIENT

Read more

* Updated the 25th of October to include information on CreateCommand vs. Command stereotype handling for the TrimmCQRS plugin.

The first Maven snapshot of TRIMM 1.0.1 is available from our Maven Repository.

The changes in the core API revolve around enhancements the MetaModel and CodeModel, no breaking API changes.

The biggest change is the addition of the TrimmCQRS which supports Model Driven code generating of AxonFramework (a Java based CQRS framework) based CQRS code.

TrimmCQRS comes with a matching TrimmCQRSMavenPlugin that can be used to drive the codegeneration.

There’s also an TrimmCQRS example project available called TrimmCQRSAxonAddressBookExample which models and generates code that implement the same features and structure of the Axon AddressBook example.
Read more

We have just added an example of how to use TRIMM JPA to generate code for Hibernate 4.x (in this case 4.2.4) to our TRIMM-Examples repository. The project is called TrimmHibernate4xMDDExample.

If you are new to TRIMM JPA, check out this tutorial on how to use it

The largest difference from the Hibernate 3.6.x example, called MDDExample, are the following:

  • To Persist DateTime and LocalDate (from JODA time) – we now use org.jadira.usertype.usertype.core and the latest joda-time version.
    This means that we have removed the dependency to joda-time-hibernate.
  • We have therefore added the following Maven jar dependency:

           <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                <version>2.2</version>
            </dependency>
            <dependency>
                <groupId>org.jadira.usertype</groupId>
                <artifactId>usertype.core</artifactId>
                <version>3.1.0.CR8</version>
            </dependency>
          

    Read more

TRIMM JPA will leave table and column names up to the default JPA rules, unless you instruct it to specify @Table, @JoinTable, @Column, @JoinColumn, et, e.g. using the addTableAndColumnNames parameter in the JPA YAML configuration.

It can sometimes be useful to control the table and column names if the default names (which follows the JPA default naming standard) collide with database reserved words or if you use a “modern” database like Oracle which still limits names to 30 characters 😉
Read more