Using the information design model shown in Figure 7.2 above as the starting point, we make an Entity class model with getters/setters and corresponding Java datatypes.
The entity class model defines getters and setters for all properties and the following property constraint annotations:
Using @Id and @NotNull, the isbn
attribute is declared to be a standard
identifier, implying that it is mandatory and unique.
Using @Pattern("\\b\\d{10}\\b"), the isbn
attribute has a pattern constraint requiring its values to match the ISBN-10 format
(simplified to the case of 10-digit strings).
Using @NotNull and @Size( max=50), the title
attribute is mandatory and has a string length maximum
constraint of at most 50 characters.
Using @NotNull, @Min( 1459) and the custom annotation @UpToNextYear, the
year
attribute is mandatory and has an
interval constraint of a special form where the minimum is
1459 and the maximum is not fixed, but provided by a custom annotation implementing the
calendar arithmetic function nextYear().
Since there is no predefined Bean Validation annotation for checking the uniqueness of an ID
value provided when creating a new entity object, we define a static method
checkIsbnAsId
that can be invoked in a corresponding controller method when
creating a new entity object.
In addition, the entity class model defines the static CRUD data management methods
retrieveAll
, create
, update
and
delete
.