Search in sources :

Example 31 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) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) Ejb3Configuration(org.hibernate.ejb.Ejb3Configuration)

Example 32 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)

Example 33 with HibernateException

use of org.jboss.tools.hibernate.runtime.spi.HibernateException 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 HibernateException(eq);
        }
    } catch (Exception e) {
        throw new HibernateException(e);
    }
}
Also used : HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) 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) SQLException(java.sql.SQLException)

Example 34 with HibernateException

use of org.jboss.tools.hibernate.runtime.spi.HibernateException in project jbosstools-hibernate by jbosstools.

the class ConsoleExtension method hqlCodeComplete.

public CompletionProposalsResult hqlCodeComplete(String query, int startPosition, int currentOffset) {
    HQLCompletionHandler handler = new HQLCompletionHandler(startPosition);
    if (!hibernateExtension.hasConfiguration()) {
        try {
            hibernateExtension.build();
            hibernateExtension.buildMappings();
        } catch (HibernateException e) {
        // FIXME
        // String mess =
        // NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
        // consoleConfiguration.getName());
        // HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
        }
    }
    IHQLCodeAssist hqlEval = hibernateExtension.getHibernateService().newHQLCodeAssist(hibernateExtension.getConfiguration());
    query = query.replace('\t', ' ');
    hqlEval.codeComplete(query, currentOffset, handler);
    return new CompletionProposalsResult(handler.getCompletionProposals(), handler.getLastErrorMessage());
}
Also used : HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IHQLCodeAssist(org.jboss.tools.hibernate.runtime.spi.IHQLCodeAssist)

Example 35 with HibernateException

use of org.jboss.tools.hibernate.runtime.spi.HibernateException in project jbosstools-hibernate by jbosstools.

the class DTDEntityResolver method getUserResourceAsStream.

private InputStream getUserResourceAsStream(String resource) {
    // $NON-NLS-1$
    boolean hasLeadingSlash = resource.startsWith("/");
    String stripped = hasLeadingSlash ? resource.substring(1) : resource;
    InputStream stream = null;
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader != null) {
        stream = classLoader.getResourceAsStream(resource);
        if (stream == null && hasLeadingSlash) {
            stream = classLoader.getResourceAsStream(stripped);
        }
    }
    if (stream == null && service != null) {
        stream = service.getClass().getClassLoader().getResourceAsStream(resource);
    }
    if (stream == null && hasLeadingSlash && service != null) {
        stream = service.getClass().getClassLoader().getResourceAsStream(stripped);
    }
    if (stream == null) {
        // $NON-NLS-1$
        throw new HibernateException(resource + " not found");
    }
    return stream;
}
Also used : HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) InputStream(java.io.InputStream)

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