use of org.jboss.tools.hibernate.runtime.spi.HibernateException in project jbosstools-hibernate by jbosstools.
the class SchemaExportFacadeTest method testGetExceptions.
@SuppressWarnings("unchecked")
@Test
public void testGetExceptions() throws Throwable {
String urlString = "jdbc:h2:mem:create_test";
configuration.setProperty(Environment.URL, urlString);
configuration.setProperty(Environment.DIALECT, H2Dialect.class.getName());
SchemaExport schemaExport = new SchemaExport(configuration);
ISchemaExport schemaExportFacade = FACADE_FACTORY.createSchemaExport(schemaExport);
assertTrue(schemaExportFacade.getExceptions().isEmpty());
schemaExport.getExceptions().add(new HibernateException("blah"));
assertFalse(schemaExportFacade.getExceptions().isEmpty());
}
use of org.jboss.tools.hibernate.runtime.spi.HibernateException in project jbosstools-hibernate by jbosstools.
the class SchemaExportFacadeTest method testGetExceptions.
@SuppressWarnings("unchecked")
@Test
public void testGetExceptions() throws Throwable {
String urlString = "jdbc:h2:mem:create_test";
configuration.setProperty(Environment.URL, urlString);
SchemaExport schemaExport = new SchemaExport(configuration);
ISchemaExport schemaExportFacade = FACADE_FACTORY.createSchemaExport(schemaExport);
assertTrue(schemaExportFacade.getExceptions().isEmpty());
schemaExport.getExceptions().add(new HibernateException("blah"));
assertFalse(schemaExportFacade.getExceptions().isEmpty());
}
use of org.jboss.tools.hibernate.runtime.spi.HibernateException in project jbosstools-hibernate by jbosstools.
the class ConfigurationFactory method loadConfigurationXML.
@SuppressWarnings("unchecked")
private IConfiguration loadConfigurationXML(IConfiguration localCfg, boolean includeMappings, EntityResolver entityResolver) {
File configXMLFile = prefs.getConfigXMLFile();
if (!includeMappings) {
org.dom4j.Document doc;
XMLHelper xmlHelper = new XMLHelper();
InputStream stream = null;
// $NON-NLS-1$
String resourceName = "<unknown>";
if (configXMLFile != null) {
resourceName = configXMLFile.toString();
try {
stream = new FileInputStream(configXMLFile);
} catch (FileNotFoundException e1) {
throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_access + configXMLFile, e1);
}
} else {
// $NON-NLS-1$
resourceName = "/hibernate.cfg.xml";
if (checkHibernateResoureExistence(resourceName)) {
// simulate hibernate's
stream = getResourceAsStream(resourceName);
// default look up
} else {
return localCfg;
}
}
try {
List<SAXParseException> errors = new ArrayList<SAXParseException>();
doc = xmlHelper.createSAXReader(resourceName, errors, entityResolver).read(new InputSource(stream));
if (errors.size() != 0) {
throw new MappingException(ConsoleMessages.ConsoleConfiguration_invalid_configuration, errors.get(0));
}
List<Node> list = doc.getRootElement().element("session-factory").elements(// $NON-NLS-1$ //$NON-NLS-2$
"mapping");
for (Node element : list) {
element.getParent().remove(element);
}
DOMWriter dw = new DOMWriter();
Document document = dw.write(doc);
return localCfg.configure(document);
} catch (DocumentException e) {
throw new HibernateException(ConsoleMessages.ConsoleConfiguration_could_not_parse_configuration + resourceName, e);
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException ioe) {
// log.warn( "could not close input stream for: " + resourceName, ioe );
}
}
} else {
if (configXMLFile != null) {
return localCfg.configure(configXMLFile);
} else {
IConfiguration resultCfg = localCfg;
if (checkHibernateResoureExistence("/hibernate.cfg.xml")) {
// $NON-NLS-1$
resultCfg = localCfg.configure();
}
return resultCfg;
}
}
}
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.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 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);
}
}
Aggregations