use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.
the class AbstractEnhancerTestTask method prepare.
public final void prepare(Configuration config) {
config.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
Class<?>[] resources = getAnnotatedClasses();
for (Class<?> resource : resources) {
config.addAnnotatedClass(resource);
}
StandardServiceRegistryBuilder serviceBuilder = new StandardServiceRegistryBuilder();
serviceBuilder.addService(ClassLoaderService.class, new ClassLoaderServiceImpl(Thread.currentThread().getContextClassLoader()));
serviceBuilder.applySettings(config.getProperties());
serviceRegistry = serviceBuilder.build();
factory = config.buildSessionFactory(serviceRegistry);
}
use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.
the class ClassLoaderServiceImplTest method testSystemClassLoaderNotOverriding.
/**
* Test for bug: HHH-7084
*/
@Test
public void testSystemClassLoaderNotOverriding() throws IOException, ClassNotFoundException {
Class<?> testClass = Entity.class;
// Check that class is accessible by SystemClassLoader.
ClassLoader.getSystemClassLoader().loadClass(testClass.getName());
// Create ClassLoader with overridden class.
TestClassLoader anotherLoader = new TestClassLoader();
anotherLoader.overrideClass(testClass);
Class<?> anotherClass = anotherLoader.loadClass(testClass.getName());
Assert.assertNotSame(testClass, anotherClass);
// Check ClassLoaderServiceImpl().classForName() returns correct class (not from current ClassLoader).
ClassLoaderServiceImpl loaderService = new ClassLoaderServiceImpl(anotherLoader);
Class<Object> objectClass = loaderService.classForName(testClass.getName());
Assert.assertSame("Should not return class loaded from the parent classloader of ClassLoaderServiceImpl", objectClass, anotherClass);
}
use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.
the class AbstractCachingTestTask method prepare.
@Override
public void prepare() {
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
registryBuilder.applySetting(AvailableSettings.GENERATE_STATISTICS, "true");
registryBuilder.applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop");
registryBuilder.applySetting(AvailableSettings.USE_SECOND_LEVEL_CACHE, "true");
registryBuilder.addService(ClassLoaderService.class, new ClassLoaderServiceImpl(Thread.currentThread().getContextClassLoader()));
StandardServiceRegistry registry = registryBuilder.build();
MetadataSources metadataSources = new MetadataSources(registry);
metadataSources.addAnnotatedClass(Document.class);
sessionFactory = (SessionFactoryImplementor) metadataSources.buildMetadata().buildSessionFactory();
}
use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.
the class MapProxyTest method shouldGenerateClassWithAppropriateAccessorsForBoolean.
@Test
public void shouldGenerateClassWithAppropriateAccessorsForBoolean() throws Exception {
//given
Map<String, Object> map = new HashMap<String, Object>();
map.put("checkbox", true);
Map<String, Class<?>> properties = new HashMap<String, Class<?>>();
properties.put("checkbox", Boolean.class);
//when
Class testClass = MapProxyTool.classForName("TestClass3", properties, new ClassLoaderServiceImpl());
Object testClassInstance = testClass.getConstructor(Map.class).newInstance(map);
//then
Getter getter = ReflectionTools.getGetter(testClass, "checkbox", "property", serviceRegistry);
Assert.assertTrue((Boolean) getter.get(testClassInstance));
}
use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.
the class MapProxyTest method shouldGenerateClassWithAppropriateSetter.
@Test
public void shouldGenerateClassWithAppropriateSetter() throws Exception {
//given
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Class<?>> properties = new HashMap<String, Class<?>>();
properties.put("age", Integer.class);
//when
Class testClass = MapProxyTool.classForName("TestClass2", properties, new ClassLoaderServiceImpl());
Object testClassInstance = testClass.getConstructor(Map.class).newInstance(map);
//then
Setter setter = ReflectionTools.getSetter(testClass, "age", "property", serviceRegistry);
int ageExpected = 14;
setter.set(testClassInstance, ageExpected, null);
Object age = map.get("age");
Assert.assertEquals(ageExpected, age);
}
Aggregations