Skip to content

Data Management

Categories of Data Sources

Within a web application you need to manage data by reading it from or/and writing it to “somewhere”. Conceptually, there are the following categories of data sources:

  • Webservices, called with a request/response pattern
  • Messaging systems, called with a publish/subscribe pattern
  • Databases, called through a persistence layer, e.g. with the help of the Java Persistence Architecture (JPA) or the jOOQ framework
  • Business logic, typically implemented in Enterprise Java Beans (EJB)

EJBs that implement business logic often access webservices, messaging systems and databases. You can wrap the access to webservices, messaging systems and databases by means of additional EJBs. This gives you the advantages of a unified exception handling and an improved testability by easy mocking.

The generated [layout-name]Bean.java is the place where you want to access data sources. You inject interfaces by means of @EJB or @Inject.

The implementation of EJBs, persistence layers, webservice and messaging clients is beyond the scope of this documentation.

Datatypes

Even when EJBs are being used to access data sources, it is technically possible and sometimes desirable to directly use datatypes that are being used in webservice or messaging clients. When you retrieve data through a webservice/messaging client, it often makes sense to keep that data available for the lifetime of a user session or at least of a web page. Doing so prevents you from the need to call the service again to retrieve the same data that you were retrieving by a previous call.

Data Mapping

Binding data to web pages is done with generated Java classes (we call them ‘DTOs’) where their properties are being referenced by means of expressions like this:
value=#{beanName.propertyName}. It is the DTO generator that generates the Java classes. A UI model is taken as input.

Data mapping is the act of bringing data from a data source to the DTOs and vice versa. Data mapping can be done in [layout-name]Bean.java or delegated to a separate Java class. Delegating the mapping to a separate Java class is one of the means to keep the size of [layout-name]Bean.java under control. The data mapper class will be placed in the same component as [layout-name]Bean.java.

Data Conversion

Data Selection

Data Validation

Test Data for Mocking

By providing another set of classes that implement the same interfaces as the EJB classes that serve as data sources, web pages can be tested without accessing databases, webservices or messaging systems. This mocking mechanism will only work when you use the @Inject annotation instead of @EJB. Or more commonly said: “Contexts and Dependency Injection” (CDI) allows you to mock data sources.