Skip to content

Commit e50fd9a

Browse files
committed
[2.7] Close #1806 - Have to the ability to dynamically set the Validation Group during a transaction. Add tests, update copyright headers.
1 parent 116033f commit e50fd9a

File tree

9 files changed

+385
-15
lines changed

9 files changed

+385
-15
lines changed

foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/EntityManagerProperties.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -319,6 +319,21 @@ public class EntityManagerProperties {
319319
* )
320320
*/
321321
public static final String COMPOSITE_UNIT_PROPERTIES = PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES;
322+
323+
/**
324+
* Overrides the Bean Validation Group(s) that will execute during a prePersist event. This should be a class or class[].
325+
*/
326+
public static final String VALIDATION_GROUP_PRE_PERSIST = "eclipselink.validation.group.prePersist";
327+
328+
/**
329+
* Overrides the Bean Validation Group(s) that will execute during a preUpdate event. This should be a class or class[].
330+
*/
331+
public static final String VALIDATION_GROUP_PRE_UPDATE = "eclipselink.validation.group.preUpdate";
332+
333+
/**
334+
* Overrides the Bean Validation Group(s) that will execute during a preRemove event. This should be a class or class[].
335+
*/
336+
public static final String VALIDATION_GROUP_PRE_REMOVE = "eclipselink.validation.group.preRemove";
322337

323338
private static final Set<String> supportedProperties = new HashSet<String>() {
324339

@@ -344,6 +359,9 @@ public class EntityManagerProperties {
344359
add(PERSISTENCE_CONTEXT_COMMIT_ORDER);
345360
add(FLUSH_CLEAR_CACHE);
346361
add(COMPOSITE_UNIT_PROPERTIES);
362+
add(VALIDATION_GROUP_PRE_PERSIST);
363+
add(VALIDATION_GROUP_PRE_UPDATE);
364+
add(VALIDATION_GROUP_PRE_REMOVE);
347365
}
348366
};
349367

jpa/eclipselink.jpa.test/resource/eclipselink-beanvalidation-model/persistence.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
3-
Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
3+
Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
44
55
This program and the accompanying materials are made available under the
66
terms of the Eclipse Public License v. 2.0 which is available at
@@ -18,6 +18,7 @@
1818
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Employee</class>
1919
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Project</class>
2020
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Address</class>
21+
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Phone</class>
2122
<validation-mode>CALLBACK</validation-mode>
2223
</persistence-unit>
2324
</persistence>

jpa/eclipselink.jpa.test/resource/eclipselink-beanvalidation-model/server/persistence.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
3-
Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
3+
Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
44
55
This program and the accompanying materials are made available under the
66
terms of the Eclipse Public License v. 2.0 which is available at
@@ -19,6 +19,7 @@
1919
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Employee</class>
2020
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Project</class>
2121
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Address</class>
22+
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Phone</class>
2223
<validation-mode>CALLBACK</validation-mode>
2324
<properties>
2425
<property name="eclipselink.target-server" value="@server-platform@"/>

jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/beanvalidation/Employee.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -50,6 +50,10 @@ public class Employee {
5050
@Valid
5151
@Embedded
5252
private Address adress;
53+
54+
@Valid
55+
@Embedded
56+
private Phone phone;
5357

5458
// ===========================================================
5559
// getters and setters for the state fields
@@ -105,4 +109,11 @@ void m1() {
105109
return "Employee {Id:" + id + " name:" + name + "}";
106110
}
107111

112+
public Phone getPhone() {
113+
return phone;
114+
}
115+
116+
public void setPhone(Phone phone) {
117+
this.phone = phone;
118+
}
108119
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2009, 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
13+
// Contributors:
14+
15+
package org.eclipse.persistence.testing.models.jpa.beanvalidation;
16+
17+
public interface GermanPhone {
18+
19+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2009, 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
13+
// Contributors:
14+
15+
package org.eclipse.persistence.testing.models.jpa.beanvalidation;
16+
17+
import javax.persistence.Embeddable;
18+
import javax.validation.constraints.Pattern;
19+
import javax.validation.constraints.Size;
20+
21+
@Embeddable
22+
public class Phone {
23+
@Pattern(regexp = "^\\+1 \\([0-9]{3}\\) [0-9]{3}-[0-9]{4}$", groups = { USPhone.class })
24+
@Pattern(regexp = "^\\+49 \\([1-9]\\d{1,4}\\) \\d{3,8}-\\d{4}$", groups = { GermanPhone.class })
25+
String phone;
26+
27+
public Phone() {}
28+
29+
public Phone(String phone) {
30+
this.phone = phone;
31+
}
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2009, 2025 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
13+
// Contributors:
14+
15+
package org.eclipse.persistence.testing.models.jpa.beanvalidation;
16+
17+
public interface USPhone {
18+
19+
}

0 commit comments

Comments
 (0)