Example usage for org.hibernate.cfg NamingStrategy classToTableName

List of usage examples for org.hibernate.cfg NamingStrategy classToTableName

Introduction

In this page you can find the example usage for org.hibernate.cfg NamingStrategy classToTableName.

Prototype

public String classToTableName(String className);

Source Link

Document

Return a table name for an entity class

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindCompositeIdentifierToManyToOne(GrailsDomainClassProperty property, SimpleValue value,
        CompositeIdentity compositeId, GrailsDomainClass refDomainClass, String path,
        String sessionFactoryBeanName) {

    NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);

    String[] propertyNames = compositeId.getPropertyNames();
    PropertyConfig config = getPropertyConfig(property);
    if (config == null)
        config = new PropertyConfig();

    if (config.getColumns().size() != propertyNames.length) {
        for (String propertyName : propertyNames) {
            final ColumnConfig cc = new ColumnConfig();
            cc.setName(addUnderscore(namingStrategy.classToTableName(refDomainClass.getShortName()),
                    getDefaultColumnName(refDomainClass.getPropertyByName(propertyName),
                            sessionFactoryBeanName)));
            config.getColumns().add(cc);
        }/*from   w  ww  .  j  ava  2  s.c  om*/
    }
    bindSimpleValue(property, value, path, config, sessionFactoryBeanName);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected String getDefaultColumnName(GrailsDomainClassProperty property, String sessionFactoryBeanName) {

    NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);

    String columnName = namingStrategy.propertyToColumnName(property.getName());
    if (property.isAssociation() && property.getReferencedDomainClass() != null) {

        if (property.isManyToMany()) {
            return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName);
        }//from  w w  w  . ja va2  s . co  m

        if (!property.isBidirectional() && property.isOneToMany()) {
            String prefix = namingStrategy.classToTableName(property.getDomainClass().getName());
            return addUnderscore(prefix, columnName) + FOREIGN_KEY_SUFFIX;
        }

        if (property.isInherited() && isBidirectionalManyToOne(property)) {
            return namingStrategy.propertyToColumnName(property.getDomainClass().getName()) + '_' + columnName
                    + FOREIGN_KEY_SUFFIX;
        }

        return columnName + FOREIGN_KEY_SUFFIX;
    }

    if (property.isBasicCollectionType()) {
        return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName);
    }

    return columnName;
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

private static void bindCompositeIdentifierToManyToOne(GrailsDomainClassProperty property, SimpleValue value,
        CompositeIdentity compositeId, GrailsDomainClass refDomainClass, String path,
        String sessionFactoryBeanName) {

    NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);

    String[] propertyNames = compositeId.getPropertyNames();
    PropertyConfig config = getPropertyConfig(property);
    if (config == null)
        config = new PropertyConfig();

    if (config.getColumns().size() != propertyNames.length) {
        for (String propertyName : propertyNames) {
            final ColumnConfig cc = new ColumnConfig();
            cc.setName(addUnderscore(namingStrategy.classToTableName(refDomainClass.getShortName()),
                    getDefaultColumnName(refDomainClass.getPropertyByName(propertyName),
                            sessionFactoryBeanName)));
            config.getColumns().add(cc);
        }/*from   w  ww.j ava 2 s  .c o  m*/
    }
    bindSimpleValue(property, value, path, config, sessionFactoryBeanName);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

