Search in sources :

Example 11 with ViewToEntityMapper

use of com.blazebit.persistence.view.impl.entity.ViewToEntityMapper in project blaze-persistence by Blazebit.

the class CollectionAttributeFlusher method flushCollectionViewElements.

private List<Object> flushCollectionViewElements(UpdateContext context, V value) {
    final ViewToEntityMapper viewToEntityMapper = elementDescriptor.getViewToEntityMapper();
    final Iterator<Object> iter = getRecordingIterator(value);
    List<Object> embeddables = new ArrayList<>();
    try {
        while (iter.hasNext()) {
            Object elem = iter.next();
            Object embeddable = viewToEntityMapper.applyToEntity(context, null, elem);
            if (!elementDescriptor.isIdentifiable() && mapping != null) {
                // Only query flushing of an element collection can bring us here
                embeddables.add(embeddable);
            }
        }
    } finally {
        resetRecordingIterator(value);
    }
    return embeddables;
}
Also used : ArrayList(java.util.ArrayList) ViewToEntityMapper(com.blazebit.persistence.view.impl.entity.ViewToEntityMapper)

Example 12 with ViewToEntityMapper

use of com.blazebit.persistence.view.impl.entity.ViewToEntityMapper in project blaze-persistence by Blazebit.

the class CollectionAttributeFlusher method invokeCollectionAction.

