Example usage for org.hibernate.mapping Column getScale

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

Introduction

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

Prototype

public int getScale() 

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());//from w  ww . j  a  v a2  s.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:it.eng.qbe.model.structure.builder.hibernate.HibernateModelStructureBuilder.java

License:Mozilla Public License

private void addKeyFields(IModelEntity dataMartEntity) {

    PersistentClass classMapping;// ww  w  .jav  a 2  s.co m
    ClassMetadata classMetadata;
    Type identifierType;

    getDataSource().getHibernateConfiguration().buildMappings();//must be called 
    classMapping = getDataSource().getHibernateConfiguration().getClassMapping(dataMartEntity.getType());
    if (classMapping == null) {
        System.out.println("class mapping for entity [" + dataMartEntity.getType() + "] not found");
        Iterator<PersistentClass> it = getDataSource().getHibernateConfiguration().getClassMappings();
        while (it.hasNext()) {
            PersistentClass pc = it.next();
            System.out.println("-> [" + pc.getClass().getName() + "] not found");
        }
    }

    classMetadata = getDataSource().getHibernateSessionFactory().getClassMetadata(dataMartEntity.getType());
    identifierType = classMetadata.getIdentifierType();

    List identifierPropertyNames = new ArrayList();
    String[] propertyClass = null;
    String[] type = null;
    int[] scale = null;
    int[] precision = null;

    String identifierPropertyName = classMetadata.getIdentifierPropertyName();

    if (identifierType.isComponentType()) {

        ComponentType componentIdentifierType = (ComponentType) identifierType;
        String[] subPropertyNames = componentIdentifierType.getPropertyNames();

        Type[] subPropertyTypes = componentIdentifierType.getSubtypes();

        propertyClass = new String[subPropertyNames.length];
        type = new String[subPropertyNames.length];
        scale = new int[subPropertyNames.length];
        precision = new int[subPropertyNames.length];
        Class subPropertyClass = null;

        for (int j = 0; j < subPropertyNames.length; j++) {
            subPropertyClass = subPropertyTypes[j].getClass();

            if (subPropertyTypes[j].isComponentType()) {
                ComponentType cType = (ComponentType) subPropertyTypes[j];
                String[] sPropertyNames = cType.getPropertyNames();
                Type[] sTypes = cType.getSubtypes();
                for (int z = 0; z < sPropertyNames.length; z++) {
                    identifierPropertyNames
                            .add(identifierPropertyName + "." + subPropertyNames[j] + "." + sPropertyNames[z]);
                    propertyClass[j] = subPropertyClass.getName();
                    type[j] = subPropertyTypes[j].getName();
                }
            } else {
                identifierPropertyNames.add(identifierPropertyName + "." + subPropertyNames[j]);
                propertyClass[j] = subPropertyClass.getName();
                type[j] = subPropertyTypes[j].getName();
            }
        }

    } else {
        propertyClass = new String[1];
        type = new String[1];
        scale = new int[1];
        precision = new int[1];

        identifierPropertyNames.add(identifierPropertyName);
        propertyClass[0] = identifierType.getClass().getName();
        type[0] = identifierType.getName();
    }

    Iterator it = classMapping.getIdentifierProperty().getColumnIterator();
    for (int k = 0; k < scale.length; k++) {
        if (!it.hasNext())
            continue;
        Column column = (Column) it.next();
        scale[k] = column.getScale();
        precision[k] = column.getPrecision();
    }

    for (int j = 0; j < identifierPropertyNames.size(); j++) {
        String fieldName = (String) identifierPropertyNames.get(j);
        IModelField dataMartField = dataMartEntity.addKeyField(fieldName);
        dataMartField.setType(type[j]);
        dataMartField.setPrecision(precision[j]);
        dataMartField.setLength(scale[j]);
        propertiesInitializer.addProperties(dataMartField);
    }
}

From source file:it.eng.qbe.model.structure.builder.hibernate.HibernateModelStructureBuilder.java

License:Mozilla Public License

