Tags:
no tags assigned
Class EntitiesPart3Doc
in package de.infoasset.platform.documentation
- Declaration
- public class EntitiesPart3Doc
- extends Object
- Hierarchy
java.lang.Object
de.infoasset.platform.documentation.EntitiesPart3Doc
See EntitiesPart1Doc and EntitiesPart2Doc before reading this
article.
Data Modeling in Tricia - Mixin Types
When building complex applications it often occurs, that some functionality should be implemented once and then be reused by different data types. In Java this can be done using class inheritance, but each class is limited to extending exactly one super class. In many cases it is not possible to partition the functionality into one inheritance structure.It is desirable to have a more modular reuse model. In Tricia this is done using mixins. MandatoryMixin is a subclass of Asset and is the superclass for defining crosscutting functionality in one place. A mixin may define properties, roles, and methods as it is possible for PersistentEntitys.
Defining a Mixin
A simple example of a mixin type is Commentable. It defines one Role which defines the relationship to the Comment entities:
public final ManyRole<Comment> comments = new ManyRole<Comment>() {
@Override
protected Role oppositeRole() {
return Comment.SCHEMA.prototype().commentable;
}
@Override
public boolean isCascadeDelete() {
return true;
}
};
Each mixin type has to define a statically accessible prototype instance -
similar to the schema instance of entities:
public static final Commentable prototype = MandatoryMixin.initializePrototype(new Commentable());This prototype instance can be used to access properties and roles for querying (see Query).
Using a Mixin Type
Mixin assets are not instantiated themselves, but rather are assigned to an entity and then extend the base entity. Entities specify the mixin types they use by implementing the method Entity.mandatoryMixins():
public class WikiPage extends PersistentEntity {
@Override
protected MandatoryMixin[] mandatoryMixins() {
return new MandatoryMixin[] { new Commentable() }
}
In this example the wiki page is augmented with the role
comments of the mixin type Commentable. Properties and
roles of all mixin types are added automatically to the database schema of
the base asset. Functionality of a certain mixin type can be accessed by
adapting the base asset to the mixin type using the method
Asset.adapt(Class). In our example the comments role of
a wiki page can be accessed like follows:
Iterable<Comment> comments = wikiPage.adapt(Commentable.class).comments.get();This diagram shows the most important methods in a UML class diagram:
Function Substitutions for Mixin Assets
It is possible to define function substitutions (see FunctionSubstitutionsDoc) for mixin assets. In the example introduced before, there could be a function substitution showing all tags of an asset realizing the mixin type Taggable:
public static TemplateSubstitution showTags(final TaggableMixin wp, FunctionParameters params) {
return new TemplateSubstitution() {
@Override
public void specifyTemplate(TemplateFinder templateName) {
templateName.useStaticName("functions/showTags");
}
@Override
public Object getScopeObject() {
return wp;
}
};
}
The Most Important Mixin Types
- Linkable and ILinkable
- Searchable
- ReadProtected and IReadProtected
- Modifiable
- Taggable
- Draftable
- Orderable
Change Listener
See ChangeListener.Constructor Summary
Constructor Detail
EntitiesPart3Doc
public EntitiesPart3Doc()
Referenced by:
0 Comments