Search in sources :

Example 1 with LazyAttributesMetadata

use of org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata in project hibernate-orm by hibernate.

the class AbstractEntityPersister method generateLazySelectStringsByFetchGroup.

protected Map<String, String> generateLazySelectStringsByFetchGroup() {
    final BytecodeEnhancementMetadata enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata();
    if (!enhancementMetadata.isEnhancedForLazyLoading() || !enhancementMetadata.getLazyAttributesMetadata().hasLazyAttributes()) {
        return Collections.emptyMap();
    }
    Map<String, String> result = new HashMap<>();
    final LazyAttributesMetadata lazyAttributesMetadata = enhancementMetadata.getLazyAttributesMetadata();
    for (String groupName : lazyAttributesMetadata.getFetchGroupNames()) {
        HashSet tableNumbers = new HashSet();
        ArrayList columnNumbers = new ArrayList();
        ArrayList formulaNumbers = new ArrayList();
        for (LazyAttributeDescriptor lazyAttributeDescriptor : lazyAttributesMetadata.getFetchGroupAttributeDescriptors(groupName)) {
            // all this only really needs to consider properties
            // of this class, not its subclasses, but since we
            // are reusing code used for sequential selects, we
            // use the subclass closure
            int propertyNumber = getSubclassPropertyIndex(lazyAttributeDescriptor.getName());
            int tableNumber = getSubclassPropertyTableNumber(propertyNumber);
            tableNumbers.add(tableNumber);
            int[] colNumbers = subclassPropertyColumnNumberClosure[propertyNumber];
            for (int colNumber : colNumbers) {
                if (colNumber != -1) {
                    columnNumbers.add(colNumber);
                }
            }
            int[] formNumbers = subclassPropertyFormulaNumberClosure[propertyNumber];
            for (int formNumber : formNumbers) {
                if (formNumber != -1) {
                    formulaNumbers.add(formNumber);
                }
            }
        }
        if (columnNumbers.size() == 0 && formulaNumbers.size() == 0) {
            // only one-to-one is lazy fetched
            continue;
        }
        result.put(groupName, renderSelect(ArrayHelper.toIntArray(tableNumbers), ArrayHelper.toIntArray(columnNumbers), ArrayHelper.toIntArray(formulaNumbers)));
    }
    return result;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LazyAttributesMetadata(org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata) ArrayList(java.util.ArrayList) BytecodeEnhancementMetadata(org.hibernate.bytecode.spi.BytecodeEnhancementMetadata) LazyAttributeDescriptor(org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeDescriptor) HashSet(java.util.HashSet)

Example 2 with LazyAttributesMetadata

use of org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata in project hibernate-orm by hibernate.

the class BytecodeEnhancementMetadataPojoImpl method from.

public static BytecodeEnhancementMetadata from(PersistentClass persistentClass) {
    final Class mappedClass = persistentClass.getMappedClass();
    final boolean enhancedForLazyLoading = PersistentAttributeInterceptable.class.isAssignableFrom(mappedClass);
    final LazyAttributesMetadata lazyAttributesMetadata = enhancedForLazyLoading ? LazyAttributesMetadata.from(persistentClass) : LazyAttributesMetadata.nonEnhanced(persistentClass.getEntityName());
    return new BytecodeEnhancementMetadataPojoImpl(persistentClass.getEntityName(), mappedClass, enhancedForLazyLoading, lazyAttributesMetadata);
}
Also used : LazyAttributesMetadata(org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

LazyAttributesMetadata (org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LazyAttributeDescriptor (org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeDescriptor)1 BytecodeEnhancementMetadata (org.hibernate.bytecode.spi.BytecodeEnhancementMetadata)1 PersistentClass (org.hibernate.mapping.PersistentClass)1