public List addNormalFields(IModelEntity dataMartEntity) {

    ClassMetadata classMetadata;//from w w  w .  java 2  s .  c  o  m
    PersistentClass classMapping;
    String[] propertyNames;
    Property property;
    Type propertyType;

    classMetadata = getDataSource().getHibernateSessionFactory().getClassMetadata(dataMartEntity.getType());
    classMapping = getDataSource().getHibernateConfiguration().getClassMapping(dataMartEntity.getType());
    propertyNames = classMetadata.getPropertyNames();

    List subEntities = new ArrayList();
    String propertyName = null;

    for (int i = 0; i < propertyNames.length; i++) {

        property = classMapping.getProperty(propertyNames[i]);

        // TEST if they are the same: if so use the first invocation
        propertyType = property.getType();

        Iterator columnIterator = property.getColumnIterator();
        Column column;

        if (propertyType instanceof ManyToOneType) { // chiave esterna

            ManyToOneType manyToOnePropertyType = (ManyToOneType) propertyType;
            String entityType = manyToOnePropertyType.getAssociatedEntityName();

            String columnName = null;
            if (columnIterator.hasNext()) {
                column = (Column) columnIterator.next();
                columnName = column.getName(); // ????
            }

            propertyName = propertyNames[i];

            //String entityName = getEntityNameFromEntityType(entityType);
            String entityName = propertyName;
            IModelEntity subentity = new ModelEntity(entityName, null, columnName, entityType,
                    dataMartEntity.getStructure());
            subEntities.add(subentity);

        } else if (propertyType instanceof CollectionType) { // chiave interna

        } else { // normal field
            propertyName = propertyNames[i];

            String type = propertyType.getName();
            int scale = 0;
            int precision = 0;

            if (columnIterator.hasNext()) {
                column = (Column) columnIterator.next();
                scale = column.getScale();
                precision = column.getPrecision();
            }

            IModelField datamartField = dataMartEntity.addNormalField(propertyName);
            datamartField.setType(type);
            datamartField.setPrecision(precision);
            datamartField.setLength(scale);
            propertiesInitializer.addProperties(datamartField);
        }
    }

    return subEntities;
}

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

License:Apache License

/**
 * Note to the unassuming maintenance developer:
 *
 * What happens with Oracle a dialect is when a varchar2 is larger than 4000,
 * the type name returned for java.sql.Type.VARCHAR is a long, which can be very confusing.
 *
 * I'm not sure that this is significant enough to warrant patching.
 *
 *///from  w w  w .j  a va2  s  . c om
private static String getTypeName(Dialect dialect, Column col) {
    return dialect.getTypeName(col.getSqlTypeCode(), col.getLength(), col.getPrecision(), col.getScale());
}

From source file:org.broadleafcommerce.openadmin.server.dao.DynamicEntityDaoImpl.java

License:Apache License

protected FieldMetadata getFieldMetadata(String prefix, String propertyName, List<Property> componentProperties,
        SupportedFieldType type, SupportedFieldType secondaryType, Type entityType, Class<?> targetClass,
        FieldPresentationAttributes presentationAttribute, MergedPropertyType mergedPropertyType)
        throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException,
        IllegalAccessException, InvocationTargetException {
    FieldMetadata fieldMetadata = new FieldMetadata();
    fieldMetadata.setFieldType(type);/*from  www. jav a2s. c o m*/
    fieldMetadata.setSecondaryType(secondaryType);
    if (entityType != null && !entityType.isCollectionType()) {
        Column column = null;
        for (Property property : componentProperties) {
            if (property.getName().equals(propertyName)) {
                column = (Column) property.getColumnIterator().next();
                break;
            }
        }
        if (column != null) {
            fieldMetadata.setLength(column.getLength());
            fieldMetadata.setScale(column.getScale());
            fieldMetadata.setPrecision(column.getPrecision());
            fieldMetadata.setRequired(!column.isNullable());
            fieldMetadata.setUnique(column.isUnique());
        }
        fieldMetadata.setCollection(false);
    } else {
        fieldMetadata.setCollection(true);
    }
    fieldMetadata.setMutable(true);
    fieldMetadata.setInheritedFromType(targetClass.getName());
    fieldMetadata.setAvailableToTypes(new String[] { targetClass.getName() });
    if (presentationAttribute != null) {
        fieldMetadata.setPresentationAttributes(presentationAttribute);
    }
    fieldMetadata.setMergedPropertyType(mergedPropertyType);
    if (SupportedFieldType.BROADLEAF_ENUMERATION.equals(type)) {
        setupBroadleafEnumeration(presentationAttribute.getBroadleafEnumeration(), fieldMetadata);
    }

    return fieldMetadata;
}

From source file:org.broadleafcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider.java

License:Apache License

