Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel2

 

...

 

The Entity Manager is a service that manages entities. An entity is an object like a Book, Person or Car. Entities, or domain objects, are defined and registered by a component within a plugin. Entities are implemented as a Java class with particular entity annotations and always defines an implementation class and an interface. Both the interface and implementation are registered by the Entity Manager. The Entity Manager supports all CRUD actions on the entity. So it can Create, Retrieve, Update and Delete entities.

The Entity Manager is a required guideline, (see G125 of the guidelines).

Implementing an Entity

As stated above, the implementation of an entity consists of two Java classes: the entity implementation and the interface. The interface contains the public methods that may be invoked by any external class, even Java classes from another plugin. The interface must extend the Identifiable interface, which holds getters and setters for the WmId. The WmId is the unique identifier for the entity inside the Entity Manager’s registry.

...

The entity implementation implements the entity interface described above. To identify that this Java class contains the definition of an Entity, four specific Entity annotations must be added to the header of the class.

  1. @Entity: First, the @Entity annotation must be added to the class header to identify the class as definition of an entity. The annotation

    takes no arguments.

    can take one argument: websiteSpecific. To make @Entity website specific, the syntax is:

    Code Block
    themeEclipse
    @Entity(websiteSpecific=true)



  2. @Interfaces: Secondly, the interface that is associated with this entity must be defined using the @Interfaces annotation. It takes the full classname (including package) of the associated interface as argument.
  3. @Namespace: Thirdly, the namespace for this entity must be defined for this entity using the @Namespace annotation. The annotation takes two arguments, the prefix and the URI.

    Note

    The plugin defines one namespace and URI for all classes contained by the plugin, including the entity. Usually the namespace and URI are defined in the Activator of the plugin or a Java class containing all constants, like IDs, namespace and URI.



  4. @Nodetype: Finally, when the Entity will be stored inside the JCR, the @NodeType annotation should be used to define the node type, super type and mixin node types of the node that represents the entity in the JCR. The @NodeType annotation takes four arguments; name, registerNodeType, supertype and mixin.

...

Code Block
themeEclipse
componentDefinition.setEntityClassNames(new String[] {CustomEntityImpl.class.getName()});
componentDefinition.setEntityFactoryClassName(DefaultJcrEntityFactoryImpl.class.getName());
componentDefinition.setPersistenceManagerClassName(DefaultJcrPersistenceManager.class.getName());

 

 

Note

Do not invoke setEntityClassNames(…) on the same entity in different component definitions. This causes a non-deterministic definition of the component that owns the entity and will cause errors in some occasions, like when purging the component.

...

The @Property annotation has the following properties:

 

PropertyDescription
name

The name of this property in the repository. Leave this empty if you want to use the same name as the property in the Java class.

type

The JSR-170 property type to use. The default is PropertyType.UNDEFINED which means that the type will be determined by the type of the property in the Java class.

mandatory

Specifies whether this property is mandatory. The default is false.

multiple

Specifies whether the property may have more than one value. The default is false.

constraints

Add JSR-170 constraints to the property. By default no constraints are added.

@Child

The @Child annotation can be used to indicate that the object should not be stored as a reference property but as a child property of this entity. As a result, the physical location of the object will be such that there will be a parent-child relation between the entity and the object to which is referred by the @Child annotation.

...

The @Child annotation has the following properties:

 

PropertyDescription
name

The name of this property in the repository. Leave this empty if you want to use the same name as the property in the Java class.

mandatory

Specifies whether this property is mandatory. The default is false.

allowsSameNameSiblings

Specifies whether this child node can have same-name siblings. In other words, whether the parent node can have more than one child node with the same name. The default is false.

requiredPrimaryTypes

Specifies the minimum set of primary node types that the child node must have. The default is {http://www.jcp.org/jcr/nt/1.0}base which is the JSR-170 base type of all node types.

defaultPrimaryType

Specifies the default primary node type that will be assigned to the child node if it is created without an explicitly specified primary node type. The default is {http://www.jcp.org/jcr/nt/1.0}unstructured which indicates the unstructured node type.

 

 

Note
  • The @Child annotation supports multiple values by returning an array of the child class (For example returning CustomEntity[]).
  • The @Child entity is an alternative to the @Property annotation, they should not be used both.

...

The @collection annotation has the following properties:

 

PropertyDescription
type

The type of the collection property, which must be either Type.LIST or Type.Set.

memberType

Specifies the class associated with the objects contained by the collection.

lazy

Specifies whether the collection should use lazy loading or not. The default is true.

reference

Specifies if the objects contained by the reference should be stored by reference or as child objects. The default is by reference.

 

 

Note

The @Collection annotation should be used in combination with the @Property annotation. If only the @Collection annotation is provided, the property will not be identified as a property of the entity.

...

Persistent classes not managed by the Entity Manager are:

 

Persistent ClassDescription
Custom media item implementation

Class that extends MediaItemArticleVersionImpl or MediaItemVersionImpl, that is, CustomMediaItemArticleVersionImpl.

Custom element implementation

Class that extends ElementBase, that is, CustomElementImpl.

A persistent class that is not managed by the Entity Manager may persist its properties using the nl.gx.webmanager.foundation.JcrUtil class. This class contains methods to read and write values to and from JCR nodes. The getters and setters of an entity managed by the Entity Manager usually only store the value in a class variable and persist the entity by using EntityManager.persist(). Using JCRUtil is an alternative to EntityManager.persist() however it should be invoked to persist each property individually. For example, to persist the company property:

...

Note
  • The getPrivateNode() receives the node instance that is created automatically by the XperienCentral framework and that contains the persistent properties.
  • Persistent classes not managed by the Entity Manager can still persist their properties using the Entity Manager. To do so add only one child property to the class that has the same type as the entity managed by the Entity Manager.

 

Back to Top