Search in sources :

Example 6 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 7 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 8 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 9 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);
    MetadataImplementor metadataImplementor = (MetadataImplementor) MetadataHelper.getMetadata(configuration);
    SchemaExport schemaExport = new SchemaExport(metadataImplementor);
    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) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.jupiter.api.Test)

Example 10 with HibernateException

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

the class CodeGenerationLaunchDelegate method runExporters.

private IArtifactCollector runExporters(final ExporterAttributes attributes, final ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for + attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
    if (monitor.isCanceled())
        return null;
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
    if (attributes.isReverseEngineer()) {
        monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
    }
    final IConfiguration cfg = buildConfiguration(attributes, cc, ResourcesPlugin.getWorkspace().getRoot());
    monitor.worked(1);
    if (monitor.isCanceled())
        return null;
    final IService service = cc.getHibernateExtension().getHibernateService();
    return (IArtifactCollector) cc.execute(new Command() {

        public Object execute() {
            IArtifactCollector artifactCollector = service.newArtifactCollector();
            // Global properties
            Properties props = new Properties();
            // $NON-NLS-1$
            props.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled());
            // $NON-NLS-1$
            props.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled());
            for (int i = 0; i < exporterFactories.length; i++) {
                monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
                Properties globalProperties = new Properties();
                globalProperties.putAll(props);
                IExporter exporter;
                try {
                    exporter = exporterFactories[i].createConfiguredExporter(cfg, attributes.getOutputPath(), attributes.getTemplatePath(), globalProperties, outputDirectories, artifactCollector, service);
                } catch (CoreException e) {
                    throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up + exporterFactories[i].getExporterDefinition(), e);
                }
                try {
                    exporter.start();
                } catch (HibernateException he) {
                    throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running + exporterFactories[i].getExporterDefinition().getDescription(), he);
                }
                monitor.worked(1);
            }
            return artifactCollector;
        }
    });
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) Command(org.hibernate.console.execution.ExecutionContext.Command) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IExporter(org.jboss.tools.hibernate.runtime.spi.IExporter) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties) IService(org.jboss.tools.hibernate.runtime.spi.IService)

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