Search in sources :

Example 26 with HibernateConsoleRuntimeException

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

the class ConsoleExtension method launchExporters.

public Map<String, File[]> launchExporters(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(configuration);
    Assert.isNotNull(monitor);
    ExporterAttributes attributes = new ExporterAttributes(configuration);
    List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
    for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext(); ) {
        ExporterFactory exFactory = iter.next();
        if (!exFactory.isEnabled(configuration)) {
            iter.remove();
        }
    }
    try {
        Set<String> outputDirectories = new HashSet<String>();
        ExporterFactory[] exporters = exporterFactories.toArray(new ExporterFactory[exporterFactories.size()]);
        IArtifactCollector collector = runExporters(attributes, exporters, outputDirectories, monitor);
        for (String path : outputDirectories) {
            CodeGenerationUtils.refreshOutputDir(path);
        }
        // eclipse will format the uptodate files!
        if (collector != null) {
            Map<String, File[]> map = new HashMap<String, File[]>();
            Set<String> types = collector.getFileTypes();
            for (String type : types) {
                File[] files = collector.getFiles(type.toString());
                map.put(type, files);
            }
            return map;
        }
    } catch (Exception e) {
        throw new CoreException(HibernatePlugin.throwableToStatus(e, 666));
    } catch (NoClassDefFoundError e) {
        throw new CoreException(HibernatePlugin.throwableToStatus(new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror, e), 666));
    } finally {
        monitor.done();
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ExporterAttributes(org.hibernate.eclipse.launch.ExporterAttributes) CoreException(org.eclipse.core.runtime.CoreException) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) File(java.io.File) HashSet(java.util.HashSet)

Example 27 with HibernateConsoleRuntimeException

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

the class ExporterAttributes method readExporterFactories.

private List<ExporterFactory> readExporterFactories(ILaunchConfiguration configuration) throws CoreException {
    List<String> exporterNames = configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, (List<String>) null);
    if (exporterNames != null) {
        Map<String, ExporterDefinition> exDefinitions = ExtensionManager.findExporterDefinitionsAsMap();
        List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
        for (String exporterId : exporterNames) {
            // $NON-NLS-1$
            String extensionId = configuration.getAttribute(getLaunchAttributePrefix(exporterId) + ".extension_id", (String) null);
            ExporterDefinition expDef = exDefinitions.get(extensionId);
            if (expDef == null) {
                String out = NLS.bind(HibernateConsoleMessages.ExporterAttributes_could_not_locate_exporter_for_in, extensionId, configuration.getName());
                throw new HibernateConsoleRuntimeException(out);
            } else {
                ExporterFactory exporterFactory = new ExporterFactory(expDef, exporterId);
                exporterFactory.isEnabled(configuration);
                factories.add(exporterFactory);
                Map<String, String> props = configuration.getAttribute(getLaunchAttributePrefix(exporterFactory.getId()) + ".properties", // $NON-NLS-1$
                new HashMap<String, String>());
                exporterFactory.setProperties(props);
            }
        }
        return factories;
    } else {
        // fall back to old way of reading if list of exporters does not exist.
        ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
        List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
        for (int i = 0; i < exDefinitions.length; i++) {
            ExporterDefinition expDef = exDefinitions[i];
            ExporterFactory exporterFactory = new ExporterFactory(expDef, expDef.getId());
            exporterFactory.isEnabled(configuration);
            factories.add(exporterFactory);
            Map<String, String> props = configuration.getAttribute(getLaunchAttributePrefix(exporterFactory.getId()) + ".properties", // $NON-NLS-1$
            new HashMap<String, String>());
            exporterFactory.setProperties(props);
        }
        return factories;
    }
}
Also used : ExporterDefinition(org.hibernate.eclipse.console.model.impl.ExporterDefinition) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) ArrayList(java.util.ArrayList) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Example 28 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException 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 HibernateConsoleRuntimeException(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) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) Ejb3Configuration(org.hibernate.ejb.Ejb3Configuration)

Example 29 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException 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 HibernateConsoleRuntimeException(eq);
        }
    } catch (Exception e) {
        throw new HibernateConsoleRuntimeException(e);
    }
}
Also used : 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) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Example 30 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException 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 HibernateConsoleRuntimeException(eq);
        }
    } catch (Exception e) {
        throw new HibernateConsoleRuntimeException(e);
    }
}
Also used : 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) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) 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