Search

Chapter 6. Data Models

download PDF

Data models are models of data objects. A data object is a custom complex data type (for example, a Person object with data fields Name, Address, and Date of Birth).

Data models are saved in data models definitions stored in your Project. Red Hat JBoss BRMS provides the Data modeler, a custom graphical editor, for defining data objects.

6.1. Data Modeler

The Data Modeler is the built-in editor for creating facts or data objects as part of a Project data model from the Business Central. Data objects are custom data types implemented as POJOs. These custom data types can be then used in any resource (such as a Guided Decision Table) after they have been imported.

To open the editor, open the Project Authoring perspective, click New Item Data Object on the perspective menu. If you want to edit an existing model, these files are located under Data Objects in Project Explorer.

You will be prompted to enter the name of this model object when creating a new model, and asked to select a location for it (in terms of the package). On successful addition, it will bring up the editor where you can create fields for your model object.

The Data Modeler supports roundtrips between the Editor and Source tabs, along with source code preservation. This allows you to make changes to your model in external tools, like JBDS, and the Data Modeler updates the necessary code blocks automatically.

In the main editor window the user can

  • Add/delete fields
  • Select a given field. When a field is selected then the field information will be loaded in all the domain editors.
user guide 7226
  • Select the data object class. For example, by clicking on the data object name (on the main window) instead of loading the field properties, the domain editors will load the class properties.

    7227

6.2. Available Field Types

Data object fields can be assigned to any of the following types:

  • Java Object Primitive Types:

    BigDecimal, BigInteger, Boolean, Byte, Character, Date, Double, Float, Integer, Long, Short, and String.

  • Java Primitive Types:

    boolean, byte, char, double, float, int, long, and short.

  • Java Enum Types:

    Java enum types defined in current project or imported as a dependency. See Adding Dependencies.

  • Current project Data Objects:

    Any user defined data object automatically becomes available to be assigned as a field type.

  • Project Dependencies:

    Other Java classes imported as a Java dependency in current project. See Adding Dependencies.

6.3. Annotations in Data Modeler

Red Hat JBoss BRMS supports all Drools annotations by default, and can be customized using the Drools & jBPM domain screen. For further information about available domain screens, see Section 6.6, “Data Object Domain Screens”.

To add or edit custom or pre-defined annotations, switch to the Source tab and modify the source code directly. You can edit the source code directly in both Red Hat JBoss Developer Studio and Business Central. Use the Advanced screen to manage arbitrary annotations.

When creating or adding fields to a persistable data object, the JPA annotations that are added by default will generate a model that can be used by Red Hat JBoss BRMS at runtime. In general, modifying the default configurations where the model will be used by processes is not recommended.

Red Hat JBoss BRMS 6.2 onwards supports the use of JPA specific annotations, with Hibernate available as the default JPA implementation. Other JPA annotations are also supported where the JPA provider is loaded on the classpath.

Note

When adding an annotation in the Data Modeler, the annotation class should be on the workbench classpath, or a project dependency can be added to a .jar file that has the annotation. The Data Modeler will run a validation check to confirm that the annotation is on the classpath, and the project will not build if the annotation is not present.

6.4. Creating a Data Object

  1. In the Project Authoring perspective, click New Item Data Object on the perspective menu.
  2. Enter the name and select the package. The name must be unique across the package, but it is possible to have two data objects with the same name in two different packages.
  3. To make your Data Object persistable, check the Persistable checkbox.
  4. Click Ok.
  5. Create fields of the data object:

    1. Click add field in the main editor window to add a field to the object with the attributes Id, Label and Type. Required attributes are marked with *.

      • Id: The ID of the field unique within the data object.
      • Label: The label to be used in the Fields panel. This field is optional.
      • Type: The data type of the field.

        DataModelerNewField2 new
    2. Click Create to create the new field and close the New field window. Alternatively, click Create and continue to keep the New field window open.

    To edit an attribute, select the attribute and use the general properties screen.

Using a data object

To use a data object, make sure you import the data model into your resource. Unless both the data model and your resource, for example a guided rule editor, are in the same package, this is necessary even if both are in the same project.

6.5. Persistable Data Objects

From Red Hat JBoss BRMS 6.2 onwards, the Data Modeler supports the generation of persistable data objects. Persistable data objects are based on the JPA specification. When you check the Persistable checkbox, the platform will use default persistence settings. You can make a data object persistable in two ways:

