Search in sources :

Example 26 with HibernateException

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());
}
Also used : H2Dialect(org.hibernate.dialect.H2Dialect) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.jupiter.api.Test)

Example 27 with HibernateException

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());
}
Also used : HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.jupiter.api.Test)

Example 28 with HibernateException

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;
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) DOMWriter(org.dom4j.io.DOMWriter) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Node(org.dom4j.Node) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) MappingException(org.jboss.tools.hibernate.exception.MappingException) SAXParseException(org.xml.sax.SAXParseException) DocumentException(org.dom4j.DocumentException) XMLHelper(org.hibernate.util.xpl.XMLHelper) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) File(java.io.File)

Example 29 with HibernateException

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);
}
Also used : Ejb3Configuration(org.hibernate.ejb.Ejb3Configuration) Configuration(org.hibernate.cfg.Configuration) JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) AnnotationConfiguration(org.hibernate.cfg.AnnotationConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) Ejb3Configuration(org.hibernate.ejb.Ejb3Configuration)

Example 30 with HibernateException

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);
    }
}
Also used : HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) DefaultReverseEngineeringStrategy(org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy) ReverseEngineeringStrategy(org.hibernate.cfg.reveng.ReverseEngineeringStrategy) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException)

Aggregations

HibernateException (org.jboss.tools.hibernate.runtime.spi.HibernateException)36 SQLException (java.sql.SQLException)18 PersistentClass (org.hibernate.mapping.PersistentClass)12 RootClass (org.hibernate.mapping.RootClass)12 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)12 Dialect (org.hibernate.dialect.Dialect)9 DatabaseMetaDataDialectResolutionInfoAdapter (org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter)9 DialectFactory (org.hibernate.engine.jdbc.dialect.spi.DialectFactory)9 DialectResolutionInfo (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)9 DialectResolutionInfoSource (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource)9 ServiceRegistry (org.hibernate.service.ServiceRegistry)9 MetaDataDialect (org.hibernate.cfg.reveng.dialect.MetaDataDialect)8 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)8 Configuration (org.hibernate.cfg.Configuration)4 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)4 DefaultReverseEngineeringStrategy (org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy)4 ReverseEngineeringStrategy (org.hibernate.cfg.reveng.ReverseEngineeringStrategy)4 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)4 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)4 ISchemaExport (org.jboss.tools.hibernate.runtime.spi.ISchemaExport)4