Skip to content

Commit a9d6787

Browse files
committed
Introduce conditional activation of Hibernate substitutions
Closes gh-31452
1 parent 9af239c commit a9d6787

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2002-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.orm.jpa.vendor;
18+
19+
import java.util.function.Predicate;
20+
21+
/**
22+
* Predicate intended to enabled the related GraalVM substitution only when the class is present in the classpath.
23+
*
24+
* @author Sebastien Deleuze
25+
* @since 6.1
26+
*/
27+
class SubstituteOnlyIfPresent implements Predicate<String> {
28+
29+
@Override
30+
public boolean test(String type) {
31+
try {
32+
Class.forName(type, false, getClass().getClassLoader());
33+
return true;
34+
}
35+
catch (ClassNotFoundException | NoClassDefFoundError ex) {
36+
return false;
37+
}
38+
}
39+
}

spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Sebastien Deleuze
3232
* @since 6.1
3333
*/
34-
@TargetClass(className = "org.hibernate.bytecode.internal.none.BytecodeProviderImpl")
34+
@TargetClass(className = "org.hibernate.bytecode.internal.none.BytecodeProviderImpl", onlyWith = SubstituteOnlyIfPresent.class)
3535
final class Target_BytecodeProvider {
3636

3737
@Substitute

spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProviderInitiator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @author Sebastien Deleuze
3333
* @since 6.1
3434
*/
35-
@TargetClass(className = "org.hibernate.bytecode.internal.BytecodeProviderInitiator")
35+
@TargetClass(className = "org.hibernate.bytecode.internal.BytecodeProviderInitiator", onlyWith = SubstituteOnlyIfPresent.class)
3636
final class Target_BytecodeProviderInitiator {
3737

3838
@Alias

0 commit comments

Comments
 (0)