Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017-2022 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.data.runtime.operations.internal;
import io.micronaut.core.annotation.AnnotationMetadata;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.beans.BeanProperty;
import io.micronaut.core.convert.ArgumentConversionContext;
import io.micronaut.core.convert.ConversionContext;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.convert.exceptions.ConversionErrorException;
import io.micronaut.core.type.Argument;
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.data.annotation.Relation;
import io.micronaut.data.model.Association;
import io.micronaut.data.model.PersistentAssociationPath;
import io.micronaut.data.model.runtime.RuntimeAssociation;
import io.micronaut.data.model.runtime.RuntimePersistentEntity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
/**
* Abstract cascade operations.
*
* @author Denis Stepanov
* @since 3.3
*/
@Internal
abstract class AbstractCascadeOperations {
private final ConversionService conversionService;
/**
* Default constructor.
*
* @param conversionService The conversion service.
*/
protected AbstractCascadeOperations(ConversionService conversionService) {
this.conversionService = conversionService;
}
/**
* Cascade on the entity instance and collect cascade operations.
*
* @param annotationMetadata The annotationMetadata
* @param repositoryType The repositoryType
* @param fkOnly Is FK only
* @param cascadeType The cascadeType
* @param ctx The cascade context
* @param persistentEntity The persistent entity
* @param entity The entity instance
* @param cascadeOps The cascade operations
* @param The entity type
*/
protected void cascade(AnnotationMetadata annotationMetadata, Class> repositoryType,
boolean fkOnly,
Relation.Cascade cascadeType,
CascadeContext ctx,
RuntimePersistentEntity persistentEntity,
T entity,
List cascadeOps) {
for (RuntimeAssociation association : persistentEntity.getAssociations()) {
BeanProperty beanProperty = association.getProperty();
Object child = beanProperty.get(entity);
if (child == null) {
continue;
}
if (association.isEmbedded()) {
cascade(annotationMetadata, repositoryType, fkOnly, cascadeType, ctx.embedded(association),
(RuntimePersistentEntity) association.getAssociatedEntity(),
child,
cascadeOps);
continue;
}
if (association.doesCascade(cascadeType) && (fkOnly || !association.isForeignKey())) {
if (association.getInverseSide().map(assoc -> ctx.rootAssociations.contains(assoc) || ctx.associations.contains(assoc)).orElse(false)) {
continue;
}
final RuntimePersistentEntity