Skip to content

Commit 083fd05

Browse files
committed
HHH-18964 simplify DefaultJtaPlatformSelector
1 parent 96b5d60 commit 083fd05

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/DefaultJtaPlatformSelector.java

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,60 +24,46 @@ public Class<? extends JtaPlatform> resolve(final String name) {
2424
if ( name.isBlank() ) {
2525
return null;
2626
}
27-
//Let's organize all string matches in groups by first letter:
28-
return switch ( name.charAt( 0 ) ) {
29-
case 'J'-> caseJ( name );
30-
case 'W'-> caseW( name );
31-
case 'o'-> caseLegacy( name, this );
32-
default -> caseOthers( name );
33-
};
34-
}
35-
36-
private static Class<? extends JtaPlatform> caseJ(final String name) {
37-
return switch ( name ) {
38-
case "JBossAS" -> JBossAppServerJtaPlatform.class;
39-
case "JBossTS" -> JBossStandAloneJtaPlatform.class;
40-
case null, default -> null;
41-
};
42-
}
43-
44-
private static Class<? extends JtaPlatform> caseW(final String name) {
45-
return switch ( name ) {
46-
case "Weblogic" -> WeblogicJtaPlatform.class;
47-
case "WebSphereLiberty" -> WebSphereLibertyJtaPlatform.class;
48-
case "WebSphere" -> WebSphereJtaPlatform.class;
49-
case "WebSphereExtended" -> WebSphereExtendedJtaPlatform.class;
50-
case null, default -> null;
51-
};
27+
if ( name.startsWith( "org." ) ) {
28+
return legacy( name, this );
29+
}
30+
else {
31+
return switch ( name ) {
32+
case "JBossAS" -> JBossAppServerJtaPlatform.class;
33+
case "JBossTS" -> JBossStandAloneJtaPlatform.class;
34+
case "Weblogic" -> WeblogicJtaPlatform.class;
35+
case "WebSphereLiberty" -> WebSphereLibertyJtaPlatform.class;
36+
case "WebSphere" -> WebSphereJtaPlatform.class;
37+
case "WebSphereExtended" -> WebSphereExtendedJtaPlatform.class;
38+
case "Atomikos" -> AtomikosJtaPlatform.class;
39+
case "Resin" -> ResinJtaPlatform.class;
40+
default -> null;
41+
};
42+
}
5243
}
5344

54-
private static Class<? extends JtaPlatform> caseOthers(final String name) {
55-
return switch ( name ) {
56-
case "Atomikos" -> AtomikosJtaPlatform.class;
57-
case "Resin" -> ResinJtaPlatform.class;
58-
case null, default -> null;
59-
};
60-
}
6145

6246
/**
6347
* Special case: we have several old fully qualified classnames which need to
6448
* be remapped to their new names for backwards compatibility reasons.
6549
*/
66-
private static Class<? extends JtaPlatform> caseLegacy(
50+
private static Class<? extends JtaPlatform> legacy(
6751
final String name,
6852
final DefaultJtaPlatformSelector defaultJtaPlatformSelector) {
6953

7054
//First, let's deal with the special cases which don't follow any recognizable pattern:
71-
if ( name.equals( "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" ) ) {
72-
return JBossAppServerJtaPlatform.class;
73-
}
74-
if ( name.equals( "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" ) ) {
75-
return JBossStandAloneJtaPlatform.class;
76-
}
77-
//This one shouldn't be necessary as it matches the implementation FQN, but let's translate the existing
78-
//code faithfully.
79-
if ( name.equals( "org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform" ) ) {
80-
return WebSphereLibertyJtaPlatform.class;
55+
switch ( name ) {
56+
case "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" -> {
57+
return JBossAppServerJtaPlatform.class;
58+
}
59+
case "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" -> {
60+
return JBossStandAloneJtaPlatform.class;
61+
}
62+
//This one shouldn't be necessary as it matches the implementation FQN,
63+
//but let's translate the existing code faithfully.
64+
case "org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform" -> {
65+
return WebSphereLibertyJtaPlatform.class;
66+
}
8167
}
8268

8369
//All other ones follow a pattern, beginning with the same prefix and ending with the same postfix,

0 commit comments

Comments
 (0)