TrimmMongo 1.0.1 Snapshot with support for Spring Data Mongo

TrimmMongo 1.0.1 Snapshot with support for Spring Data Mongo

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

You can find out more about Spring Data Mongo mapping by clicking this link Spring Data Mongo Mapping

Have a look at the model from the example project to see how the Stereotype are used

TrimmMongo example model

TrimmMongo example model

Short introduction to TrimmMongo codegeneration

Code generation for a TrimmMongo annotated UML class model can be done in a classical Maven project by using the TrimmJavaMavenPlugin.
For the Mongo example you need to XMI Export the mongo-example package from Enterprise Architect (as XMI version 2.1) to the Java example projects model/ subfolder under the name model.xml (since this is how we reference it in the MongoModel.yml that I will cover in a second)
See here for information about modeling in Enterprise Architect in general and here for information about Exporting a model to XMI 2.1.

We need to add the TrimmJavaMavenPlugin to the Java example projects pom.xml:


The yml configuration looks like this, remember to add SpringDataMongoGeneratorListener listener.

# Setup
xmiModelPath: model/model.xml
# EA, MagicDraw, FQCN, .groovy script
umlTool: EA

generateExtensionClasses: false
# addExtensionAndBaseClassAnnotations is only valid if generateExtensionClasses is set to true
addExtensionAndBaseClassAnnotations: false
#    implementation:
    # Formatting exclusions can be specified even though implementation hasn't been specified (and the default JalopyFormattingCodeWriter is used)
        - dk.tigerteam.mddexample.meta
        - dk.tigerteam.mddexample.test
# Paths
generateBaseClassesToPath: target/generated-sources/domainmodel

# Extensions (note these listeners can also be groovy scripts containing a single class implement the GeneratorEventListener interface (or
# which extend specializations thereof) 
    - listener: dk.tigerteam.trimm.mdsd.mongo.SpringDataMongoGeneratorListener
    - listener:
    - listener:
    - listener:
    - listener:

See the TrimmMongo example project for the full configuration and setup.

Have a look in the target/generated-sources/domainmodel for an example of a generated artifact from the example model:

package dk.tigerteam.trimm.mongo.exa;

import dk.tigerteam.trimm.mongo.exa.Address;
import dk.tigerteam.trimm.mongo.exa.Customer;
import dk.tigerteam.trimm.mongo.exa.Order;


import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Customer {
    private static final long serialVersionUID = 626358653L;

    @Indexed(unique = true)
    private String username;

    private String firstName;

    private String lastName;

    private String id;

    private Set<Order> order = new HashSet<Order>();

    private Address address;

    public String getUsername() {
        return username;

    public void setUsername(String parameter) {
        this.username = parameter;

    public String getFirstName() {
        return firstName;

    public void setFirstName(String parameter) {
        this.firstName = parameter;

    public String getLastName() {
        return lastName;

    public void setLastName(String parameter) {
        this.lastName = parameter;

    public String getId() {
        return id;

    public void setId(String parameter) { = parameter;

    public Set<Order> getOrder() {
        return order;

    public void setOrder(Set<Order> parameter) {
        this.order = parameter;

    public Address getAddress() {
        return address;

    public void setAddress(Address parameter) {
        this.address = parameter;

    public Customer withUsername(String username) {

        return (Customer) this;

    public Customer withFirstName(String firstName) {

        return (Customer) this;

    public Customer withLastName(String lastName) {

        return (Customer) this;

    public Customer withId(String id) {

        return (Customer) this;

    public Customer addToOrder(Order... values) {

        return (Customer) this;

    public Customer withAddress(Address address) {

        return (Customer) this;

    public String toString() {
        return "Customer[" + "address: " + address + ", firstName: " +
        firstName + ", id: " + id + ", lastName: " + lastName + ", username: " +
        username + "]";

Try it out with our own model or the example one and let us know what you think.


No comments yet.