Skip to content

Commit 072879a

Browse files
Merge pull request #214 from xdev-software/jakarta.validation.constraints
Jakarta.validation.constraints
2 parents 4f1cc86 + 78a6794 commit 072879a

File tree

8 files changed

+471
-19
lines changed

8 files changed

+471
-19
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
* Auto-Fix problems with adding ids to entities with existing data store.
1919

20-
~~~~
2120
# 2.3.0
2221

2322
* Add support for shutting down the storage during application shutdown

docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
** xref:features/transactions.adoc[Transactions]
1010
** xref:features/versions.adoc[Versions]
1111
** xref:features/rest-api.adoc[REST Interface]
12+
** xref:features/validation-constraints.adoc[Validation Constraints]
1213
* xref:migration.adoc[Migration from JPA]
1314
* xref:known-issues.adoc[Known issues]

docs/modules/ROOT/pages/features/features.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
* xref:features/transactions.adoc[Transactions]
77
* xref:features/versions.adoc[Versions]
88
* xref:features/rest-api.adoc[REST Interface]
9+
* xref:features/validation-constraints.adoc[Validation Constraints]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
= Validation Constraints
2+
3+
By using the https://jakarta.ee/learn/docs/jakartaee-tutorial/current/beanvalidation/bean-validation/bean-validation.html[Jakarta Bean Validation Constraints] developers with {product-name} can easily limit the allowed input of entities.
4+
Here is a full list of supported validations: https://jakarta.ee/learn/docs/jakartaee-tutorial/current/beanvalidation/bean-validation/bean-validation.html#_using_jakarta_bean_validation_constraints[https://jakarta.ee/learn]
5+
6+
[source,java,title="https://github.com/xdev-software/spring-data-eclipse-store/blob/develop/spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/model/Person.java[Example from complex demo]"]
7+
----
8+
package software.xdev.spring.data.eclipse.store.demo.complex.model;
9+
10+
import jakarta.validation.constraints.NotBlank;
11+
12+
public class Person extends BaseEntity
13+
{
14+
@NotBlank
15+
private String firstName;
16+
//...
17+
----
18+
19+
The ``jakarta.validation.Validator`` is provided by the https://github.com/xdev-software/spring-data-eclipse-store/tree/develop/spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java[``EclipseStoreClientConfiguration``] and can be changed in the project-specific configuration.

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/model/Person.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
*/
1616
package software.xdev.spring.data.eclipse.store.demo.complex.model;
1717

18+
import jakarta.validation.constraints.NotBlank;
19+
20+
1821
public class Person extends BaseEntity
1922
{
23+
@NotBlank
2024
private String firstName;
2125

2226
private String lastName;

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import jakarta.validation.Validation;
1919
import jakarta.validation.Validator;
20+
import jakarta.validation.ValidatorFactory;
2021

2122
import org.eclipse.serializer.reflect.ClassLoaderProvider;
2223
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
@@ -206,6 +207,9 @@ public void shutdownStorageOnContextClosed(final ContextClosedEvent event)
206207
@Bean
207208
public Validator getValidator()
208209
{
209-
return Validation.buildDefaultValidatorFactory().getValidator();
210+
try(ValidatorFactory factory = Validation.buildDefaultValidatorFactory())
211+
{
212+
return factory.getValidator();
213+
}
210214
}
211215
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/constraints/ConstraintDaoObject.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class ConstraintDaoObject
6565
@DecimalMin("5.00")
6666
BigDecimal discountMin5;
6767

68-
@DecimalMax("30.00")
68+
@DecimalMax("20.00")
6969
BigDecimal discountMax20;
7070

7171
@Email
@@ -116,8 +116,8 @@ public class ConstraintDaoObject
116116
@PositiveOrZero
117117
int positiveOrZeroField;
118118

119-
@Size(min = 2, max = 240)
120-
String messageMin2AndMax240;
119+
@Size(min = 2, max = 10)
120+
String messageMin2AndMax10;
121121

122122
public ConstraintDaoObject()
123123
{
@@ -141,7 +141,7 @@ public ConstraintDaoObject()
141141
this.phoneNumber = "(123)456-7890";
142142
this.area = BigDecimal.valueOf(1);
143143
this.positiveOrZeroField = 1;
144-
this.messageMin2AndMax240 = "..";
144+
this.messageMin2AndMax10 = "..";
145145
}
146146

147147
@AssertFalse
@@ -186,12 +186,12 @@ public void setDiscountMin5(final @DecimalMin("5.00") BigDecimal discountMin5)
186186
this.discountMin5 = discountMin5;
187187
}
188188

189-
public @DecimalMax("30.00") BigDecimal getDiscountMax20()
189+
public @DecimalMax("20.00") BigDecimal getDiscountMax20()
190190
{
191191
return this.discountMax20;
192192
}
193193

194-
public void setDiscountMax20(final @DecimalMax("30.00") BigDecimal discountMax20)
194+
public void setDiscountMax20(final @DecimalMax("20.00") BigDecimal discountMax20)
195195
{
196196
this.discountMax20 = discountMax20;
197197
}
@@ -361,13 +361,13 @@ public void setPositiveOrZeroField(@PositiveOrZero final int positiveOrZeroField
361361
this.positiveOrZeroField = positiveOrZeroField;
362362
}
363363

364-
public @Size(min = 2, max = 240) String getMessageMin2AndMax240()
364+
public @Size(min = 2, max = 10) String getMessageMin2AndMax10()
365365
{
366-
return this.messageMin2AndMax240;
366+
return this.messageMin2AndMax10;
367367
}
368368

369-
public void setMessageMin2AndMax240(final @Size(min = 2, max = 240) String messageMin2AndMax240)
369+
public void setMessageMin2AndMax10(final @Size(min = 2, max = 10) String messageMin2AndMax10)
370370
{
371-
this.messageMin2AndMax240 = messageMin2AndMax240;
371+
this.messageMin2AndMax10 = messageMin2AndMax10;
372372
}
373373
}

0 commit comments

Comments
 (0)