Search in sources :

Example 81 with IConfiguration

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

the class ConfigurationFactory method buildJPAConfiguration.

private IConfiguration buildJPAConfiguration(String persistenceUnit, Properties properties, String entityResolver, boolean includeMappings) {
    if (StringHelper.isEmpty(persistenceUnit)) {
        persistenceUnit = null;
    }
    try {
        Map<Object, Object> overrides = new HashMap<Object, Object>();
        if (properties != null) {
            overrides.putAll(properties);
        }
        if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
            // $NON-NLS-1$
            overrides.put("hibernate.ejb.naming_strategy", prefs.getNamingStrategy());
        }
        if (StringHelper.isNotEmpty(prefs.getDialectName())) {
            overrides.put(environment.getDialect(), prefs.getDialectName());
        }
        if (!includeMappings) {
            // $NON-NLS-1$//$NON-NLS-2$
            overrides.put("hibernate.archive.autodetection", "none");
        }
        if (StringHelper.isEmpty((String) overrides.get("javax.persistence.validation.mode"))) {
            // $NON-NLS-1$
            // $NON-NLS-1$//$NON-NLS-2$
            overrides.put("javax.persistence.validation.mode", "none");
        }
        IConfiguration invoke = service.newJpaConfiguration(entityResolver, persistenceUnit, overrides);
        changeDatasourceProperties(invoke);
        invoke = configureConnectionProfile(invoke);
        return invoke;
    // Class hibernatePersistanceProviderClass = ReflectHelper.classForName("org.hibernate.jpa.HibernatePersistenceProvider", ConsoleConfiguration.class);
    // Object hibernatePersistanceProvider = hibernatePersistanceProviderClass.newInstance();
    // 
    // Method getEntityManagerFactoryBuilderOrNull = hibernatePersistanceProviderClass.getDeclaredMethod(
    // "getEntityManagerFactoryBuilderOrNull",
    // new Class[] { String.class, Map.class });
    // getEntityManagerFactoryBuilderOrNull.setAccessible(true);
    // Object entityManagerFactoryBuilder =
    // getEntityManagerFactoryBuilderOrNull.invoke(
    // hibernatePersistanceProvider,
    // new Object[] { persistenceUnit, overrides});
    // 
    // if (entityManagerFactoryBuilder == null) {
    // throw new HibernateConsoleRuntimeException(
    // "Persistence unit not found: '" +
    // persistenceUnit +
    // "'.");
    // }
    // 
    // Method build =
    // entityManagerFactoryBuilder.getClass().getMethod(
    // "build", new Class[0]);
    // build.invoke(entityManagerFactoryBuilder, null);
    // 
    // Method getHibernateConfiguration =
    // entityManagerFactoryBuilder.getClass().getMethod(
    // "getHibernateConfiguration", new Class[0]);
    // return (Configuration)getHibernateConfiguration.invoke(
    // entityManagerFactoryBuilder, null);
    } catch (HibernateConsoleRuntimeException he) {
        throw he;
    } catch (Exception e) {
        throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_create_jpa_based_configuration, e);
    }
}
Also used : HashMap(java.util.HashMap) 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 82 with IConfiguration

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

the class HibernateJpaProject method getDefaultSchema.

/*
	 * The sequence is(from biggest priority to lowest):
	 * 1) Configuration.getProperty() (if cc.hasConfiguration())
	 * 2) ConsoleConfiguration.getPreference().getProperty()-uses hibernate.properties
	 * 3) JpaProject user overrides
	 * 4) persistence.xml
	 * 5) logic from superclass
	 */
@Override
public String getDefaultSchema() {
    String schema = null;
    ConsoleConfiguration cc = getDefaultConsoleConfiguration();
    if (cc != null) {
        if (cc.hasConfiguration()) {
            // was not build yet
            IConfiguration configuration = cc.getConfiguration();
            if (configuration.getProperties().containsKey(getEnvironment().getDefaultSchema())) {
                schema = configuration.getProperty(getEnvironment().getDefaultSchema());
            }
        }
        Properties properties = cc.getPreferences().getProperties();
        if (properties != null && properties.containsKey(getEnvironment().getDefaultSchema())) {
            schema = properties.getProperty(getEnvironment().getDefaultSchema());
        }
    }
    if (schema == null) {
        BasicHibernateProperties prop = getBasicHibernateProperties();
        if (getUserOverrideDefaultSchema() != null) {
            schema = getUserOverrideDefaultSchema();
        } else if (prop != null && prop.getSchemaDefault() != null) {
            schema = prop.getSchemaDefault();
        }
    }
    return schema != null ? schema : super.getDefaultSchema();
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties)

Example 83 with IConfiguration

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

the class HibernateJpaProject method getDefaultCatalog.

/*
	 * The sequence is(from biggest priority to lowest):
	 * 1) Configuration.getProperty() (if cc.hasConfiguration())
	 * 2) ConsoleConfiguration.getPreference().getProperty()-uses hibernate.properties
	 * 3) JpaProject user overrides
	 * 4) persistence.xml
	 * 5) logic from superclass
	 */
@Override
public String getDefaultCatalog() {
    String catalog = null;
    BasicHibernateProperties prop = getBasicHibernateProperties();
    ConsoleConfiguration cc = getDefaultConsoleConfiguration();
    if (cc != null) {
        if (cc.hasConfiguration()) {
            // was not build yet
            IConfiguration configuration = cc.getConfiguration();
            if (configuration.getProperties().containsKey(getEnvironment().getDefaultCatalog())) {
                catalog = configuration.getProperty(getEnvironment().getDefaultCatalog());
            }
        }
        Properties properties = cc.getPreferences().getProperties();
        if (properties != null && properties.containsKey(getEnvironment().getDefaultCatalog())) {
            catalog = properties.getProperty(getEnvironment().getDefaultCatalog());
        }
    }
    if (catalog == null) {
        if (getUserOverrideDefaultCatalog() != null) {
            catalog = getUserOverrideDefaultCatalog();
        } else if (prop != null && prop.getCatalogDefault() != null) {
            catalog = prop.getCatalogDefault();
        }
    }
    return catalog != null ? catalog : super.getDefaultCatalog();
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties)

Example 84 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration 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 85 with IConfiguration

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

the class ServiceImpl method newDefaultConfiguration.

@Override
public IConfiguration newDefaultConfiguration() {
    getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
    Configuration target = new Configuration();
    target.setProperty("hibernate.validator.autoregister_listeners", "false");
    target.setProperty("hibernate.validator.apply_to_ddl", "false");
    return facadeFactory.createConfiguration(target);
}
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)

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