To make an already created data object persistable:

  1. Open your data object in Business Central.
  2. Click the Editor tab.
  3. Select the Persistence icon from the menu on the right:

    persistenceicon
  4. Check Persistable.
  5. Click Save to save your changes.

6.6. Data Object Domain Screens

The following domain screen tabs can be selected from the right side of the data object editor screen.

Drools & jBPM

The Drools & jBPM screen allows configuration of Drools-specific attributes.

The Data Modeler in Business Central supports editing of the pre-defined annotations of fact model classes and attributes. The following Drools annotations are supported, and can be customized using the Drools & jBPM interface:

  • TypeSafe
  • ClassReactive
  • PropertyReactive
  • Role
  • Timestamp
  • Duration
  • Expires
  • Remotable

Figure 6.1. The Drools & jBPM Class View

DataModelerDroolsAndJBPM

For the fields within the fact model, the position and Equals annotations are supported. The Drools & jBPM screen when a specific field is selected looks as follows:

Figure 6.2. The Drools & jBPM Field View

72230

Persistence

The Persistence screen can be used to configure attributes on basic JPA annotations for persistence. For fine tuning of annotations, or to add specific annotations, use the Advanced screen.

Figure 6.3. The Class Persistence View

DataModelerPersistence

The Persistence screen when a specific field is selected looks as follows:

Figure 6.4. The Field Persistence View

72231

The following annotations can be managed via the Persistence screen.

Table 6.1. Type Annotations
AnnotationAutomatically Generated when the Data Object is Persistable

javax.persistence.Entity

Yes

javax.persistence.Table

No

Table 6.2. Field Annotations
AnnotationAutomatically Generated when the Data Object is PersistableResponsible UI Element

javax.persistence.Id

Yes

Is Identifier

javax.persistence.GeneratedValue

Yes

Generation strategy

javax.persistence.SequenceGenerator

Yes

Sequence Generator

javax.persistence.Column

No

Column Properties attributes

javax.persistence.OneToOne

No

Relationship Type

javax.persistence.OneToMany

Yes - when a field has one or multiple values

Relationship Type

javax.persistence.ManyToOne

Yes - when a field has multiple values

Relationship Type

javax.persistence.ManyToMany

No

Relationship Type

javax.persistence.ElementCollection

Yes - generated by the UI when a new field has one or multiple of a base java type, such as Integer, Boolean, String. This annotation cannot be edited with the ⁠Persistence screen tool (use the Advanced screen tool instead).

Created by a field marked as list.

All other JPA annotations can be added using the Advanced screen.

Advanced

The Advanced screen is used for fine-tuning of annotations. Annotations can be configured, added and removed using the Advanced Domain screen. These can be any annotation that is on the classpath.

DataModelerAdvanced

After you click on the add annotation option, the Add new Annotation window is displayed. It is required to enter a fully qualified class name of an annotation and by pressing the search icon, the annotation definition is loaded into the wizard. Then it is possible to set different annotation parameters (required parameters are marked with *).

72232

If possible, the wizard will provide a suitable editor for the given parameters.

72233

If it is not possible to provide a customized editor, the wizard will provide a generic parameter editor.

72234

After you enter all the required parameters, the Finish button is enabled and the annotation can be added to the given field or data object.

6.7. Configuring Relationships Between Data Objects

When an attribute type is defined as another data object, the relationship is identified and defined by the Info icon symbol in the object attribute list. You can jump to the data object definition to view and edit by clicking on the icon.

Relationship customization is only relevant where the data object is persistable.

Relationships can be configured by selecting an attribute with a relationship and choosing the Persistence button on the right. Under Relationship Properties, click the Relationship Type property editing option.

DataModelerRelationshipConfig

Attempting to delete a data object that is used by a different data object will show the Usage Detected screen. It is still possible to delete the object from here, however this will stop your project from building successfully until the resulting errors are resolved.

6.8. Persistence Descriptor

Business central contains a persistence.xml file with default persistence settings. To configure persistence settings, click Project Settings: Project General Settings Persistence descriptor.

PersistenceXML new

Use the Advanced properties section to change or delete or add properties.

7229

If you open the Project persistable Data Objects section in the Persistence Descriptor, you will see two buttons:

  • Add class enables the user to add arbitrary classes to the persistence.xml file to be declared as entities.
  • Add project persistable classes will automatically load all the persistable data objects in the current project.
7228
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.