use of org.jboss.tools.hibernate.exception.MappingException in project jbosstools-hibernate by jbosstools.
the class JDBCToHibernateTypeHelper method getJDBCType.
public static int getJDBCType(String value) {
checkTypes();
Integer number = (Integer) jdbcTypes.get(value);
if (number == null) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new MappingException("jdbc-type: " + value + " is not a known JDBC Type nor a valid number");
}
} else {
return number.intValue();
}
}
use of org.jboss.tools.hibernate.exception.MappingException 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;
}
}
}
Aggregations