此内容没有您所选择的语言版本。

Chapter 2. Data objects


Data objects are the building blocks for the rule assets that you create. Data objects are custom data types implemented as Java objects in specified packages of your project. For example, you might create a Person object with data fields Name, Address, and DateOfBirth to specify personal details for loan application rules. These custom data types determine what data your assets and your decision services are based on.

The following tables show the Violation and Driver data objects that you will create for this project.

Table 2.1. Violation data object
IDLabelType

code

Code

String

points

Points

Integer

violationDate

Violation Date

Date

type

Type

String

fineAmount

Fine Amount

Double

speedLimit

Speed Limit

Integer

actualSpeed

Actual Speed

Integer

Table 2.2. Driver data object
IDLabelType

name

Name

String

age

Age

Integer

state

State

String

city

City

String

violations

Violations

Violation (org.jboss.example.traffic_violations.Violation)

Note: The Violations field is set to List to hold multiple items for the given type.

fineAmount

Fine Amount

Double

totalPoints

Total Points

Integer

reason

Reason

String

2.1. Creating the Violation data object

The Violation data object contains data fields based on violation details, such as the Violation Date, Fine Amount, and Speed Limit.

Prerequisites

You have created the Driver_department_traffic_violations project.

Procedure

  1. Click Add Asset Data Object.
  2. In the Create new Data Object wizard, enter the following values:

    • Data Object: Violation
    • Package: select com.myspace.driver_department_traffic_violations
  3. Click Ok.

    Figure 2.1. Create new Data Object window

    data object

2.1.1. Adding the Violation data object constraints

Populate the Violation data object fields with the constraints that you will select when you define your rules.

Prerequisites

You have created the Violation data object.

Procedure

  1. In the 'Violation'-general properties section, enter Violation in the Label field.

    Figure 2.2. General properties

    gen props
  2. Click + add field.
  3. Enter the following values:

    • Id: code
    • Label: Code
    • Type: String
  4. Click Create and continue, then enter the following values:

    • Id: points
    • Label: Points
    • Type: Integer
  5. Click Create and continue, then enter the following values:

    • Id: violationDate
    • Label: Violation Date
    • Type: Date
  6. Click Create and continue, then enter the following values:

    • Id: type
    • Label: Type
    • Type: String
  7. Click Create and continue, then enter the following values:

    • Id: fineAmount
    • Label: Fine Amount
    • Type: Double
  8. Click Create and continue, then enter the following values:

    • Id: speedLimit
    • Label: Speed Limit
    • Type: Integer
  9. Click Create and continue, then enter the following values:

    • Id: actualSpeed
    • Label: Actual Speed
    • Type: Integer
  10. Click Create.
  11. Click Save, and then click Save to confirm your changes.
  12. Click the Driver_department_traffic_violations label to return to the Assets view of the project.

    Figure 2.3. Violation data object fields

    violation data fields

2.2. Creating the Driver data object

The Driver data object contains data fields based on driver details, such as the Name, Age, and Total Points of the driver.

Prerequisites

You have created the Driver_department_traffic_violations project.

Procedure

  1. Go to Menu Design Projects Driver_department_traffic_violations.
  2. Click Add Asset Data Object.
  3. In the Create new Data Object wizard, enter the following values:

    • Data Object: Driver
    • Package: select com.myspace.driver_department_traffic_violations
  4. Click Ok.

    Figure 2.4. Create new Data Object window

    data object2

2.2.1. Adding the Driver data object constraints

Populate the Driver data object fields with the constraints that you will select when you define your rules.

Prerequisites

You have created the Driver data object.

Procedure

  1. In the 'Driver'-general properties section, enter Driver in the Label field.
  2. Click + add field.
  3. Enter the following values:

    • Id: name
    • Label: Full Name
    • Type: String
  4. Click Create and continue, then enter the following values:

    • Id: age
    • Label: Age
    • Type: Integer
  5. Click Create and continue, then enter the following values:

    • Id: state
    • Label: State
    • Type: String
  6. Click Create and continue, then enter the following values:

    • Id: city
    • Label: City
    • Type: String
  7. Click Create and continue, then enter the following values:

    • Id: violations
    • Label: Violations
    • Type: Violation(com.myspace.driver_department_traffic_violations.Violation)
    • List: Select this check box to enable the field to hold multiple items for the specified type.
  8. Click Create and continue, then enter the following values:

    • Id: fineAmount
    • Label: Fine Amount
    • Type: Double
  9. Click Create and continue, then enter the following values:

    • Id: totalPoints
    • Label: Total Points
    • Type: Integer
  10. Click Create and continue, then enter the following values:

    • Id: reason
    • Label: Reason
    • Type: String
  11. Click Create.
  12. Click Save, and then click Save to confirm your changes.
  13. Click the Driver_department_traffic_violations label to return to the Assets view of the project.

    Figure 2.5. Driver data object fields

    driver data fields
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat