Example usage for org.hibernate.type EnumType NAMED

List of usage examples for org.hibernate.type EnumType NAMED

Introduction

In this page you can find the example usage for org.hibernate.type EnumType NAMED.

Prototype

String NAMED

To view the source code for org.hibernate.type EnumType NAMED.

Click Source Link

Usage

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

License:Apache License

protected void bindEnumType(PersistentProperty property, Class<?> propertyType, SimpleValue simpleValue,
        String columnName) {/*  w  w w  . j  a  v a  2s .com*/

    PropertyConfig pc = getPropertyConfig(property);
    final PersistentEntity owner = property.getOwner();
    String typeName = getTypeName(property, getPropertyConfig(property), getMapping(owner));
    if (typeName == null) {
        Properties enumProperties = new Properties();
        enumProperties.put(ENUM_CLASS_PROP, propertyType.getName());

        String enumType = pc == null ? DEFAULT_ENUM_TYPE : pc.getEnumType();
        boolean isDefaultEnumType = enumType.equals(DEFAULT_ENUM_TYPE);
        simpleValue.setTypeName(ENUM_TYPE_CLASS);
        if (isDefaultEnumType || "string".equalsIgnoreCase(enumType)) {
            enumProperties.put(EnumType.TYPE, String.valueOf(Types.VARCHAR));
            enumProperties.put(EnumType.NAMED, Boolean.TRUE.toString());
        } else if ("identity".equals(enumType)) {
            simpleValue.setTypeName(HibernateUtils.buildIdentityEnumTypeFactory().getName());
        } else if (!"ordinal".equalsIgnoreCase(enumType)) {
            simpleValue.setTypeName(enumType);
        }
        simpleValue.setTypeParameters(enumProperties);
    } else {
        simpleValue.setTypeName(typeName);
    }

    Table t = simpleValue.getTable();
    Column column = new Column();

    if (owner.isRoot()) {
        column.setNullable(property.isNullable());
    } else {
        Mapping mapping = getMapping(owner);
        if (mapping == null || mapping.getTablePerHierarchy()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName()
                        + "] for column name [" + column.getName() + "] set to nullable");
            }
            column.setNullable(true);
        } else {
            column.setNullable(property.isNullable());
        }
    }
    column.setValue(simpleValue);
    column.setName(columnName);
    if (t != null)
        t.addColumn(column);

    simpleValue.addColumn(column);

    PropertyConfig propertyConfig = getPropertyConfig(property);
    if (propertyConfig != null && !propertyConfig.getColumns().isEmpty()) {
        bindIndex(columnName, column, propertyConfig.getColumns().get(0), t);
        bindColumnConfigToColumn(property, column, propertyConfig.getColumns().get(0));
    }
}