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-2021 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.model.jpa.criteria.impl;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.data.model.Association;
import io.micronaut.data.model.PersistentEntity;
import io.micronaut.data.model.PersistentProperty;
import io.micronaut.data.model.jpa.criteria.PersistentAssociationPath;
import io.micronaut.data.model.jpa.criteria.PersistentCollectionAssociationPath;
import io.micronaut.data.model.jpa.criteria.PersistentEntityCollectionJoin;
import io.micronaut.data.model.jpa.criteria.PersistentEntityFrom;
import io.micronaut.data.model.jpa.criteria.PersistentEntityJoin;
import io.micronaut.data.model.jpa.criteria.PersistentEntityListJoin;
import io.micronaut.data.model.jpa.criteria.PersistentEntitySetJoin;
import io.micronaut.data.model.jpa.criteria.PersistentListAssociationPath;
import io.micronaut.data.model.jpa.criteria.PersistentSetAssociationPath;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Fetch;
import jakarta.persistence.criteria.From;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.MapJoin;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.metamodel.CollectionAttribute;
import jakarta.persistence.metamodel.ListAttribute;
import jakarta.persistence.metamodel.MapAttribute;
import jakarta.persistence.metamodel.PluralAttribute;
import jakarta.persistence.metamodel.SetAttribute;
import jakarta.persistence.metamodel.SingularAttribute;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.notSupportedOperation;
/**
* The abstract implementation of {@link PersistentEntityFrom}.
*
* @param The associated entity owner type
* @param The association entity type
* @author Denis Stepanov
* @since 3.2
*/
@Internal
public abstract class AbstractPersistentEntityJoinSupport implements PersistentEntityFrom, SelectionVisitable {
protected final Map joins = new LinkedHashMap<>();
public abstract PersistentEntity getPersistentEntity();
protected abstract PersistentAssociationPath createJoinAssociation(@NonNull Association association,
@Nullable io.micronaut.data.annotation.Join.Type type,
@Nullable String alias);
private PersistentAssociationPath getJoin(String attributeName, io.micronaut.data.annotation.Join.Type type, String alias) {
PersistentProperty persistentProperty = getPersistentEntity().getPropertyByName(attributeName);
if (!(persistentProperty instanceof Association)) {
throw new IllegalStateException("Expected an association for attribute name: " + attributeName);
}
PersistentAssociationPath path = joins.computeIfAbsent(attributeName, a -> createJoinAssociation((Association) persistentProperty, type, alias));
if (type != null && type != io.micronaut.data.annotation.Join.Type.DEFAULT) {
path.setAssociationJoinType(type);
}
if (alias != null) {
path.setAlias(alias);
}
return (PersistentAssociationPath) path;
}
private PersistentCollectionAssociationPath getCollectionJoin(String attributeName, io.micronaut.data.annotation.Join.Type type, String alias) {
PersistentAssociationPath