Search in sources :

Example 1 with INamingStrategy

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

the class ConfigurationFactory method configureStandardConfiguration.

private IConfiguration configureStandardConfiguration(final boolean includeMappings, IConfiguration localCfg, Properties properties) {
    if (properties != null) {
        localCfg = localCfg.setProperties(properties);
    }
    EntityResolver entityResolver = new DTDEntityResolver(service);
    if (StringHelper.isNotEmpty(prefs.getEntityResolverName())) {
        try {
            entityResolver = (EntityResolver) ReflectHelper.classForName(prefs.getEntityResolverName()).newInstance();
        } catch (Exception c) {
            throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_configure_entity_resolver + prefs.getEntityResolverName(), c);
        }
    }
    localCfg.setEntityResolver(entityResolver);
    if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
        try {
            INamingStrategy ns = service.newNamingStrategy(prefs.getNamingStrategy());
            localCfg.setNamingStrategy(ns);
        } catch (Exception c) {
            throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_configure_naming_strategy + prefs.getNamingStrategy(), c);
        }
    }
    localCfg = loadConfigurationXML(localCfg, includeMappings, entityResolver);
    changeDatasourceProperties(localCfg);
    localCfg = configureConnectionProfile(localCfg);
    // replace dialect if it is set in preferences
    if (StringHelper.isNotEmpty(prefs.getDialectName())) {
        localCfg.setProperty(environment.getDialect(), prefs.getDialectName());
    }
    if (StringHelper.isEmpty(localCfg.getProperty("javax.persistence.validation.mode"))) {
        // $NON-NLS-1$
        // $NON-NLS-1$//$NON-NLS-2$
        localCfg.setProperty("javax.persistence.validation.mode", "none");
    }
    return localCfg;
}
Also used : INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) EntityResolver(org.xml.sax.EntityResolver) DTDEntityResolver(org.hibernate.util.xpl.DTDEntityResolver) DTDEntityResolver(org.hibernate.util.xpl.DTDEntityResolver) 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 2 with INamingStrategy

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

the class ConfigurationFacadeTest method testSetNamingStrategy.

@Test
public void testSetNamingStrategy() {
    NamingStrategy dns = new DefaultNamingStrategy();
    INamingStrategy namingStrategy = FACADE_FACTORY.createNamingStrategy(dns);
    Assert.assertNotSame(dns, configuration.getNamingStrategy());
    configurationFacade.setNamingStrategy(namingStrategy);
    Assert.assertSame(dns, configuration.getNamingStrategy());
}
Also used : NamingStrategy(org.hibernate.cfg.NamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Example 3 with INamingStrategy

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

the class ConfigurationFacadeTest method testGetNamingStrategy.

@Test
public void testGetNamingStrategy() {
    NamingStrategy firstStrategy = new DefaultNamingStrategy();
    configuration.setNamingStrategy(firstStrategy);
    INamingStrategy firstStrategyFacade = configurationFacade.getNamingStrategy();
    Assert.assertSame(firstStrategy, ((IFacade) firstStrategyFacade).getTarget());
    NamingStrategy secondStrategy = new DefaultNamingStrategy();
    configuration.setNamingStrategy(secondStrategy);
    INamingStrategy secondStrategyFacade = configurationFacade.getNamingStrategy();
    Assert.assertNotSame(secondStrategy, ((IFacade) secondStrategyFacade).getTarget());
}
Also used : NamingStrategy(org.hibernate.cfg.NamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Example 4 with INamingStrategy

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

the class FacadeFactoryTest method testCreateNamingStrategy.

@Test
public void testCreateNamingStrategy() {
    DefaultNamingStrategy namingStrategy = new DefaultNamingStrategy();
    INamingStrategy facade = facadeFactory.createNamingStrategy(namingStrategy);
    Assert.assertSame(namingStrategy, ((IFacade) facade).getTarget());
}
Also used : INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Example 5 with INamingStrategy

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

the class ConfigurationFacadeTest method testSetNamingStrategy.

@Test
public void testSetNamingStrategy() {
    INamingStrategy namingStrategy = FACADE_FACTORY.createNamingStrategy(new DefaultNamingStrategy());
    ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
    Assert.assertNotSame(namingStrategy, facade.namingStrategy);
    configurationFacade.setNamingStrategy(namingStrategy);
    Assert.assertSame(namingStrategy, facade.namingStrategy);
}
Also used : INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Aggregations

INamingStrategy (org.jboss.tools.hibernate.runtime.spi.INamingStrategy)30 DefaultNamingStrategy (org.hibernate.cfg.DefaultNamingStrategy)28 Test (org.junit.Test)28 NamingStrategy (org.hibernate.cfg.NamingStrategy)9 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)4 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 DocumentException (org.dom4j.DocumentException)1 Entity (org.eclipse.jpt.jpa.core.context.Entity)1 RelationshipMapping (org.eclipse.jpt.jpa.core.context.RelationshipMapping)1 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)1 DTDEntityResolver (org.hibernate.util.xpl.DTDEntityResolver)1 MappingException (org.jboss.tools.hibernate.exception.MappingException)1 HibernateException (org.jboss.tools.hibernate.runtime.spi.HibernateException)1 EntityResolver (org.xml.sax.EntityResolver)1 SAXParseException (org.xml.sax.SAXParseException)1