use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newJpaConfiguration.
@Override
public IConfiguration newJpaConfiguration(String entityResolver, String persistenceUnit, Map<Object, Object> overrides) {
getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
IConfiguration result = null;
try {
HibernatePersistenceProvider hibernatePersistenceProvider = new HibernatePersistenceProvider();
Method getEntityManagerFactoryBuilderOrNull = hibernatePersistenceProvider.getClass().getDeclaredMethod("getEntityManagerFactoryBuilderOrNull", new Class[] { String.class, Map.class });
getEntityManagerFactoryBuilderOrNull.setAccessible(true);
Object entityManagerFactoryBuilder = getEntityManagerFactoryBuilderOrNull.invoke(hibernatePersistenceProvider, new Object[] { persistenceUnit, overrides });
if (entityManagerFactoryBuilder == null) {
throw new HibernateConsoleRuntimeException("Persistence unit not found: '" + persistenceUnit + "'.");
}
Method buildServiceRegistry = entityManagerFactoryBuilder.getClass().getMethod("buildServiceRegistry", new Class[0]);
Object serviceRegistry = buildServiceRegistry.invoke(entityManagerFactoryBuilder, (Object[]) null);
Class<?> serviceRegistryClass = StandardClassLoaderDelegateImpl.INSTANCE.classForName("org.hibernate.service.ServiceRegistry");
Method buildHibernateConfiguration = entityManagerFactoryBuilder.getClass().getMethod("buildHibernateConfiguration", new Class[] { serviceRegistryClass });
Configuration configuration = (Configuration) buildHibernateConfiguration.invoke(entityManagerFactoryBuilder, new Object[] { serviceRegistry });
result = facadeFactory.createConfiguration(configuration);
} catch (SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new HibernateConsoleRuntimeException(e);
}
return result;
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newJpaConfiguration.
@Override
public IConfiguration newJpaConfiguration(String entityResolver, String persistenceUnit, Map<Object, Object> overrides) {
getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
if (StringHelper.isNotEmpty(entityResolver)) {
try {
Class<?> resolver = ReflectHelper.classForName(entityResolver, this.getClass());
Object object = resolver.newInstance();
ejb3Configuration.setEntityResolver((EntityResolver) object);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new HibernateConsoleRuntimeException(e);
}
}
ejb3Configuration.setProperty("hibernate.validator.autoregister_listeners", "false");
ejb3Configuration.setProperty("hibernate.validator.apply_to_ddl", "false");
ejb3Configuration.configure(persistenceUnit, overrides);
Configuration configuration = ejb3Configuration.getHibernateConfiguration();
return facadeFactory.createConfiguration(configuration);
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newReverseEngineeringStrategy.
private Object newReverseEngineeringStrategy(final String className, Object delegate) {
try {
Class<?> clazz = ReflectHelper.classForName(className);
Class<?> revEngClass = ReflectHelper.classForName("org.hibernate.cfg.reveng.ReverseEngineeringStrategy");
Constructor<?> constructor = clazz.getConstructor(new Class[] { revEngClass });
return constructor.newInstance(new Object[] { delegate });
} catch (NoSuchMethodException e) {
try {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Class<?> clazz = null;
if (contextClassLoader != null) {
clazz = contextClassLoader.loadClass(className);
} else {
clazz = Class.forName(className);
}
if (clazz != null) {
return clazz.newInstance();
} else {
throw new HibernateConsoleRuntimeException("Class " + className + " could not be found.");
}
} catch (Exception eq) {
throw new HibernateConsoleRuntimeException(eq);
}
} catch (Exception e) {
throw new HibernateConsoleRuntimeException(e);
}
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newDialect.
@Override
public String newDialect(Properties properties, final Connection connection) {
ServiceRegistry serviceRegistry = buildServiceRegistry(properties);
DialectFactory dialectFactory = serviceRegistry.getService(DialectFactory.class);
Dialect dialect = dialectFactory.buildDialect(properties, new DialectResolutionInfoSource() {
@Override
public DialectResolutionInfo getDialectResolutionInfo() {
try {
return new DatabaseMetaDataDialectResolutionInfoAdapter(connection.getMetaData());
} catch (SQLException sqlException) {
throw new HibernateConsoleRuntimeException("Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect to use", sqlException);
}
}
});
return dialect != null ? dialect.toString() : null;
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ConsoleConfigurationTest method testBuildConfiguration.
@Test
public void testBuildConfiguration() {
MockCCListener listener = new MockCCListener();
Assert.assertTrue(consoleCfg.getConsoleConfigurationListeners().length == 1);
consoleCfg.addConsoleConfigurationListener(listener);
consoleCfg.build();
Assert.assertEquals(0, listener.factoryBuilt);
consoleCfg.buildSessionFactory();
Assert.assertEquals(1, listener.factoryBuilt);
try {
consoleCfg.buildSessionFactory();
Assert.fail(TestConsoleMessages.ConsoleConfigurationTest_factory_already_exists);
} catch (HibernateConsoleRuntimeException hcre) {
}
// $NON-NLS-1$
QueryPage qp = consoleCfg.executeHQLQuery("from java.lang.Object");
Assert.assertNotNull(qp);
Assert.assertEquals(1, listener.queryCreated);
consoleCfg.closeSessionFactory();
Assert.assertEquals(1, listener.factoryClosing);
}
Aggregations