Search in sources :

Example 31 with HibernateConsoleRuntimeException

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 {
            Class<?> clazz = ReflectHelper.classForName(className);
            return clazz.newInstance();
        } catch (Exception eq) {
            throw new HibernateConsoleRuntimeException(eq);
        }
    } catch (Exception e) {
        throw new HibernateConsoleRuntimeException(e);
    }
}
Also used : PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) SQLException(java.sql.SQLException) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Example 32 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.

the class EclipseConsoleConfigurationPreferences method readStateFrom.

public static EclipseConsoleConfigurationPreferences[] readStateFrom(File f) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser;
    try {
        parser = factory.newDocumentBuilder();
        Document doc = parser.parse(f);
        Element root = doc.getDocumentElement();
        // TODO: only get nearest children.
        NodeList elementsByTagName = root.getElementsByTagName(CONFIGURATION_TAG);
        EclipseConsoleConfigurationPreferences[] result = new EclipseConsoleConfigurationPreferences[elementsByTagName.getLength()];
        for (int i = 0; i < elementsByTagName.getLength(); i++) {
            result[i] = new EclipseConsoleConfigurationPreferences();
            result[i].readStateFrom((Element) elementsByTagName.item(i));
        }
        return result;
    } catch (SAXException sa) {
        throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.EclipseConsoleConfigurationPreferences_errors_while_parsing + f, sa);
    } catch (ParserConfigurationException e) {
        throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.EclipseConsoleConfigurationPreferences_errors_while_parsing + f, e);
    } catch (IOException e) {
        throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.EclipseConsoleConfigurationPreferences_errors_while_parsing + f, e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 33 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.

the class EclipseConsoleConfigurationPreferences method getCustomClassPathURLS.

public URL[] getCustomClassPathURLS() {
    try {
        IJavaProject project = ProjectUtils.findJavaProject(getProjectName());
        String[] additonal = new String[0];
        if (project != null && useProjectClasspath() && project.exists()) {
            try {
                additonal = JavaRuntime.computeDefaultRuntimeClassPath(project);
            } catch (CoreException e) {
                throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.EclipseConsoleConfigurationPreferences_could_not_compute_def_classpath + project);
            }
        }
        URL[] rawLocationsURLForResources = ClassLoaderHelper.getRawLocationsURLForResources(customClasspath);
        URL[] result = new URL[rawLocationsURLForResources.length + additonal.length];
        for (int i = 0; i < rawLocationsURLForResources.length; i++) {
            result[i] = rawLocationsURLForResources[i];
        }
        for (int i = 0; i < additonal.length; i++) {
            String url = additonal[i];
            result[i + rawLocationsURLForResources.length] = new File(url).toURI().toURL();
        }
        return result;
    } catch (MalformedURLException mue) {
        throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.EclipseConsoleConfigurationPreferences_could_not_resolve_classpaths, mue);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) File(java.io.File) URL(java.net.URL)

Example 34 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.

the class BuildSessionFactoryAction method doRun.

protected void doRun() {
    for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext(); ) {
        try {
            Object node = i.next();
            if (node instanceof ConsoleConfiguration) {
                ConsoleConfiguration config = (ConsoleConfiguration) node;
                if (config.isSessionFactoryCreated()) {
                    config.reset();
                } else {
                    config.build();
                    config.buildSessionFactory();
                }
                updateState(config);
            }
        } catch (HibernateConsoleRuntimeException he) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.BuildSessionFactoryAction_exception_while_start_hibernate, he);
        } catch (UnsupportedClassVersionError ucve) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.BuildSessionFactoryAction_start_hibernate_resulted, ucve);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Aggregations

HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)34 SQLException (java.sql.SQLException)10 File (java.io.File)8 CoreException (org.eclipse.core.runtime.CoreException)7 PersistentClass (org.hibernate.mapping.PersistentClass)7 RootClass (org.hibernate.mapping.RootClass)7 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)7 Properties (java.util.Properties)5 MetaDataDialect (org.hibernate.cfg.reveng.dialect.MetaDataDialect)5 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)5 Dialect (org.hibernate.dialect.Dialect)5 DatabaseMetaDataDialectResolutionInfoAdapter (org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter)5 DialectFactory (org.hibernate.engine.jdbc.dialect.spi.DialectFactory)5 DialectResolutionInfo (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)5 DialectResolutionInfoSource (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource)5 ServiceRegistry (org.hibernate.service.ServiceRegistry)5 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)5 IOException (java.io.IOException)4 Configuration (org.hibernate.cfg.Configuration)3 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)3