Search in sources :

Example 1 with BytecodeEnhancementMetadata

use of org.hibernate.bytecode.spi.BytecodeEnhancementMetadata 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 BytecodeEnhancementMetadata

use of org.hibernate.bytecode.spi.BytecodeEnhancementMetadata in project hibernate-orm by hibernate.

the class AbstractEntityTuplizer method getPropertyValues.

@Override
public Object[] getPropertyValues(Object entity) {
    final BytecodeEnhancementMetadata enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata();
    final int span = entityMetamodel.getPropertySpan();
    final Object[] result = new Object[span];
    for (int j = 0; j < span; j++) {
        NonIdentifierAttribute property = entityMetamodel.getProperties()[j];
        if (!property.isLazy() || enhancementMetadata.isAttributeLoaded(entity, property.getName())) {
            result[j] = getters[j].get(entity);
        } else {
            result[j] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
        }
    }
    return result;
}
Also used : NonIdentifierAttribute(org.hibernate.tuple.NonIdentifierAttribute) BytecodeEnhancementMetadata(org.hibernate.bytecode.spi.BytecodeEnhancementMetadata)

Aggregations

BytecodeEnhancementMetadata (org.hibernate.bytecode.spi.BytecodeEnhancementMetadata)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 LazyAttributesMetadata (org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata)1 NonIdentifierAttribute (org.hibernate.tuple.NonIdentifierAttribute)1