@Override
protected void invokeCollectionAction(UpdateContext context, Object ownerView, Object view, V targetCollection, Object value, List<? extends CollectionAction<?>> collectionActions) {
    final ViewToEntityMapper viewToEntityMapper = elementDescriptor.getLoadOnlyViewToEntityMapper();
    if (mapping == null) {
        // When the mapping is null this means that there is no collection role in the entity
        // This happens for correlated attributes and we will just provide an empty collection for applying actions
        targetCollection = createCollection(0);
        for (CollectionAction<V> action : (List<CollectionAction<V>>) (List<?>) collectionActions) {
            action.doAction(targetCollection, context, viewToEntityMapper, removeListener);
        }
    } else {
        if (flushStrategy == FlushStrategy.QUERY && !context.isForceEntity()) {
            FusedCollectionActions fusedCollectionActions = null;
            // We can't selectively delete/add if duplicates are allowed. Bags always need to be recreated
            if (canFlushSeparateCollectionOperations()) {
                if (collectionActions.isEmpty()) {
                    return;
                } else if (!(collectionActions.get(0) instanceof CollectionClearAction<?, ?>)) {
                    // The replace action is handled specially
                    fusedCollectionActions = getFusedOperations(collectionActions);
                }
            }
            flushCollectionOperations(context, ownerView, view, null, (V) value, null, fusedCollectionActions, true);
        } else {
            // If an error is desired, a user should configure optimistic locking
            for (CollectionAction<V> action : (List<CollectionAction<V>>) (List<?>) collectionActions) {
                action.doAction(targetCollection, context, viewToEntityMapper, removeListener);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ViewToEntityMapper(com.blazebit.persistence.view.impl.entity.ViewToEntityMapper)

Example 13 with ViewToEntityMapper

use of com.blazebit.persistence.view.impl.entity.ViewToEntityMapper in project blaze-persistence by Blazebit.

the class MapRemoveAllEntriesAction method doAction.

@Override
@SuppressWarnings("unchecked")
public void doAction(C map, UpdateContext context, MapViewToEntityMapper mapper, CollectionRemoveListener keyRemoveListener, CollectionRemoveListener valueRemoveListener) {
    if (mapper != null) {
        Collection<Map.Entry<K, V>> entrySet = map.entrySet();
        ViewToEntityMapper keyMapper = mapper.getKeyMapper();
        ViewToEntityMapper valueMapper = mapper.getValueMapper();
        if (elements.size() == 1) {
            Map.Entry<K, V> entry = elements.iterator().next();
            K k = entry.getKey();
            V v = entry.getValue();
            if (keyMapper != null) {
                k = (K) keyMapper.applyToEntity(context, null, k);
            }
            if (valueMapper != null) {
                v = (V) valueMapper.applyToEntity(context, null, v);
            }
            Map.Entry<K, V> e = new AbstractMap.SimpleEntry<K, V>(k, v);
            if (entrySet.remove(e)) {
                if (keyRemoveListener != null && k != null) {
                    keyRemoveListener.onCollectionRemove(context, entry.getKey());
                }
                if (valueRemoveListener != null && v != null) {
                    valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(entry.getKey()));
                }
            }
        } else {
            if (keyMapper == null) {
                if (valueMapper == null) {
                    for (Map.Entry<? extends K, ? extends V> entry : elements) {
                        K k = entry.getKey();
                        V v = entry.getValue();
                        if (entrySet.remove(entry)) {
                            if (keyRemoveListener != null && k != null) {
                                keyRemoveListener.onCollectionRemove(context, entry.getKey());
                            }
                            if (valueRemoveListener != null && v != null) {
                                valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(entry.getKey()));
                            }
                        }
                    }
                } else {
                    List<V> entities = new ArrayList<>(elements.size());
                    for (Map.Entry<K, V> entry : elements) {
                        entities.add(entry.getValue());
                    }
                    valueMapper.applyAll(context, (List<Object>) entities);
                    int i = 0;
                    for (Map.Entry<? extends K, ? extends V> entry : elements) {
                        K k = entry.getKey();
                        V v = entities.get(i++);
                        Map.Entry<K, V> e = new AbstractMap.SimpleEntry<K, V>(k, v);
                        if (entrySet.remove(e)) {
                            if (keyRemoveListener != null && k != null) {
                                keyRemoveListener.onCollectionRemove(context, entry.getKey());
                            }
                            if (valueRemoveListener != null && v != null) {
                                valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(entry.getKey()));
                            }
                        }
                    }
                }
            } else if (valueMapper == null) {
                List<K> entities = new ArrayList<>(elements.size());
                for (Map.Entry<K, V> entry : elements) {
                    entities.add(entry.getKey());
                }
                keyMapper.applyAll(context, (List<Object>) entities);
                int i = 0;
                for (Map.Entry<? extends K, ? extends V> entry : elements) {
                    K k = entities.get(i++);
                    V v = entry.getValue();
                    Map.Entry<K, V> e = new AbstractMap.SimpleEntry<K, V>(k, v);
                    if (entrySet.remove(e)) {
                        if (keyRemoveListener != null && k != null) {
                            keyRemoveListener.onCollectionRemove(context, entry.getKey());
                        }
                        if (valueRemoveListener != null && v != null) {
                            valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(entry.getKey()));
                        }
                    }
                }
            } else {
                List<K> keyEntities = new ArrayList<>(elements.size());
                List<V> valueEntities = new ArrayList<>(elements.size());
                for (Map.Entry<? extends K, ? extends V> entry : elements) {
                    keyEntities.add(entry.getKey());
                    valueEntities.add(entry.getValue());
                }
                keyMapper.applyAll(context, (List<Object>) keyEntities);
                valueMapper.applyAll(context, (List<Object>) valueEntities);
                int i = 0;
                for (Map.Entry<? extends K, ? extends V> entry : elements) {
                    K k = keyEntities.get(i);
                    V v = valueEntities.get(i++);
                    Map.Entry<K, V> e = new AbstractMap.SimpleEntry<K, V>(k, v);
                    if (entrySet.remove(e)) {
                        if (keyRemoveListener != null && k != null) {
                            keyRemoveListener.onCollectionRemove(context, entry.getKey());
                        }
                        if (valueRemoveListener != null && v != null) {
                            valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(entry.getKey()));
                        }
                    }
                }
            }
        }
    } else {
        if (map.size() > 0 && (keyRemoveListener != null || valueRemoveListener != null)) {
            Collection<Map.Entry<K, V>> entrySet = map.entrySet();
            for (Map.Entry<? extends K, ? extends V> e : elements) {
                if (entrySet.remove(e)) {
                    K k = e.getKey();
                    V v = e.getValue();
                    if (keyRemoveListener != null && k != null) {
                        keyRemoveListener.onCollectionRemove(context, k);
                    }
                    if (valueRemoveListener != null && v != null) {
                        valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(k));
                    }
                }
            }
        } else {
            map.entrySet().removeAll(elements);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AbstractMap(java.util.AbstractMap) List(java.util.List) ArrayList(java.util.ArrayList) MapViewToEntityMapper(com.blazebit.persistence.view.impl.entity.MapViewToEntityMapper) ViewToEntityMapper(com.blazebit.persistence.view.impl.entity.ViewToEntityMapper) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 14 with ViewToEntityMapper

use of com.blazebit.persistence.view.impl.entity.ViewToEntityMapper in project blaze-persistence by Blazebit.

the class MapPutAllAction method doAction.

@Override
@SuppressWarnings("unchecked")
public void doAction(C map, UpdateContext context, MapViewToEntityMapper mapper, CollectionRemoveListener keyRemoveListener, CollectionRemoveListener valueRemoveListener) {
    if (mapper != null) {
        ViewToEntityMapper keyMapper = mapper.getKeyMapper();
        ViewToEntityMapper valueMapper = mapper.getValueMapper();
        if (elements.size() == 1) {
            Map.Entry<? extends K, ? extends V> e = elements.entrySet().iterator().next();
            K k = e.getKey();
            V v = e.getValue();
            if (keyMapper != null) {
                k = (K) keyMapper.applyToEntity(context, null, k);
            }
            if (valueMapper != null) {
                v = (V) valueMapper.applyToEntity(context, null, v);
            }
            V oldValue = map.put(k, v);
            if (valueRemoveListener != null && oldValue != null) {
                valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(e.getKey()));
            }
        } else {
            if (keyMapper == null) {
                if (valueMapper == null) {
                    for (Map.Entry<? extends K, ? extends V> e : elements.entrySet()) {
                        V oldValue = map.put(e.getKey(), e.getValue());
                        if (valueRemoveListener != null && oldValue != null) {
                            valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(e.getKey()));
                        }
                    }
                } else {
                    List<V> entities = new ArrayList<>(elements.size());
                    entities.addAll(elements.values());
                    valueMapper.applyAll(context, (List<Object>) entities);
                    int i = 0;
                    for (Map.Entry<? extends K, ? extends V> e : elements.entrySet()) {
                        V value = entities.get(i++);
                        V oldValue = map.put(e.getKey(), value);
                        if (valueRemoveListener != null && oldValue != null) {
                            valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(e.getKey()));
                        }
                    }
                }
            } else if (valueMapper == null) {
                List<K> entities = new ArrayList<>(elements.size());
                entities.addAll(elements.keySet());
                keyMapper.applyAll(context, (List<Object>) entities);
                int i = 0;
                for (Map.Entry<? extends K, ? extends V> e : elements.entrySet()) {
                    K key = entities.get(i++);
                    V oldValue = map.put(key, e.getValue());
                    if (valueRemoveListener != null && oldValue != null) {
                        valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(e.getKey()));
                    }
                }
            } else {
                List<K> keyEntities = new ArrayList<>(elements.size());
                List<V> valueEntities = new ArrayList<>(elements.size());
                for (Map.Entry<? extends K, ? extends V> entry : elements.entrySet()) {
                    keyEntities.add(entry.getKey());
                    valueEntities.add(entry.getValue());
                }
                keyMapper.applyAll(context, (List<Object>) keyEntities);
                valueMapper.applyAll(context, (List<Object>) valueEntities);
                int i = 0;
                for (Map.Entry<? extends K, ? extends V> e : elements.entrySet()) {
                    K key = keyEntities.get(i);
                    V value = valueEntities.get(i++);
                    V oldValue = map.put(key, value);
                    if (valueRemoveListener != null && oldValue != null) {
                        valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(e.getKey()));
                    }
                }
            }
        }
    } else {
        if (map.size() > 0 && valueRemoveListener != null) {
            for (Map.Entry<? extends K, ? extends V> e : elements.entrySet()) {
                V oldValue = map.put(e.getKey(), e.getValue());
                if (oldValue != null) {
                    valueRemoveListener.onCollectionRemove(context, removedObjectsInView.get(e.getKey()));
                }
            }
        } else {
            map.putAll(elements);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MapViewToEntityMapper(com.blazebit.persistence.view.impl.entity.MapViewToEntityMapper) ViewToEntityMapper(com.blazebit.persistence.view.impl.entity.ViewToEntityMapper) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 15 with ViewToEntityMapper

use of com.blazebit.persistence.view.impl.entity.ViewToEntityMapper in project blaze-persistence by Blazebit.

the class EntityViewUpdaterImpl method createSingularAttributeFlusher.

private DirtyAttributeFlusher<?, ?, ?> createSingularAttributeFlusher(EntityViewManagerImpl evm, Map<Object, EntityViewUpdaterImpl> localCache, ManagedViewTypeImplementor<?> viewType, AbstractMethodAttribute<?, ?> attribute, EntityViewUpdaterImpl owner, String ownerMapping) {
    EntityMetamodel entityMetamodel = evm.getMetamodel().getEntityMetamodel();
    Class<?> entityClass = viewType.getEntityClass();
    String attributeName = attribute.getName();
    String attributeMapping = attribute.getMapping();
    AttributeAccessor entityAttributeAccessor = Accessors.forEntityMapping(evm, attribute);
    String attributeLocation = attribute.getLocation();
    boolean cascadePersist = attribute.isPersistCascaded();
    boolean cascadeUpdate = attribute.isUpdateCascaded();
    boolean cascadeDelete = attribute.isDeleteCascaded();
    boolean viewOnlyDeleteCascaded = cascadeDelete && !entityMetamodel.getManagedType(ExtendedManagedType.class, entityClass).getAttribute(attributeMapping).isDeleteCascaded();
    boolean optimisticLockProtected = attribute.isOptimisticLockProtected();
    Set<Type<?>> readOnlyAllowedSubtypes = attribute.getReadOnlyAllowedSubtypes();
    Set<Type<?>> persistAllowedSubtypes = attribute.getPersistCascadeAllowedSubtypes();
    Set<Type<?>> updateAllowedSubtypes = attribute.getUpdateCascadeAllowedSubtypes();
    JpaProvider jpaProvider = evm.getJpaProvider();
    if (attribute.isSubview()) {
        boolean shouldFlushUpdates = cascadeUpdate && !updateAllowedSubtypes.isEmpty();
        boolean shouldFlushPersists = cascadePersist && !persistAllowedSubtypes.isEmpty();
        ManagedViewTypeImplementor<?> subviewType = (ManagedViewTypeImplementor<?>) ((com.blazebit.persistence.view.metamodel.SingularAttribute<?, ?>) attribute).getType();
        boolean passThrough = false;
        if (attribute.isUpdatable() || shouldFlushUpdates || (passThrough = shouldPassThrough(evm, viewType, attribute))) {
            // TODO: shouldn't this be done for any flat view? or are updatable flat views for entity types disallowed?
            if (!(subviewType.getJpaManagedType() instanceof EntityType<?>)) {
                AttributeAccessor viewAttributeAccessor = Accessors.forViewAttribute(evm, attribute, true);
                // A singular attribute where the subview refers to an embeddable type
                EmbeddableUpdaterBasedViewToEntityMapper viewToEntityMapper = new EmbeddableUpdaterBasedViewToEntityMapper(attributeLocation, evm, subviewType.getJavaType(), readOnlyAllowedSubtypes, persistAllowedSubtypes, updateAllowedSubtypes, EntityLoaders.referenceLoaderForAttribute(evm, localCache, subviewType, attribute), shouldFlushPersists, null, owner == null ? this : owner, ownerMapping == null ? attributeMapping : ownerMapping + "." + attributeMapping, localCache);
                CompositeAttributeFlusher nestedFlusher = (CompositeAttributeFlusher) viewToEntityMapper.getFullGraphNode();
                boolean supportsQueryFlush = nestedFlusher.supportsQueryFlush() && jpaProvider.supportsUpdateSetEmbeddable();
                String parameterName;
                String updateFragment;
                if (supportsQueryFlush) {
                    parameterName = attributeName;
                    updateFragment = attributeMapping;
                } else {
                    parameterName = attributeName + "_";
                    updateFragment = attributeMapping + ".";
                }
                return new EmbeddableAttributeFlusher<>(attributeName, attributeMapping, updateFragment, parameterName, optimisticLockProtected, passThrough, supportsQueryFlush, entityAttributeAccessor, viewAttributeAccessor, viewToEntityMapper);
            } else {
                // Subview refers to entity type
                ViewTypeImplementor<?> attributeViewType = (ViewTypeImplementor<?>) subviewType;
                InitialValueAttributeAccessor viewAttributeAccessor = Accessors.forMutableViewAttribute(evm, attribute);
                AttributeAccessor subviewIdAccessor;
                InverseFlusher<Object> inverseFlusher = InverseFlusher.forAttribute(evm, localCache, viewType, attribute, TypeDescriptor.forType(evm, localCache, this, attribute, subviewType, owner, ownerMapping), owner, ownerMapping);
                InverseRemoveStrategy inverseRemoveStrategy = attribute.getInverseRemoveStrategy();
                ManagedType<?> ownerEntityType = owner == null ? viewType.getJpaManagedType() : owner.managedViewType.getJpaManagedType();
                ViewToEntityMapper viewToEntityMapper;
                boolean fetch = shouldFlushUpdates;
                String parameterName = null;
                String attributeElementIdMapping;
                if (ownerEntityType instanceof EntityType<?> && attribute.getMapping() != null) {
                    ExtendedManagedType<?> extendedManagedType = evm.getMetamodel().getEntityMetamodel().getManagedType(ExtendedManagedType.class, attributeViewType.getEntityClass());
                    attributeElementIdMapping = TypeDescriptor.getAttributeElementIdentifier(evm, (EntityType<?>) ownerEntityType, attribute.getName(), ownerMapping, attribute.getMapping(), extendedManagedType.getType());
                } else {
                    attributeElementIdMapping = ((MappingAttribute<?, ?>) attributeViewType.getIdAttribute()).getMapping();
                }
                subviewIdAccessor = Accessors.forSubviewAssociationId(evm, attributeViewType, attributeElementIdMapping, true);
                Attribute<?, ?> attributeIdAttribute = attributeViewType.getJpaManagedType().getAttribute(attributeElementIdMapping);
                javax.persistence.metamodel.Type<?> attributeIdAttributeType = entityMetamodel.type(JpaMetamodelUtils.resolveFieldClass(attributeViewType.getEntityClass(), attributeIdAttribute));
                List<String> idComponentMappings;
                boolean requiresComponentWiseSetInUpdate = true;
                if (requiresComponentWiseSetInUpdate && attributeIdAttributeType instanceof EmbeddableType<?>) {
                    // If the identifier used for the association is an embeddable, we must collect the individual attribute components since updates don't work on embeddables directly
                    Set<Attribute<?, ?>> idAttributeComponents = (Set<Attribute<?, ?>>) ((EmbeddableType<?>) attributeIdAttributeType).getAttributes();
                    idComponentMappings = new ArrayList<>(idAttributeComponents.size());
                    for (Attribute<?, ?> idAttributeComponent : idAttributeComponents) {
                        idComponentMappings.add(attributeMapping + "." + attributeElementIdMapping + "." + idAttributeComponent.getName());
                    }
                } else {
                    idComponentMappings = Collections.singletonList(attributeMapping + "." + attributeElementIdMapping);
                }
                String[] idAttributeMappings = idComponentMappings.toArray(new String[idComponentMappings.size()]);
                if (attribute.isUpdatable() && ownerEntityType instanceof EntityType<?>) {
                    viewToEntityMapper = createViewToEntityMapper(attributeLocation, evm, localCache, (EntityType<?>) ownerEntityType, attributeName, attributeMapping, attributeViewType, cascadePersist, cascadeUpdate, readOnlyAllowedSubtypes, persistAllowedSubtypes, updateAllowedSubtypes, EntityLoaders.referenceLoaderForAttribute(evm, localCache, attributeViewType, attribute.getViewTypes(), attributeElementIdMapping), owner, ownerMapping);
                    parameterName = attributeName;
                } else {
                    String elementIdentifier;
                    if (ownerEntityType instanceof EntityType<?>) {
                        elementIdentifier = TypeDescriptor.getAttributeElementIdentifier(evm, (EntityType<?>) ownerEntityType, attributeName, ownerMapping, attributeMapping, attributeViewType.getJpaManagedType());
                    } else {
                        elementIdentifier = null;
                    }
                    AttributeAccessor entityIdAccessor = Accessors.forEntityMapping(evm, attributeViewType.getEntityClass(), elementIdentifier);
                    if (shouldFlushUpdates) {
                        viewToEntityMapper = new UpdaterBasedViewToEntityMapper(attributeLocation, evm, subviewType.getJavaType(), readOnlyAllowedSubtypes, persistAllowedSubtypes, updateAllowedSubtypes, EntityLoaders.referenceLoaderForAttribute(evm, localCache, subviewType, attribute), subviewIdAccessor, entityIdAccessor, shouldFlushPersists, owner, ownerMapping, localCache);
                    } else if (!shouldFlushPersists && shouldPassThrough(evm, viewType, attribute)) {
                        viewToEntityMapper = new LoadOnlyViewToEntityMapper(EntityLoaders.referenceLoaderForAttribute(evm, localCache, subviewType, attribute), subviewIdAccessor, entityIdAccessor);
                    } else {
                        viewToEntityMapper = new LoadOrPersistViewToEntityMapper(attributeLocation, evm, subviewType.getJavaType(), readOnlyAllowedSubtypes, persistAllowedSubtypes, updateAllowedSubtypes, EntityLoaders.referenceLoaderForAttribute(evm, localCache, subviewType, attribute), subviewIdAccessor, entityIdAccessor, shouldFlushPersists, owner, ownerMapping, localCache);
                    }
                }
                return new SubviewAttributeFlusher<>(attributeName, attributeMapping, optimisticLockProtected, attribute.isUpdatable(), cascadeDelete, attribute.isOrphanRemoval(), viewOnlyDeleteCascaded, subviewType.getConverter(), fetch, idAttributeMappings, parameterName, passThrough, owner != null, entityAttributeAccessor, viewAttributeAccessor, subviewIdAccessor, viewToEntityMapper, inverseFlusher, inverseRemoveStrategy);
            }
        } else {
            return null;
        }
    } else {
        BasicTypeImpl<?> attributeType = (BasicTypeImpl<?>) ((com.blazebit.persistence.view.metamodel.SingularAttribute<?, ?>) attribute).getType();
        TypeDescriptor elementDescriptor = TypeDescriptor.forType(evm, localCache, this, attribute, attributeType, owner, ownerMapping);
        // Basic attributes like String, Integer but also JPA managed types
        boolean updatable = attribute.isUpdatable();
        if (updatable || elementDescriptor.shouldFlushMutations() || shouldPassThrough(evm, viewType, attribute)) {
            // Basic attributes can normally be updated by queries
            InverseFlusher<Object> inverseFlusher = InverseFlusher.forAttribute(evm, localCache, viewType, attribute, elementDescriptor, owner, ownerMapping);
            InverseRemoveStrategy inverseRemoveStrategy = attribute.getInverseRemoveStrategy();
            String parameterName = attributeName;
            String updateFragment = attributeMapping;
            ManagedType<?> ownerEntityType = owner == null ? viewType.getJpaManagedType() : owner.managedViewType.getJpaManagedType();
            UnmappedBasicAttributeCascadeDeleter deleter;
            if (elementDescriptor.isJpaEntity() && cascadeDelete && ownerEntityType instanceof EntityType<?>) {
                String elementIdAttributeName = TypeDescriptor.getAttributeElementIdentifier(evm, (EntityType<?>) ownerEntityType, attributeName, ownerMapping, attributeMapping, attributeType.getManagedType());
                deleter = new UnmappedBasicAttributeCascadeDeleter(evm, attributeName, entityMetamodel.getManagedType(ExtendedManagedType.class, entityClass).getAttribute(attributeMapping), attributeMapping + "." + elementIdAttributeName, false);
            } else {
                deleter = null;
            }
            // When wanting to read the actual value of non-updatable attributes or writing values to attributes we need the view attribute accessor
            // Whenever we merge or persist, we are going to need that
            AttributeAccessor viewAttributeAccessor;
            if (elementDescriptor.shouldFlushMutations()) {
                viewAttributeAccessor = Accessors.forMutableViewAttribute(evm, attribute);
            } else {
                viewAttributeAccessor = Accessors.forViewAttribute(evm, attribute, true);
            }
            Map.Entry<AttributeAccessor, BasicAttributeFlusher>[] componentFlusherEntries = null;
            if (elementDescriptor.isJpaEmbeddable()) {
                if (!jpaProvider.supportsUpdateSetEmbeddable()) {
                    Set<Attribute<?, ?>> attributes = (Set<Attribute<?, ?>>) attributeType.getManagedType().getAttributes();
                    Map<AttributeAccessor, BasicAttributeFlusher> componentFlushers = new HashMap<>(attributes.size());
                    buildComponentFlushers(evm, viewType.getEntityClass(), attributeType.getJavaType(), attributeName + "_", attributeMapping + ".", "", attributes, componentFlushers);
                    componentFlusherEntries = componentFlushers.entrySet().toArray(new Map.Entry[componentFlushers.size()]);
                }
            }
            return new BasicAttributeFlusher<>(attributeName, attributeMapping, true, optimisticLockProtected, updatable, cascadeDelete, attribute.isOrphanRemoval(), viewOnlyDeleteCascaded, componentFlusherEntries, elementDescriptor, updateFragment, parameterName, entityAttributeAccessor, viewAttributeAccessor, deleter, inverseFlusher, inverseRemoveStrategy);
        } else {
            return null;
        }
    }
}
Also used : CompositeAttributeFlusher(com.blazebit.persistence.view.impl.update.flush.CompositeAttributeFlusher) ViewTypeImplementor(com.blazebit.persistence.view.impl.metamodel.ViewTypeImplementor) ManagedViewTypeImplementor(com.blazebit.persistence.view.impl.metamodel.ManagedViewTypeImplementor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InverseRemoveStrategy(com.blazebit.persistence.view.InverseRemoveStrategy) SubviewAttributeFlusher(com.blazebit.persistence.view.impl.update.flush.SubviewAttributeFlusher) UnmappedBasicAttributeCascadeDeleter(com.blazebit.persistence.view.impl.update.flush.UnmappedBasicAttributeCascadeDeleter) ExtendedManagedType(com.blazebit.persistence.spi.ExtendedManagedType) EntityType(javax.persistence.metamodel.EntityType) TypeDescriptor(com.blazebit.persistence.view.impl.update.flush.TypeDescriptor) InitialValueAttributeAccessor(com.blazebit.persistence.view.impl.accessor.InitialValueAttributeAccessor) AttributeAccessor(com.blazebit.persistence.view.impl.accessor.AttributeAccessor) EmbeddableUpdaterBasedViewToEntityMapper(com.blazebit.persistence.view.impl.entity.EmbeddableUpdaterBasedViewToEntityMapper) LoadOrPersistViewToEntityMapper(com.blazebit.persistence.view.impl.entity.LoadOrPersistViewToEntityMapper) Set(java.util.Set) HashSet(java.util.HashSet) UpdaterBasedViewToEntityMapper(com.blazebit.persistence.view.impl.entity.UpdaterBasedViewToEntityMapper) EmbeddableUpdaterBasedViewToEntityMapper(com.blazebit.persistence.view.impl.entity.EmbeddableUpdaterBasedViewToEntityMapper) LoadOnlyViewToEntityMapper(com.blazebit.persistence.view.impl.entity.LoadOnlyViewToEntityMapper) MappingAttribute(com.blazebit.persistence.view.metamodel.MappingAttribute) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) AbstractMethodAttribute(com.blazebit.persistence.view.impl.metamodel.AbstractMethodAttribute) PluralAttribute(com.blazebit.persistence.view.metamodel.PluralAttribute) ExtendedAttribute(com.blazebit.persistence.spi.ExtendedAttribute) MapAttribute(com.blazebit.persistence.view.metamodel.MapAttribute) MethodAttribute(com.blazebit.persistence.view.metamodel.MethodAttribute) BasicTypeImpl(com.blazebit.persistence.view.impl.metamodel.BasicTypeImpl) InitialValueAttributeAccessor(com.blazebit.persistence.view.impl.accessor.InitialValueAttributeAccessor) EmbeddableAttributeFlusher(com.blazebit.persistence.view.impl.update.flush.EmbeddableAttributeFlusher) LoadOrPersistViewToEntityMapper(com.blazebit.persistence.view.impl.entity.LoadOrPersistViewToEntityMapper) LoadOnlyViewToEntityMapper(com.blazebit.persistence.view.impl.entity.LoadOnlyViewToEntityMapper) SimpleMapViewToEntityMapper(com.blazebit.persistence.view.impl.update.flush.SimpleMapViewToEntityMapper) UpdaterBasedViewToEntityMapper(com.blazebit.persistence.view.impl.entity.UpdaterBasedViewToEntityMapper) EmbeddableUpdaterBasedViewToEntityMapper(com.blazebit.persistence.view.impl.entity.EmbeddableUpdaterBasedViewToEntityMapper) MapViewToEntityMapper(com.blazebit.persistence.view.impl.entity.MapViewToEntityMapper) ViewToEntityMapper(com.blazebit.persistence.view.impl.entity.ViewToEntityMapper) JpaProvider(com.blazebit.persistence.spi.JpaProvider) ManagedViewTypeImplementor(com.blazebit.persistence.view.impl.metamodel.ManagedViewTypeImplementor) ManagedType(javax.persistence.metamodel.ManagedType) BasicType(com.blazebit.persistence.view.metamodel.BasicType) EntityType(javax.persistence.metamodel.EntityType) Type(com.blazebit.persistence.view.metamodel.Type) ExtendedManagedType(com.blazebit.persistence.spi.ExtendedManagedType) VersionBasicUserType(com.blazebit.persistence.view.spi.type.VersionBasicUserType) ManagedViewType(com.blazebit.persistence.view.metamodel.ManagedViewType) EmbeddableType(javax.persistence.metamodel.EmbeddableType) ViewType(com.blazebit.persistence.view.metamodel.ViewType) BasicAttributeFlusher(com.blazebit.persistence.view.impl.update.flush.BasicAttributeFlusher) EntityMetamodel(com.blazebit.persistence.parser.EntityMetamodel)

Aggregations

ViewToEntityMapper (com.blazebit.persistence.view.impl.entity.ViewToEntityMapper)22 MapViewToEntityMapper (com.blazebit.persistence.view.impl.entity.MapViewToEntityMapper)11 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)10 AbstractMap (java.util.AbstractMap)8 RecordingMap (com.blazebit.persistence.view.impl.collection.RecordingMap)7 IdentityHashMap (java.util.IdentityHashMap)7 EntityMetamodel (com.blazebit.persistence.parser.EntityMetamodel)4 AttributeAccessor (com.blazebit.persistence.view.impl.accessor.AttributeAccessor)4 LoadOrPersistViewToEntityMapper (com.blazebit.persistence.view.impl.entity.LoadOrPersistViewToEntityMapper)4 ManagedViewType (com.blazebit.persistence.view.metamodel.ManagedViewType)4 MutableStateTrackable (com.blazebit.persistence.view.spi.type.MutableStateTrackable)4 ArrayList (java.util.ArrayList)4 ExtendedAttribute (com.blazebit.persistence.spi.ExtendedAttribute)3 ExtendedManagedType (com.blazebit.persistence.spi.ExtendedManagedType)3 InitialValueAttributeAccessor (com.blazebit.persistence.view.impl.accessor.InitialValueAttributeAccessor)3 EmbeddableUpdaterBasedViewToEntityMapper (com.blazebit.persistence.view.impl.entity.EmbeddableUpdaterBasedViewToEntityMapper)3 LoadOnlyViewToEntityMapper (com.blazebit.persistence.view.impl.entity.LoadOnlyViewToEntityMapper)3 UpdaterBasedViewToEntityMapper (com.blazebit.persistence.view.impl.entity.UpdaterBasedViewToEntityMapper)3