Skip to content
Martin Goellnitz edited this page May 5, 2016 · 4 revisions

The Data Model

The foundation of data driven web applications obviously is the data model. To avoid re-inventing the wheel, we rely on proven ORM solutions for the Java environment but have to add a little more specific details.

  • JDO
  • CoMA
  • JPA
  • EBean
  • Tangram specific Model Elements

JDO

The first implementation of a storage layer for Tangram was the Java Data Objects (JDO) implementation DataNucleus Access Plattform

CoMA

JPA

EBean

Morphia

Tangram specific Model Elements

In addition to the ORM solutions usable with Tangram there are some extensions and constraints built on top of the plain ORM layer.

Basics

The main contraint vor model classes to be usable within Tangram is, that they must implement the org.tangram.content.Content interface.

Any of the content base classes provided by the ORM specific modules of Tangram implements this interface and provides all the necessary details. If you use derived classes you are safe.

package org.tangram.example;

import javax.persistence.MappedSuperclass;
import org.tangram.content.Content;
import org.tangram.ebean.EContent;


@MappedSuperclass
public abstract class Linkable extends EContent {

    private String title;

    private String shortTitle;

    private String keywords;

} // Linkable

EBean example

Structured Text Properties

Tangram supports structured text in a property of a class. This structured text can be either HTML fragments (divs and ps) or markdown.

If the getters and setters of the property use char[] as the property type, this property is handled as a HTML fragment holder and editing takes place through the CKEditor in the Tangram editor module.

If you prefer to edit structured text as markdown, you have to wrap your internal data as org.tangram.content.Markdown.

package org.tangram.example;

import javax.jdo.annotations.PersistenceCapable;
import lombok.Getter;
import lombok.Setter;
import org.tangram.content.Markdown;


@PersistenceCapable
public class Article extends Linkable {

    @Getter
    @Setter
    private char[] text;

    private char[] markdown;


    public Markdown getMarkdown() {
        return new Markdown(markdown);
    }


    public void setMarkdown(Markdown markdown) {
        this.markdown = markdown.getContent();
    }

} // Article

JDO Example using DataNucleus Access Plattform

Besides the getter and setter constraints you are free to store the data internally as String, char[], or blob whichevery fits your storage needs better.

Taking Care of the Modification Date and Time

If you need to track the modification time of an object through the Tangram editor module, you simply have to implement the org.tangram.mutable.HasModificationTime interface and store a long value together with the neede getters and setters.

All code implementations of Tangram implement this interface, so you will be able to check when you last modified the codes stored in the Tangram repository like you can do this on you local disk storage with file containing code.

Also the ftp module has been extended to make use of the modification time field.

Pseudo Abstract Classes

The org.tangram.annotate.Abstract annotation. In some situation you might only want to avoid that classes are instanciated through Tangram and not in general. (Sometimes there might be limitations with the model implementation leading to pseudo-abstract classes.) In such situations you can add a Tangram specific annotation @Abstract at the class level to let Tangram handle this class as if it where abstract.

package org.tangram.example;

import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import lombok.Getter;
import lombok.Setter;
import org.tangram.annotate.Abstract;
import org.tangram.content.Content;
import org.tangram.jpa.JpaContent;


@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Abstract
public class Linkable extends JpaContent {

    @Getter
    @Setter
    private String title;

    @Getter
    @Setter
    private String shortTitle;

    @Getter
    @Setter
    private String keywords;

} // Linkable

Lomboked JPA Example intended for OpenJPA

Clone this wiki locally