9. Performing Basic CRUD Operations

PROBLEM

When a domain object is added to a data access object, it implies that the application intends to persist objects for that domain object. The most basic persistence functions in Create, Read, Update and Write, and they are cummulatively referred to as CRUD operations

SOLUTION

For every domain object added to a Data Access Object, the developer can perform basic persistence functions using the Modify Data Access Object and Search Data Access Object steps. The Modify Data Access Object step is used for creating, update and deleting objects from a DAO, and the Search Data Access Object step is for reading object(s) from a DAO.

HOW IT WORKS

Operations - Create / Update / Delete

While the Modify Data Access Object step is very easy to configure, the object oriented concepts can be difficult to understand initially. While a relational database is ultimately going to be used to persist the data, an object oriented view of the data is different than a relational view of the data.

The Modify Data Access Object step supports two operations: Update and Remove. These operations are highly dependent on the primary key(s) defined for a persistable domain object. The key(s) must uniquely identify the object, and the ORM framework will use the keys to determine which objects should be removed, added or updated. For the update operations the ORM framework will determine whether to do an update and an insert based on the keys. If an object with the same keys already exist, then the ORM framework will use an update SQL statement. If an object with the same keys doesn't exist, then the ORM framework will do an insert SQL statement.

The following examples will demonstrate how the Modify Data Access Object works.

Figure 4.6. CRUD - Modify Data Access Object Examples

CRUD - Modify Data Access Object Examples