Search in sources :

Example 21 with HibernateException

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

the class ServiceImpl method newDialect.

@Override
public String newDialect(Properties properties, final Connection connection) {
    ServiceRegistry serviceRegistry = buildServiceRegistry(properties);
    DialectFactory dialectFactory = serviceRegistry.getService(DialectFactory.class);
    Dialect dialect = dialectFactory.buildDialect(properties, new DialectResolutionInfoSource() {

        @Override
        public DialectResolutionInfo getDialectResolutionInfo() {
            try {
                return new DatabaseMetaDataDialectResolutionInfoAdapter(connection.getMetaData());
            } catch (SQLException sqlException) {
                throw new HibernateException("Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect to use", sqlException);
            }
        }
    });
    return dialect != null ? dialect.toString() : null;
}
Also used : DialectResolutionInfoSource(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource) SQLException(java.sql.SQLException) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) MetaDataDialect(org.hibernate.cfg.reveng.dialect.MetaDataDialect) Dialect(org.hibernate.dialect.Dialect) DatabaseMetaDataDialectResolutionInfoAdapter(org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter) DialectFactory(org.hibernate.engine.jdbc.dialect.spi.DialectFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) DialectResolutionInfo(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)

Example 22 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 {
            ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
            Class<?> clazz = null;
            if (contextClassLoader != null) {
                clazz = contextClassLoader.loadClass(className);
            } else {
                clazz = Class.forName(className);
            }
            if (clazz != null) {
                return clazz.newInstance();
            } else {
                throw new HibernateException("Class " + className + " could not be found.");
            }
        } 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 23 with HibernateException

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

the class ServiceImpl method newDialect.

@Override
public String newDialect(Properties properties, final Connection connection) {
    ServiceRegistry serviceRegistry = buildServiceRegistry(properties);
    DialectFactory dialectFactory = serviceRegistry.getService(DialectFactory.class);
    Dialect dialect = dialectFactory.buildDialect(transform(properties), new DialectResolutionInfoSource() {

        @Override
        public DialectResolutionInfo getDialectResolutionInfo() {
            try {
                return new DatabaseMetaDataDialectResolutionInfoAdapter(connection.getMetaData());
            } catch (SQLException sqlException) {
                throw new HibernateException("Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect to use", sqlException);
            }
        }
    });
    return dialect != null ? dialect.toString() : null;
}
Also used : DialectResolutionInfoSource(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource) SQLException(java.sql.SQLException) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) RevengDialect(org.hibernate.tool.api.reveng.RevengDialect) Dialect(org.hibernate.dialect.Dialect) DatabaseMetaDataDialectResolutionInfoAdapter(org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter) RevengDialectFactory(org.hibernate.tool.api.reveng.RevengDialectFactory) DialectFactory(org.hibernate.engine.jdbc.dialect.spi.DialectFactory) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) DialectResolutionInfo(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)

Example 24 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 = classForName(className);
        Constructor<?> constructor = clazz.getConstructor(new Class[] { RevengStrategy.class });
        return constructor.newInstance(new Object[] { delegate });
    } catch (NoSuchMethodException e) {
        try {
            ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
            Class<?> clazz = null;
            if (contextClassLoader != null) {
                clazz = contextClassLoader.loadClass(className);
            } else {
                clazz = Class.forName(className);
            }
            if (clazz != null) {
                return clazz.newInstance();
            } else {
                throw new HibernateException("Class " + className + " could not be found.");
            }
        } 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 25 with HibernateException

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

the class ServiceImpl method newDialect.

@Override
public String newDialect(Properties properties, final Connection connection) {
    ServiceRegistry serviceRegistry = buildServiceRegistry(properties);
    DialectFactory dialectFactory = serviceRegistry.getService(DialectFactory.class);
    Dialect dialect = dialectFactory.buildDialect(properties, new DialectResolutionInfoSource() {

        @Override
        public DialectResolutionInfo getDialectResolutionInfo() {
            try {
                return new DatabaseMetaDataDialectResolutionInfoAdapter(connection.getMetaData());
            } catch (SQLException sqlException) {
                throw new HibernateException("Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect to use", sqlException);
            }
        }
    });
    return dialect != null ? dialect.toString() : null;
}
Also used : DialectResolutionInfoSource(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource) SQLException(java.sql.SQLException) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) MetaDataDialect(org.hibernate.cfg.reveng.dialect.MetaDataDialect) Dialect(org.hibernate.dialect.Dialect) DatabaseMetaDataDialectResolutionInfoAdapter(org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter) DialectFactory(org.hibernate.engine.jdbc.dialect.spi.DialectFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) DialectResolutionInfo(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)

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