Search in sources :

Example 1 with IConfiguration

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

the class ConsoleExtension method buildConfiguration.

private IConfiguration buildConfiguration(final ExporterAttributes attributes, ConsoleConfiguration cc, IWorkspaceRoot root) {
    final boolean reveng = attributes.isReverseEngineer();
    final String reverseEngineeringStrategy = attributes.getRevengStrategy();
    final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
    final IResource revengres = PathHelper.findMember(root, attributes.getRevengSettings());
    if (reveng) {
        IConfiguration configuration = null;
        if (cc.hasConfiguration()) {
            configuration = cc.getConfiguration();
        } else {
            configuration = cc.buildWith(null, false);
        }
        final IConfiguration cfg = hibernateExtension.getHibernateService().newJDBCMetaDataConfiguration();
        // final JDBCMetaDataConfiguration cfg = new
        // JDBCMetaDataConfiguration();
        Properties properties = configuration.getProperties();
        cfg.setProperties(properties);
        cc.buildWith(cfg, false);
        cfg.setPreferBasicCompositeIds(preferBasicCompositeids);
        cc.execute(new // need to execute in the
        Command() {

            // consoleconfiguration to let it handle
            // classpath stuff!
            public Object execute() {
                // todo: factor this setup of revengstrategy to core
                IService service = hibernateExtension.getHibernateService();
                IReverseEngineeringStrategy res = service.newDefaultReverseEngineeringStrategy();
                IOverrideRepository repository = null;
                if (revengres != null) {
                    File file = PathHelper.getLocation(revengres).toFile();
                    repository = service.newOverrideRepository();
                    repository.addFile(file);
                }
                if (repository != null) {
                    res = repository.getReverseEngineeringStrategy(res);
                }
                if (reverseEngineeringStrategy != null && reverseEngineeringStrategy.trim().length() > 0) {
                    res = service.newReverseEngineeringStrategy(reverseEngineeringStrategy, res);
                }
                IReverseEngineeringSettings qqsettings = service.newReverseEngineeringSettings(res).setDefaultPackageName(attributes.getPackageName()).setDetectManyToMany(attributes.detectManyToMany()).setDetectOneToOne(attributes.detectOneToOne()).setDetectOptimisticLock(attributes.detectOptimisticLock());
                res.setSettings(qqsettings);
                cfg.setReverseEngineeringStrategy(res);
                cfg.readFromJDBC();
                cfg.buildMappings();
                return null;
            }
        });
        return cfg;
    } else {
        cc.build();
        cc.buildMappings();
        return cc.getConfiguration();
    }
}
Also used : IReverseEngineeringSettings(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringSettings) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 2 with IConfiguration

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

the class ConsoleExtension 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;
    return (IArtifactCollector) cc.execute(new Command() {

        public Object execute() {
            IArtifactCollector artifactCollector = hibernateExtension.getHibernateService().newArtifactCollector();
            // Global properties
            Properties props = new Properties();
            props.put(CodeGenerationStrings.EJB3, // $NON-NLS-1$
            "" + attributes.isEJB3Enabled());
            props.put(CodeGenerationStrings.JDK5, // $NON-NLS-1$
            "" + 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, hibernateExtension.getHibernateService());
                } 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)

Example 3 with IConfiguration

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

the class HibernateExtension method buildWith.

public IConfiguration buildWith(final IConfiguration cfg, final boolean includeMappings) {
    reinitClassLoader();
    // TODO handle user libraries here
    executionContext = new DefaultExecutionContext(prefs.getName(), classLoader);
    IConfiguration result = (IConfiguration) execute(new Command() {

        public Object execute() {
            ConfigurationFactory cf = new ConfigurationFactory(prefs, fakeDrivers);
            return cf.createConfiguration(cfg, includeMappings);
        }
    });
    return result;
}
Also used : DefaultExecutionContext(org.hibernate.console.execution.DefaultExecutionContext) Command(org.hibernate.console.execution.ExecutionContext.Command) ConfigurationFactory(org.hibernate.console.ConfigurationFactory) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 4 with IConfiguration

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

the class ConfigurationFactory method buildConfiguration.

// TODO: delegate to some extension point
private IConfiguration buildConfiguration(Properties properties, boolean includeMappings) {
    IConfiguration localCfg = null;
    if (prefs.getConfigurationMode().equals(ConfigurationMode.ANNOTATIONS)) {
        try {
            localCfg = buildAnnotationConfiguration();
            localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
        } catch (HibernateConsoleRuntimeException he) {
            throw he;
        } catch (Exception e) {
            throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_load_annotationconfiguration, e);
        }
    } else if (prefs.getConfigurationMode().equals(ConfigurationMode.JPA)) {
        try {
            localCfg = buildJPAConfiguration(getPreferences().getPersistenceUnitName(), properties, prefs.getEntityResolverName(), includeMappings);
        } catch (HibernateConsoleRuntimeException he) {
            throw he;
        } catch (Exception e) {
            throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_load_jpa_configuration, e);
        }
    } else {
        localCfg = service.newDefaultConfiguration();
        localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
    }
    return localCfg;
}
Also used : IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) SQLException(java.sql.SQLException) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXParseException(org.xml.sax.SAXParseException) MappingException(org.jboss.tools.hibernate.exception.MappingException) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException)

Example 5 with IConfiguration

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

the class ColumnFacadeImpl method getSqlType.

@Override
public String getSqlType(IConfiguration configuration) {
    Column targetColumn = (Column) getTarget();
    Configuration configurationTarget = (Configuration) ((IFacade) configuration).getTarget();
    Properties properties = configurationTarget.getProperties();
    ServiceRegistryBuilder ssrb = new ServiceRegistryBuilder();
    ssrb.applySettings(properties);
    ServiceRegistry ssr = ssrb.buildServiceRegistry();
    DialectFactory df = ssr.getService(DialectFactory.class);
    Dialect dialectTarget = df.buildDialect(properties, null);
    return targetColumn.getSqlType(dialectTarget, configurationTarget.buildMapping());
}
Also used : IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Configuration(org.hibernate.cfg.Configuration) Column(org.hibernate.mapping.Column) Dialect(org.hibernate.dialect.Dialect) DialectFactory(org.hibernate.service.jdbc.dialect.spi.DialectFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) Properties(java.util.Properties) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder)

Aggregations

IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)137 Test (org.junit.Test)72 Configuration (org.hibernate.cfg.Configuration)65 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)29 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)25 File (java.io.File)19 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)17 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)16 Properties (java.util.Properties)13 CoreException (org.eclipse.core.runtime.CoreException)10 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)10 IJDBCReader (org.jboss.tools.hibernate.runtime.spi.IJDBCReader)9 FileWriter (java.io.FileWriter)8 IOException (java.io.IOException)8 JDBCReader (org.hibernate.cfg.reveng.JDBCReader)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)7 PartInitException (org.eclipse.ui.PartInitException)7 Ejb3Configuration (org.hibernate.ejb.Ejb3Configuration)7