Skip to content

Commit f2d0ded

Browse files
committed
avoid use of BootstrapServiceRegistryBuilder in MockSessionFactory
so we don't need to go locating and instantiating unnecessary services
1 parent 29a7148 commit f2d0ded

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
2424
import org.hibernate.boot.model.relational.Database;
2525
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
26-
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
2726
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
27+
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
2828
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
29+
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
2930
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
31+
import org.hibernate.boot.registry.selector.internal.StrategySelectorImpl;
3032
import org.hibernate.boot.spi.BootstrapContext;
3133
import org.hibernate.boot.spi.MappingDefaults;
3234
import org.hibernate.boot.spi.MetadataBuildingContext;
@@ -161,25 +163,31 @@ public abstract class MockSessionFactory
161163
private final MetadataContext metadataContext;
162164

163165
public MockSessionFactory() {
164-
165-
serviceRegistry = StandardServiceRegistryImpl.create(
166-
new BootstrapServiceRegistryBuilder().applyClassLoaderService(new ClassLoaderServiceImpl() {
167-
@Override
168-
@SuppressWarnings("unchecked")
169-
public Class<?> classForName(String className) {
170-
try {
171-
return super.classForName(className);
172-
}
173-
catch (ClassLoadingException e) {
174-
if (isClassDefined(className)) {
175-
return Object[].class;
176-
}
177-
else {
178-
throw e;
179-
}
180-
}
166+
final ClassLoaderService classLoaderService = new ClassLoaderServiceImpl() {
167+
@Override
168+
@SuppressWarnings("unchecked")
169+
public Class<?> classForName(String className) {
170+
try {
171+
return super.classForName( className );
172+
}
173+
catch (ClassLoadingException e) {
174+
if ( isClassDefined( className ) ) {
175+
return Object[].class;
176+
}
177+
else {
178+
throw e;
181179
}
182-
}).build(),
180+
}
181+
}
182+
};
183+
serviceRegistry = StandardServiceRegistryImpl.create(
184+
new BootstrapServiceRegistryImpl(
185+
true,
186+
classLoaderService,
187+
new StrategySelectorImpl( classLoaderService ),
188+
() -> emptyList()
189+
),
190+
// new BootstrapServiceRegistryBuilder().applyClassLoaderService( classLoaderService ).build(),
183191
singletonList(MockJdbcServicesInitiator.INSTANCE),
184192
emptyList(),
185193
emptyMap()

0 commit comments

Comments
 (0)