Services

Table of Contents

Paging Resultsets

The service layer of the CDM contains a set of service objects that are intended to provide basic query, search and persistence functionality for the CDM objects, plus business logic to support common tasks. These objects are intended to be singleton services used across the whole application. As with the persistence layer, the services are strongly typed, generic service objects, with a single service per (significant base) class. All service classes implement IService and most implement IVersionableService, providing access to generic base methods to deal with the class.

Figure 7.1. An overview of the cdm service layer

An overview of the cdm service layer
The Service layer in the CDM Java Library. There is a service for each major type of data that the CDM deals with.

Table 7.1. IService methods

MethodDescription
UUID saveOrUpdate(newOrTransientEntity);

Makes a new object persistent, or persists the state of a transient object.

Map<UUID,T> save(Collection<T> newEntities);

Makes a collection of new objects persistent.

UUID save(newEntity);

Makes a new object persistent.

UUID update(newEntity);

Makes changes to a transient object persistent.

UUID merge(newEntity);

Merges the state of a detached object into the persisted version.

UUID delete(persistentEntity);

Deletes a persistent object.

List<T> list(Class<? extends T> clazz,
             Integer pageSize,
             Integer pageNumber,
             List<OrderHint> orderHints,
             List<String> propertyPaths);

Returns a (sub-)list of objects matching the type clazz, sorted according to the order hints and initialized according to the propertyPaths.

Pager<T> page(Class<? extends T> clazz,
              Integer pageSize,
              Integer pageNumber,
              List<OrderHint> orderHints,
              List<String> propertyPaths);

Returns a paged (sub-)list of objects matching the type clazz, sorted according to the order hints and initialized according to the propertyPaths.

int count(Class<? extends T> clazz);

Returns a count of objects matching the type clazz.

find(UUID uuid);

Returns an object of type T matching the supplied uuid if it exists.

Collection<T> find(Collection<UUID> uuids);

Returns a collection of objects of type T matching the uuids supplied, if they exist.

load(UUID uuid,
       Collection<String> propertyPaths);

Returns an object of type T with properties initialized according to the rules described below.

Set<T> load(Collection<UUID> uuids,
            Collection<String> propertyPaths);

Returns a collection of objects of type T matching the uuids supplied, if they exist, initialized according to the rules described below.

boolean exists(UUID uuid);

Returns true if there is an object of type T in the database matching the supplied uuid.

Class<T> getType();

Returns the class of objects that this Service provides access to.


Table 7.2. IVersionableService methods

MethodDescription
Pager<AuditEventRecord<T>> pageAuditEvents(versionablentity,
                                           Integer pageSize,
                                           Integer pageNumber,
                                           AuditEventSort sort);

Makes a new object persistent, or persists the state of a transient object.

AuditEvent getNextAuditEvent(t);

Makes a collection of new objects persistent.

AuditEvent getPreviousAuditEvent(t);

Makes a new object persistent.

boolean existed(UUID uuid);

Makes a new object persistent.


Paging Resultsets

In addition to being able to return results as a java.util.List, service layer methods can return results as a Pager. Pagers contain a sublist of the total result set, plus a count of the total number of matching objects. In addition, they contain a number of convenience methods to facilitate the rendering of paged resultsets, including the generation of labels for pages, based upon the matching objects.