use of org.jboss.tools.hibernate.runtime.spi.HibernateException in project jbosstools-hibernate by jbosstools.
the class LazyDatabaseSchemaWorkbenchAdapter method readDatabaseSchema.
protected IDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final IReverseEngineeringStrategy strategy) {
final IConfiguration configuration = consoleConfiguration.buildWith(null, false);
return (IDatabaseCollector) consoleConfiguration.execute(new ExecutionContext.Command() {
public Object execute() {
IDatabaseCollector db = null;
try {
IService service = consoleConfiguration.getHibernateExtension().getHibernateService();
IJDBCReader reader = service.newJDBCReader(configuration, strategy);
db = service.newDatabaseCollector(reader);
reader.readDatabaseSchema(db, new ProgressListener(monitor));
} catch (UnsupportedOperationException he) {
throw new HibernateException(he);
} catch (Exception he) {
he.printStackTrace();
throw new HibernateException(he.getMessage(), he.getCause());
}
return db;
}
});
}
use of org.jboss.tools.hibernate.runtime.spi.HibernateException 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 HibernateException(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.jboss.tools.hibernate.runtime.spi.HibernateException 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 HibernateException("Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect to use", sqlException);
}
}
});
return dialect != null ? dialect.toString() : null;
}
use of org.jboss.tools.hibernate.runtime.spi.HibernateException in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newReverseEngineeringStrategy.
@SuppressWarnings("unchecked")
private ReverseEngineeringStrategy newReverseEngineeringStrategy(final String className, ReverseEngineeringStrategy delegate) {
try {
Class<ReverseEngineeringStrategy> clazz = (Class<ReverseEngineeringStrategy>) ReflectHelper.classForName(className);
Constructor<ReverseEngineeringStrategy> constructor = clazz.getConstructor(new Class[] { ReverseEngineeringStrategy.class });
return constructor.newInstance(new Object[] { delegate });
} catch (NoSuchMethodException e) {
try {
Class<?> clazz = ReflectHelper.classForName(className);
ReverseEngineeringStrategy rev = (ReverseEngineeringStrategy) clazz.newInstance();
return rev;
} catch (Exception eq) {
throw new HibernateException(eq);
}
} catch (Exception e) {
throw new HibernateException(e);
}
}
use of org.jboss.tools.hibernate.runtime.spi.HibernateException 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 HibernateException("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 HibernateException(e);
}
return result;
}
Aggregations