Browse Source

Add more database constraints for BOOK table

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.1-alpha
Pekka Helenius 4 years ago
parent
commit
967396b23d
1 changed files with 6 additions and 2 deletions
  1. +6
    -2
      bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java

+ 6
- 2
bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java View File

@ -81,6 +81,7 @@ public class Book {
// Attributes with hard-coded constraints // Attributes with hard-coded constraints
////////// //////////
@Column(nullable = false)
@Size( @Size(
min = strMin, max = strMax, min = strMin, max = strMax,
message = "Title length must be " + strMin + "-" + strMax + " characters" message = "Title length must be " + strMin + "-" + strMax + " characters"
@ -95,6 +96,7 @@ public class Book {
private String title; private String title;
////////// //////////
@Column(nullable = false)
@Size( @Size(
min = strMin, max = strMax, min = strMin, max = strMax,
message = "Author length must be " + strMin + "-" + strMax + " characters" message = "Author length must be " + strMin + "-" + strMax + " characters"
@ -113,7 +115,8 @@ public class Book {
// @DateTimeFormat(pattern = "yyyy") // @DateTimeFormat(pattern = "yyyy")
// private Timestamp year; // private Timestamp year;
// ... // ...
// TODO: Consider allowing 0 value if year is not known
@Column(nullable = true)
@Min( @Min(
value = yearMin, value = yearMin,
message = "Minimum allowed year: " + yearMin message = "Minimum allowed year: " + yearMin
@ -122,7 +125,7 @@ public class Book {
private int year; private int year;
////////// //////////
@Column(unique = true)
@Column(unique = true, nullable = false)
@NotBlank( @NotBlank(
message = "Fill the ISBN code form" message = "Fill the ISBN code form"
) )
@ -141,6 +144,7 @@ public class Book {
////////// //////////
@NumberFormat(style = Style.NUMBER, pattern = "#,###.###") @NumberFormat(style = Style.NUMBER, pattern = "#,###.###")
@Column(nullable = false)
@Digits( @Digits(
integer = 3, fraction = 2, integer = 3, fraction = 2,
message = "Invalid price, possibly too many decimals" message = "Invalid price, possibly too many decimals"


Loading…
Cancel
Save