Example usage for org.hibernate.type Type getColumnSpan

List of usage examples for org.hibernate.type Type getColumnSpan

Introduction

In this page you can find the example usage for org.hibernate.type Type getColumnSpan.

Prototype

int getColumnSpan(Mapping mapping) throws MappingException;

Source Link

Document

How many columns are used to persist this type.

Usage

From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java

License:Apache License

private String[] columnNamesByPropertyName(AbstractEntityPersister persister, String[] propertyNames,
        String subAttributeName, String prefix, String[] elementColumnNames, Mapping factory) {
    int offset = 0;
    for (int i = 0; i < propertyNames.length; i++) {
        String propertyName = propertyNames[i];
        Type propertyType = persister.getPropertyType(prefix + propertyName);
        int span = propertyType.getColumnSpan(factory);
        if (subAttributeName.equals(propertyName)) {
            String[] columnNames = new String[span];
            System.arraycopy(elementColumnNames, offset, columnNames, 0, span);
            return columnNames;
        } else {//from  w  w w  . j a  va2s  . c  o m
            offset += span;
        }
    }

    return null;
}

From source file:org.nextframework.persistence.PersistenceUtils.java

License:Apache License

@SuppressWarnings("unchecked")
private static InverseCollectionProperties getInverseCollectionProperties(
        SessionFactoryImplementor sessionFactoryImplementor, Class<? extends Object> clazz,
        Class<?> returnedClass, String[] keyColumnNames, String[] propertyColumnNames, Type propertyType,
        String propertyName) {/*ww  w.ja  va 2  s.  c om*/
    if (propertyType instanceof ManyToOneType) {
        ManyToOneType mtot = (ManyToOneType) propertyType;
        if (mtot.getReturnedClass().isAssignableFrom(clazz)) {
            //if propertyColumnNames == keyColumnNames
            if (Arrays.deepEquals(propertyColumnNames, keyColumnNames)) {
                InverseCollectionProperties inverseCollectionProperties = new InverseCollectionProperties();
                inverseCollectionProperties.property = propertyName;
                inverseCollectionProperties.type = returnedClass;
                return inverseCollectionProperties;
            }
        }
    }
    if (propertyType instanceof ComponentType) {
        ComponentType ct = (ComponentType) propertyType;
        String[] propertyNames = ct.getPropertyNames();
        Type[] propertyTypes = ct.getSubtypes();
        int beginIndex = 0;
        for (int i = 0; i < propertyTypes.length; i++) {
            Type subType = propertyTypes[i];
            String subPropertyName = propertyNames[i];
            int columnSpan = subType.getColumnSpan(sessionFactoryImplementor);
            String[] propertyColumnNamesMapping = new String[columnSpan];
            System.arraycopy(propertyColumnNames, beginIndex, propertyColumnNamesMapping, 0, columnSpan);
            InverseCollectionProperties inverseCollectionProperties = getInverseCollectionProperties(
                    sessionFactoryImplementor, clazz, returnedClass, keyColumnNames, propertyColumnNamesMapping,
                    subType, subPropertyName);
            if (inverseCollectionProperties != null) {
                inverseCollectionProperties.property = propertyName + "."
                        + inverseCollectionProperties.property;
                return inverseCollectionProperties;
            }
            beginIndex += columnSpan;
        }
    }
    return null;
}