Example usage for org.hibernate.mapping Column setScale

List of usage examples for org.hibernate.mapping Column setScale

Introduction

In this page you can find the example usage for org.hibernate.mapping Column setScale.

Prototype

public void setScale(int scale) 

Source Link

Usage

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

License:Apache License

protected void bindColumnConfigToColumn(PersistentProperty property, Column column, ColumnConfig columnConfig) {
    final PropertyConfig mappedForm = property != null ? (PropertyConfig) property.getMapping().getMappedForm()
            : null;/*  w  ww.j ava 2s.co m*/
    boolean allowUnique = mappedForm != null && !mappedForm.isUniqueWithinGroup();

    if (columnConfig == null) {
        return;
    }

    if (columnConfig.getLength() != -1) {
        column.setLength(columnConfig.getLength());
    }
    if (columnConfig.getPrecision() != -1) {
        column.setPrecision(columnConfig.getPrecision());
    }
    if (columnConfig.getScale() != -1) {
        column.setScale(columnConfig.getScale());
    }
    if (columnConfig.getSqlType() != null && !columnConfig.getSqlType().isEmpty()) {
        column.setSqlType(columnConfig.getSqlType());
    }
    if (allowUnique) {
        column.setUnique(columnConfig.getUnique());
    }
}

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

License:Apache License

protected void bindSimpleValue(PersistentProperty grailsProp, PersistentProperty parentProperty,
        SimpleValue simpleValue, String path, PropertyConfig propertyConfig, String sessionFactoryBeanName) {
    setTypeForPropertyConfig(grailsProp, simpleValue, propertyConfig);
    final PropertyConfig mappedForm = (PropertyConfig) grailsProp.getMapping().getMappedForm();
    if (mappedForm.isDerived() && !(grailsProp instanceof TenantId)) {
        Formula formula = new Formula();
        formula.setFormula(propertyConfig.getFormula());
        simpleValue.addFormula(formula);
    } else {//from w  w  w . j  ava2  s .  c o  m
        Table table = simpleValue.getTable();
        boolean hasConfig = propertyConfig != null;

        String generator = hasConfig ? propertyConfig.getGenerator() : null;
        if (generator != null) {
            simpleValue.setIdentifierGeneratorStrategy(generator);
            Properties params = propertyConfig.getTypeParams();
            if (params != null) {
                Properties generatorProps = new Properties();
                generatorProps.putAll(params);

                if (generatorProps.containsKey(SEQUENCE_KEY)) {
                    generatorProps.put(SequenceStyleGenerator.SEQUENCE_PARAM,
                            generatorProps.getProperty(SEQUENCE_KEY));
                }
                simpleValue.setIdentifierGeneratorProperties(generatorProps);
            }
        }

        // Add the column definitions for this value/property. Note that
        // not all custom mapped properties will have column definitions,
        // in which case we still need to create a Hibernate column for
        // this value.
        List<?> columnDefinitions = hasConfig ? propertyConfig.getColumns()
                : Arrays.asList(new Object[] { null });
        if (columnDefinitions.isEmpty()) {
            columnDefinitions = Arrays.asList(new Object[] { null });
        }

        for (Object columnDefinition : columnDefinitions) {
            ColumnConfig cc = (ColumnConfig) columnDefinition;
            Column column = new Column();

            // Check for explicitly mapped column name and SQL type.
            if (cc != null) {
                if (cc.getName() != null) {
                    column.setName(cc.getName());
                }
                if (cc.getSqlType() != null) {
                    column.setSqlType(cc.getSqlType());
                }
            }

            column.setValue(simpleValue);

            if (cc != null) {
                if (cc.getLength() != -1) {
                    column.setLength(cc.getLength());
                }
                if (cc.getPrecision() != -1) {
                    column.setPrecision(cc.getPrecision());
                }
                if (cc.getScale() != -1) {
                    column.setScale(cc.getScale());
                }
                if (!mappedForm.isUniqueWithinGroup()) {
                    column.setUnique(cc.isUnique());
                }
            }

            bindColumn(grailsProp, parentProperty, column, cc, path, table, sessionFactoryBeanName);

            if (table != null) {
                table.addColumn(column);
            }

            simpleValue.addColumn(column);
        }
    }
}