Search in sources :

Example 11 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)

Example 12 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() {
    INamingStrategy strategy = FACADE_FACTORY.createNamingStrategy(new DefaultNamingStrategy());
    ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
    Assert.assertNull(facade.getNamingStrategy());
    facade.namingStrategy = strategy;
    Assert.assertSame(strategy, facade.getNamingStrategy());
}
Also used : INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Example 13 with INamingStrategy

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

the class NamingStrategyMappingTools method buildJoinTableDefaultName.

public static String buildJoinTableDefaultName(Relationship relationshipReference) {
    if (relationshipReference.getJpaProject().getDataSource().connectionProfileIsActive()) {
        return buildDbJoinTableDefaultName(relationshipReference);
    }
    RelationshipMapping relationshipMapping = relationshipReference.getMapping();
    if (relationshipMapping == null) {
        return null;
    }
    if (!(relationshipReference.getTypeMapping() instanceof Entity))
        // could be JavaNullTypeMapping
        return null;
    Entity ownerEntity = (Entity) relationshipReference.getTypeMapping();
    org.eclipse.jpt.jpa.core.context.Table ownerTable = ownerEntity.getTable();
    if (ownerTable == null) {
        return null;
    }
    Entity targetEntity = relationshipMapping.getResolvedTargetEntity();
    if (targetEntity == null) {
        return null;
    }
    org.eclipse.jpt.jpa.core.context.Table targetTable = targetEntity.getTable();
    if (targetTable == null) {
        return null;
    }
    INamingStrategy ns = getJpaProject(relationshipReference).getNamingStrategy();
    if (getJpaProject(relationshipReference).isNamingStrategyEnabled() && ns != null) {
        /*
			 * By testing generated DDL I have found for JPA console configuration:
			 * 1) first parameter of the method is always fully qualified owner entity class name
			 * 2) second and forth parameters of the method are always fully qualified target entity class name
			 * 3) third parameter of the method is name attribute of @Table annotation,
			 * 		if it is not specified, then it is *unqualified* name attribute of @Entity annotation
			 * 		if @Entity annotation not specified it is *unqualified* name of the target entity class.
			 * 4) fifth parameter is owner entity field name (even if @Column annotation set different name)
			 * 
			 */
        try {
            String targetEntityName = targetEntity.getPersistentType().getName();
            String ownerEntityName = ownerEntity.getPersistentType().getName();
            String propName = relationshipMapping.getPersistentAttribute().getName();
            return ns.collectionTableName(ownerEntityName, targetTable.getName(), targetEntityName, targetTable.getName(), propName);
        } catch (Exception e) {
            IMessage m = HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY, Messages.NAMING_STRATEGY_EXCEPTION, relationshipReference);
            HibernateJptPlugin.logException(m.getText(), e);
        }
    }
    return ownerTable.getName() + '_' + targetTable.getName();
}
Also used : Entity(org.eclipse.jpt.jpa.core.context.Entity) RelationshipMapping(org.eclipse.jpt.jpa.core.context.RelationshipMapping) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy)

Example 14 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 15 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() {
    NamingStrategy namingStrategy = new DefaultNamingStrategy();
    INamingStrategy facade = facadeFactory.createNamingStrategy(namingStrategy);
    Assert.assertSame(namingStrategy, ((IFacade) facade).getTarget());
}
Also used : DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) NamingStrategy(org.hibernate.cfg.NamingStrategy) 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)

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