private static String getDefaultColumnName(GrailsDomainClassProperty property, String sessionFactoryBeanName) {

    NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);

    String columnName = namingStrategy.propertyToColumnName(property.getName());
    if (property.isAssociation() && property.getReferencedDomainClass() != null) {

        if (property.isManyToMany()) {
            return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName);
        }/* w w  w . j  av a  2 s .c  om*/

        if (!property.isBidirectional() && property.isOneToMany()) {
            String prefix = namingStrategy.classToTableName(property.getDomainClass().getName());
            return addUnderscore(prefix, columnName) + FOREIGN_KEY_SUFFIX;
        }

        if (property.isInherited() && isBidirectionalManyToOne(property)) {
            return namingStrategy.propertyToColumnName(property.getDomainClass().getName()) + '_' + columnName
                    + FOREIGN_KEY_SUFFIX;
        }

        return columnName + FOREIGN_KEY_SUFFIX;
    }

    if (property.isBasicCollectionType()) {
        return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName);
    }

    return columnName;
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindCompositeIdentifierToManyToOne(Association property, SimpleValue value,
        CompositeIdentity compositeId, PersistentEntity refDomainClass, String path,
        String sessionFactoryBeanName) {

    NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);

    String[] propertyNames = compositeId.getPropertyNames();
    PropertyConfig config = getPropertyConfig(property);

    if (config.getColumns().size() != propertyNames.length) {
        for (String propertyName : propertyNames) {
            final ColumnConfig cc = new ColumnConfig();
            cc.setName(addUnderscore(/* w w w.jav a 2 s.  c o  m*/
                    namingStrategy.classToTableName(refDomainClass.getJavaClass().getSimpleName()),
                    getDefaultColumnName(refDomainClass.getPropertyByName(propertyName),
                            sessionFactoryBeanName)));
            config.getColumns().add(cc);
        }
    }
    bindSimpleValue(property, value, path, config, sessionFactoryBeanName);
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected String getDefaultColumnName(PersistentProperty property, String sessionFactoryBeanName) {

    NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);

    String columnName = namingStrategy.propertyToColumnName(property.getName());
    if (property instanceof Association) {
        Association association = (Association) property;
        boolean isBasic = property instanceof Basic;
        if (isBasic && ((PropertyConfig) property.getMapping().getMappedForm()).getType() != null) {
            return columnName;
        }/*  w ww. j a  va2  s. c  o  m*/

        if (isBasic) {
            return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName);
        }

        if (property instanceof ManyToMany) {
            return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName);
        }

        if (!association.isBidirectional()
                && association instanceof org.grails.datastore.mapping.model.types.OneToMany) {
            String prefix = namingStrategy.classToTableName(property.getOwner().getName());
            return addUnderscore(prefix, columnName) + FOREIGN_KEY_SUFFIX;
        }

        if (property.isInherited() && isBidirectionalManyToOne(property)) {
            return namingStrategy.propertyToColumnName(property.getOwner().getName()) + '_' + columnName
                    + FOREIGN_KEY_SUFFIX;
        }

        return columnName + FOREIGN_KEY_SUFFIX;
    }

    return columnName;
}

From source file:org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaTableImpl.java

License:Open Source License

protected String buildDefaultDBTableName() {
    if (getDefaultName() == null)
        return null;
    NamingStrategy ns = getJpaProject().getNamingStrategy();
    if (getJpaProject().isNamingStrategyEnabled() && ns != null) {
        try {/*from   w  w  w . ja v a2 s . c o  m*/
            return ns.classToTableName(getDefaultName());
        } catch (Exception e) {
            IMessage m = HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY,
                    Messages.NAMING_STRATEGY_EXCEPTION, this);
            HibernateJptPlugin.logException(m.getText(), e);
        }
    }
    return this.getDefaultName();
}

From source file:org.jboss.tools.hibernate.jpt.core.internal.context.orm.HibernateOrmTableImpl.java

License:Open Source License

protected String buildDefaultDBTableName() {
    if (getDefaultName() != null) {
        NamingStrategy ns = getJpaProject().getNamingStrategy();
        if (getJpaProject().isNamingStrategyEnabled() && ns != null) {
            try {
                return ns.classToTableName(getDefaultName());
            } catch (Exception e) {
                IMessage m = HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY,
                        Messages.NAMING_STRATEGY_EXCEPTION, this);
                HibernateJptPlugin.logException(m.getText(), e);
            }//from w  w  w .j  a  va 2 s . c o  m
        }
    }
    return this.getDefaultName();
}