Example usage for org.hibernate.mapping Column setLength

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

Introduction

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

Prototype

public void setLength(int length) 

Source Link

Usage

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());
    col.setPrecision(column.getLength());
    col.setScale(column.getScale());/*from w  w  w  .j av a 2 s  . c o  m*/
    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:net.lshift.hibernate.migrations.AlterTableBuilder.java

License:Apache License

private static Column buildColumnDefinition(String name, int sqlType, int length, boolean nullable,
        Object defaultVal) {//w  ww  .  j av a 2 s .c  o  m
    Column col = new Column(name);
    col.setSqlTypeCode(sqlType);
    col.setNullable(nullable);
    col.setLength(length);
    col.setDefaultValue(defaultVal != null ? defaultVal.toString() : null);
    return col;
}

From source file:net.lshift.hibernate.migrations.CreateTableBuilder.java

License:Apache License

public CreateTableBuilder column(String name, int sqlType, int length, boolean nullable, Object defaultVal) {
    Column col = new Column(name);
    col.setNullable(nullable);// ww w .j  a v  a2  s  .  c o  m
    col.setSqlTypeCode(sqlType);
    col.setLength(length);
    col.setDefaultValue(defaultVal != null ? defaultVal.toString() : null);

    columns.add(col);

    return this;
}

From source file:org.beangle.orm.hibernate.tool.HbmGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
public void gen(String file) throws Exception {
    hbconfig = new OverrideConfiguration();
    hbconfig.getProperties().put(Environment.DIALECT, new Oracle10gDialect());
    ConfigBuilder.build(hbconfig);//from ww w .j ava2  s .  c om
    freemarkerConfig = new freemarker.template.Configuration();
    freemarkerConfig.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));

    Iterator<PersistentClass> iter = hbconfig.getClassMappings();
    List<PersistentClass> pcs = CollectUtils.newArrayList();
    while (iter.hasNext()) {
        PersistentClass pc = iter.next();
        Class<?> cls = pc.getMappedClass();
        Iterator<Property> pi = pc.getPropertyIterator();
        // For AnnotationBinder don't set column'length and nullable in ,let's we do it.
        while (pi.hasNext()) {
            Property p = pi.next();
            if (p.getColumnSpan() != 1)
                continue;
            Column column = (Column) p.getColumnIterator().next();
            if (column.getLength() == Column.DEFAULT_LENGTH) {
                Size size = findAnnotation(cls, Size.class, p.getName());
                if (null != size)
                    column.setLength(size.max());
            }
            if (column.isNullable()) {
                NotNull notnull = findAnnotation(cls, NotNull.class, p.getName());
                if (null != notnull)
                    column.setNullable(false);
            }
        }
        if (!pc.getClassName().contains(".example."))
            pcs.add(pc);
    }
    Map<String, Object> data = CollectUtils.newHashMap();
    data.put("classes", pcs);
    data.put("generator", this);
    Template freemarkerTemplate = freemarkerConfig.getTemplate("/hbm.ftl");
    FileWriter fw = new FileWriter("/tmp/hibernate.hbm.xml");
    freemarkerTemplate.process(data, fw);
}

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 ww  w .  j av a 2 s .  co m*/
    }

    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 linkValueUsingAColumnCopy(GrailsDomainClassProperty prop, Column column, DependantValue key) {
    Column mappingColumn = new Column();
    mappingColumn.setName(column.getName());
    mappingColumn.setLength(column.getLength());
    mappingColumn.setNullable(prop.isOptional());
    mappingColumn.setSqlType(column.getSqlType());

    mappingColumn.setValue(key);/*from w w w. jav  a  2s  .co m*/
    key.addColumn(mappingColumn);
    key.getTable().addColumn(mappingColumn);
}

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   w  w w  . j  av a2  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
 * length of the property's value.  If such constraints exist, this method adjusts the length
 * of the column accordingly./*from  w  w w. j  a v  a2  s.  c  o  m*/
 *
 * @param column              the column that corresponds to the property
 * @param constrainedProperty the property's constraints
 */
protected void bindStringColumnConstraints(Column column, ConstrainedProperty constrainedProperty) {
    Integer columnLength = constrainedProperty.getMaxSize();
    List<?> inListValues = constrainedProperty.getInList();
    if (columnLength != null) {
        column.setLength(columnLength.intValue());
    } else if (inListValues != null) {
        column.setLength(getMaxSize(inListValues));
    }
}

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());
    }/*  w  ww  . ja  v  a2 s  .  co  m*/
}

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

License:Apache License

private static void linkValueUsingAColumnCopy(GrailsDomainClassProperty prop, Column column,
        DependantValue key) {// w w  w.  ja v a2 s  .  c  o m
    Column mappingColumn = new Column();
    mappingColumn.setName(column.getName());
    mappingColumn.setLength(column.getLength());
    mappingColumn.setNullable(prop.isOptional());
    mappingColumn.setSqlType(column.getSqlType());

    mappingColumn.setValue(key);
    key.addColumn(mappingColumn);
    key.getTable().addColumn(mappingColumn);
}