List of usage examples for org.hibernate.mapping Column setScale
public void setScale(int scale)
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected Column createColumn(Mappings mappings, Table tab, com.manydesigns.portofino.model.database.Column column) { Column col = new Column(); col.setName(escapeName(column.getColumnName())); col.setLength(column.getLength());//from w ww . java 2s . c o m col.setPrecision(column.getLength()); col.setScale(column.getScale()); col.setNullable(column.isNullable()); String columnType = column.getColumnType(); int jdbcType = column.getJdbcType(); col.setSqlTypeCode(jdbcType); col.setSqlType(columnType); SimpleValue value = new SimpleValue(mappings, tab); if (!setHibernateType(value, column, column.getActualJavaType(), jdbcType)) { logger.error("Skipping column {}", column.getQualifiedName()); return null; } value.addColumn(col); tab.addColumn(col); mappings.addColumnBinding(column.getColumnName(), col, tab); return col; }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindColumnConfigToColumn(Column column, ColumnConfig columnConfig) { if (columnConfig == null) { return;/*from w ww. j a v a 2s . c om*/ } 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()); } column.setUnique(columnConfig.getUnique()); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindSimpleValue(GrailsDomainClassProperty grailsProp, GrailsDomainClassProperty parentProperty, SimpleValue simpleValue, String path, PropertyConfig propertyConfig, String sessionFactoryBeanName) { setTypeForPropertyConfig(grailsProp, simpleValue, propertyConfig); if (grailsProp.isDerived()) { Formula formula = new Formula(); formula.setFormula(propertyConfig.getFormula()); simpleValue.addFormula(formula); } else {/*from ww w . j av a 2 s . c o m*/ Table table = simpleValue.getTable(); // 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 = propertyConfig != null ? propertyConfig.getColumns() : Arrays.asList(new Object[] { null }); if (columnDefinitions.isEmpty()) { columnDefinitions = Arrays.asList(new Object[] { null }); } for (int i = 0, n = columnDefinitions.size(); i < n; i++) { ColumnConfig cc = (ColumnConfig) columnDefinitions.get(i); 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()); } column.setUnique(cc.isUnique()); } bindColumn(grailsProp, parentProperty, column, cc, path, table, sessionFactoryBeanName); if (table != null) { table.addColumn(column); } simpleValue.addColumn(column); } } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Interrogates the specified constraints looking for any constraints that would limit the * precision and/or scale of the property's value. If such constraints exist, this method adjusts * the precision and/or scale of the column accordingly. * * @param column the column that corresponds to the property * @param constrainedProperty the property's constraints * @param cc the column configuration/* w ww . ja v a 2 s .c o m*/ */ protected void bindNumericColumnConstraints(Column column, ConstrainedProperty constrainedProperty, ColumnConfig cc) { int scale = Column.DEFAULT_SCALE; int precision = Column.DEFAULT_PRECISION; if (cc != null && cc.getScale() > -1) { column.setScale(cc.getScale()); } else if (constrainedProperty.getScale() != null) { scale = constrainedProperty.getScale().intValue(); column.setScale(scale); } if (cc != null && cc.getPrecision() > -1) { column.setPrecision(cc.getPrecision()); } else { Comparable<?> minConstraintValue = constrainedProperty.getMin(); Comparable<?> maxConstraintValue = constrainedProperty.getMax(); int minConstraintValueLength = 0; if ((minConstraintValue != null) && (minConstraintValue instanceof Number)) { minConstraintValueLength = Math.max(countDigits((Number) minConstraintValue), countDigits(((Number) minConstraintValue).longValue()) + scale); } int maxConstraintValueLength = 0; if ((maxConstraintValue != null) && (maxConstraintValue instanceof Number)) { maxConstraintValueLength = Math.max(countDigits((Number) maxConstraintValue), countDigits(((Number) maxConstraintValue).longValue()) + scale); } if (minConstraintValueLength > 0 && maxConstraintValueLength > 0) { // If both of min and max constraints are setted we could use // maximum digits number in it as precision precision = Math.max(minConstraintValueLength, maxConstraintValueLength); } else { // Overwise we should also use default precision precision = DefaultGroovyMethods .max(new Integer[] { precision, minConstraintValueLength, maxConstraintValueLength }); } column.setPrecision(precision); } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void bindColumnConfigToColumn(Column column, ColumnConfig columnConfig) { if (columnConfig != null) { column.setLength(columnConfig.getLength()); column.setPrecision(columnConfig.getPrecision()); column.setSqlType(columnConfig.getSqlType()); column.setUnique(columnConfig.getUnique()); column.setScale(columnConfig.getScale()); }/*from w ww .j a va 2s .co m*/ }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void bindSimpleValue(GrailsDomainClassProperty grailsProp, GrailsDomainClassProperty parentProperty, SimpleValue simpleValue, String path, PropertyConfig propertyConfig, String sessionFactoryBeanName) { setTypeForPropertyConfig(grailsProp, simpleValue, propertyConfig); if (grailsProp.isDerived()) { Formula formula = new Formula(); formula.setFormula(propertyConfig.getFormula()); simpleValue.addFormula(formula); } else {//w w w .ja v a 2 s. c o m Table table = simpleValue.getTable(); // 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 = propertyConfig != null ? propertyConfig.getColumns() : Arrays.asList(new Object[] { null }); if (columnDefinitions.isEmpty()) { columnDefinitions = Arrays.asList(new Object[] { null }); } for (int i = 0, n = columnDefinitions.size(); i < n; i++) { ColumnConfig cc = (ColumnConfig) columnDefinitions.get(i); 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); bindColumn(grailsProp, parentProperty, column, cc, path, table, sessionFactoryBeanName); 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()); } column.setUnique(cc.isUnique()); } if (table != null) table.addColumn(column); simpleValue.addColumn(column); } } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * Interrogates the specified constraints looking for any constraints that would limit the * precision and/or scale of the property's value. If such constraints exist, this method adjusts * the precision and/or scale of the column accordingly. * * @param column the column that corresponds to the property * @param constrainedProperty the property's constraints *//*w w w . j a va2 s. c o m*/ protected static void bindNumericColumnConstraints(Column column, ConstrainedProperty constrainedProperty) { int scale = Column.DEFAULT_SCALE; int precision = Column.DEFAULT_PRECISION; if (constrainedProperty.getScale() != null) { scale = constrainedProperty.getScale().intValue(); column.setScale(scale); } Comparable<?> minConstraintValue = constrainedProperty.getMin(); Comparable<?> maxConstraintValue = constrainedProperty.getMax(); int minConstraintValueLength = 0; if ((minConstraintValue != null) && (minConstraintValue instanceof Number)) { minConstraintValueLength = Math.max(countDigits((Number) minConstraintValue), countDigits(new Long(((Number) minConstraintValue).longValue())) + scale); } int maxConstraintValueLength = 0; if ((maxConstraintValue != null) && (maxConstraintValue instanceof Number)) { maxConstraintValueLength = Math.max(countDigits((Number) maxConstraintValue), countDigits(new Long(((Number) maxConstraintValue).longValue())) + scale); } if (minConstraintValueLength > 0 && maxConstraintValueLength > 0) { // If both of min and max constraints are setted we could use // maximum digits number in it as precision precision = NumberUtils.max(new int[] { minConstraintValueLength, maxConstraintValueLength }); } else { // Overwise we should also use default precision precision = NumberUtils .max(new int[] { precision, minConstraintValueLength, maxConstraintValueLength }); } column.setPrecision(precision); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindColumnConfigToColumn(PersistentProperty property, Column column, ColumnConfig columnConfig) { final PropertyConfig mappedForm = property != null ? (PropertyConfig) property.getMapping().getMappedForm() : null;//from ww w . jav a 2s . c om 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.AbstractGrailsDomainBinder.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()) { Formula formula = new Formula(); formula.setFormula(propertyConfig.getFormula()); simpleValue.addFormula(formula); } else {// www. ja v a 2 s .c om Table table = simpleValue.getTable(); // 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 = propertyConfig != null ? 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); } } }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Interrogates the specified constraints looking for any constraints that would limit the * precision and/or scale of the property's value. If such constraints exist, this method adjusts * the precision and/or scale of the column accordingly. * @param column the column that corresponds to the property * @param property the property's constraints * @param cc the column configuration//from w w w . j ava 2 s . c o m */ protected void bindNumericColumnConstraints(Column column, PersistentProperty property, ColumnConfig cc) { int scale = Column.DEFAULT_SCALE; int precision = Column.DEFAULT_PRECISION; PropertyConfig constrainedProperty = (PropertyConfig) property.getMapping().getMappedForm(); if (cc != null && cc.getScale() > -1) { column.setScale(cc.getScale()); } else if (constrainedProperty.getScale() > -1) { scale = constrainedProperty.getScale(); column.setScale(scale); } if (cc != null && cc.getPrecision() > -1) { column.setPrecision(cc.getPrecision()); } else { Comparable<?> minConstraintValue = constrainedProperty.getMin(); Comparable<?> maxConstraintValue = constrainedProperty.getMax(); int minConstraintValueLength = 0; if ((minConstraintValue != null) && (minConstraintValue instanceof Number)) { minConstraintValueLength = Math.max(countDigits((Number) minConstraintValue), countDigits(((Number) minConstraintValue).longValue()) + scale); } int maxConstraintValueLength = 0; if ((maxConstraintValue != null) && (maxConstraintValue instanceof Number)) { maxConstraintValueLength = Math.max(countDigits((Number) maxConstraintValue), countDigits(((Number) maxConstraintValue).longValue()) + scale); } if (minConstraintValueLength > 0 && maxConstraintValueLength > 0) { // If both of min and max constraints are setted we could use // maximum digits number in it as precision precision = Math.max(minConstraintValueLength, maxConstraintValueLength); } else { // Overwise we should also use default precision precision = DefaultGroovyMethods .max(new Integer[] { precision, minConstraintValueLength, maxConstraintValueLength }); } column.setPrecision(precision); } }