@Override
public FieldProviderResponse addMetadataFromMappingData(
        AddMetadataFromMappingDataRequest addMetadataFromMappingDataRequest, FieldMetadata metadata) {
    BasicFieldMetadata fieldMetadata = (BasicFieldMetadata) metadata;
    fieldMetadata.setFieldType(addMetadataFromMappingDataRequest.getType());
    fieldMetadata.setSecondaryType(addMetadataFromMappingDataRequest.getSecondaryType());
    if (addMetadataFromMappingDataRequest.getRequestedEntityType() != null
            && !addMetadataFromMappingDataRequest.getRequestedEntityType().isCollectionType()) {
        Column column = null;
        for (Property property : addMetadataFromMappingDataRequest.getComponentProperties()) {
            if (property.getName().equals(addMetadataFromMappingDataRequest.getPropertyName())) {
                Object columnObject = property.getColumnIterator().next();
                if (columnObject instanceof Column) {
                    column = (Column) columnObject;
                }/*from w  w  w . j  a  v  a  2 s  .  c om*/
                break;
            }
        }
        if (column != null) {
            fieldMetadata.setLength(column.getLength());
            fieldMetadata.setScale(column.getScale());
            fieldMetadata.setPrecision(column.getPrecision());
            fieldMetadata.setRequired(!column.isNullable());
            fieldMetadata.setUnique(column.isUnique());
        }
        fieldMetadata.setForeignKeyCollection(false);
    } else {
        fieldMetadata.setForeignKeyCollection(true);
    }
    fieldMetadata.setMutable(true);
    fieldMetadata.setMergedPropertyType(addMetadataFromMappingDataRequest.getMergedPropertyType());
    if (SupportedFieldType.BROADLEAF_ENUMERATION.equals(addMetadataFromMappingDataRequest.getType())) {
        try {
            setupBroadleafEnumeration(fieldMetadata.getBroadleafEnumeration(), fieldMetadata,
                    addMetadataFromMappingDataRequest.getDynamicEntityDao());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return FieldProviderResponse.HANDLED;
}

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

License:Apache License

private void assertColumnPrecisionAndScale(ConstrainedProperty constrainedProperty, int expectedPrecision,
        int expectedScale) {
    Column column = new Column();
    GrailsDomainBinder.bindNumericColumnConstraints(column, constrainedProperty);
    assertEquals(expectedPrecision, column.getPrecision());
    assertEquals(expectedScale, column.getScale());
}

From source file:org.sparkcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider.java

License:Apache License

@Override
public FieldProviderResponse addMetadataFromMappingData(
        AddMetadataFromMappingDataRequest addMetadataFromMappingDataRequest, FieldMetadata metadata) {
    BasicFieldMetadata fieldMetadata = (BasicFieldMetadata) metadata;
    fieldMetadata.setFieldType(addMetadataFromMappingDataRequest.getType());
    fieldMetadata.setSecondaryType(addMetadataFromMappingDataRequest.getSecondaryType());
    if (addMetadataFromMappingDataRequest.getRequestedEntityType() != null
            && !addMetadataFromMappingDataRequest.getRequestedEntityType().isCollectionType()) {
        Column column = null;
        for (Property property : addMetadataFromMappingDataRequest.getComponentProperties()) {
            if (property.getName().equals(addMetadataFromMappingDataRequest.getPropertyName())) {
                Object columnObject = property.getColumnIterator().next();
                if (columnObject instanceof Column) {
                    column = (Column) columnObject;
                }/*from   w  w  w.  j a v a  2s . c  om*/
                break;
            }
        }
        if (column != null) {
            fieldMetadata.setLength(column.getLength());
            fieldMetadata.setScale(column.getScale());
            fieldMetadata.setPrecision(column.getPrecision());
            fieldMetadata.setRequired(!column.isNullable());
            fieldMetadata.setUnique(column.isUnique());
        }
        fieldMetadata.setForeignKeyCollection(false);
    } else {
        fieldMetadata.setForeignKeyCollection(true);
    }
    fieldMetadata.setMutable(true);
    fieldMetadata.setMergedPropertyType(addMetadataFromMappingDataRequest.getMergedPropertyType());
    if (SupportedFieldType.BROADLEAF_ENUMERATION.equals(addMetadataFromMappingDataRequest.getType())) {
        try {
            setupSparkEnumeration(fieldMetadata.getSparkEnumeration(), fieldMetadata,
                    addMetadataFromMappingDataRequest.getDynamicEntityDao());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return FieldProviderResponse.HANDLED;
}