Table of Contents
The data layer is also referred to as the persistence layer or domain object layer. The data layer is represented by a domain model; a distinct set of inter-related application objects that embody the functionality and characteristics of the system being built. This layer also encompasses the persistence of the domain model to and from a database.
The tools for defining the data layer in the Spring DSL are the Domain Object and Data Access Object artifacts, and they will be described in detail in a following chapter.
PROBLEM
For application frameworks like the Spring Framework that utilizes plain old java objects (POJO), there needs to be a easy way of creating POJOs.
SOLUTION
A Domain Object is a Spring DSL artifact that defines the domain model of the application. By default a domain object is generated into a plain old java object (POJO). If a domain object is associated with a data access object, then the domain object is annotated as an @Entity (JPA) annotated class, and it's associated with a primary key class (@IdClass). Fields can be added to domain objects by using the basic data types, and a domain object can have relationships to other domain objects.
HOW IT WORKS
All applications work with data, and domain objects specify the kind of data that can be stored and manipulated within a program. Skyway supports a number of fundamental basic data types (scalar data types), which are the simplest data types in a Skyway application.
The following table lists the basic data types supported.
Table 4.1. Skyway Basic Data Types
Name | Description | ||
---|---|---|---|
ID | java.lang.String | ||
Text | java.lang.String | ||
Integer | java.lang.Integer | ||
Decimal | java.math.BigDecimal | ||
Date and Time | java.util.Calendar | ||
Boolean | java.lang.Boolean | ||
Large Text | java.lang.String | ||
Date | java.util.Calendar | ||
Map | java.util.HashMap | ||
Time | java.util.Calendar | ||
Picture | Java Byte Array | ||
Large Data Storage | Java Byte Array |
Skyway Domain Objects are used to define objects. As described in the Spring DSL model, domain objects can be created in model packages.
Steps for creating a Domain Object:
Right click on a Model Package, and select New-->Domain Object to open the New Domain Object Wizard.
From the New Domain Object panel, enter a name for the domain objectl. Click Finish to open the Domain Object Editor.
From the Domain Object Editor add fields to the domain object. A field consists of a field name and field type. You can also specify whether the field is a collection and a primary key.
You can also relate the current domain object to other domain objects by adding relationships.
This figure shows a domain object being defined in Skyway Builder. Attributes were added as fields. For each field you can specify the type (Text, Integer, etc..) and whether it's a collection. You can also specify which attribute(s) uniquely identify the object from other objects of the same type.
This is an example of the code that is generated from the Order domain object defined in the previous figure.
Example 4.1. Domain Object - POJO (Generated)
package domain.ordermgmt; public class Order implements Serializable{ /** * * @generated */ private String invoiceId; private Calendar invoiceDate; private Integer lineItemCount; // Constructors, Getters and Setters ... }
For the fields that were defined as primary keys, Skyway Builder will generate primary key classes. Composite keys are supported.
Example 4.2. Domain Object - Primary Key Class (Generated)
package domain.ordermgmt; public class OrderPK implements Serializable { /** * * @generated */ private String invoiceId; // Constructors, Getters and Setters, Hashcode() and Equals() ... }
By default a field is scalar; it can store one value of the basic type that is specified. If you mark the field as a collection, the field becomes a composite field that can store one or more values of that domain object.