All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.micronaut.data.runtime.criteria.RuntimePersistentAssociationPath Maven / Gradle / Ivy

There is a newer version: 4.10.5
Show newest version
/*
 * 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.runtime.criteria;

import io.micronaut.core.annotation.Internal;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.data.annotation.Join;
import io.micronaut.data.model.Association;
import io.micronaut.data.model.jpa.criteria.PersistentAssociationPath;
import io.micronaut.data.model.jpa.criteria.PersistentEntityFrom;
import io.micronaut.data.model.runtime.RuntimeAssociation;
import io.micronaut.data.model.runtime.RuntimePersistentEntity;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Path;

import java.util.ArrayList;
import java.util.List;

/**
 * The runtime associated path.
 *
 * @param  The association owner type
 * @param      The association entity type
 * @author Denis Stepanov
 * @since 3.2
 */
@Internal
class RuntimePersistentAssociationPath extends AbstractRuntimePersistentEntityJoinSupport
    implements RuntimePersistentEntityPath, PersistentAssociationPath {

    private final PersistentEntityFrom parent;
    private final RuntimeAssociation association;
    private final List associations;
    private Join.Type associationJoinType;
    @Nullable
    private String alias;

    RuntimePersistentAssociationPath(PersistentEntityFrom parent,
                                     RuntimeAssociation association,
                                     List associations,
                                     Join.Type associationJoinType,
                                     @Nullable String alias,
                                     CriteriaBuilder criteriaBuilder) {
        super(criteriaBuilder);
        this.parent = parent;
        this.association = association;
        this.associations = associations;
        this.associationJoinType = associationJoinType;
        this.alias = alias;
    }

    @Override
    public PersistentEntityFrom getParent() {
        return parent;
    }

    @Override
    public Join.Type getAssociationJoinType() {
        return associationJoinType;
    }

    @Override
    public void setAssociationJoinType(Join.Type type) {
        this.associationJoinType = type;
    }

    @Override
    @Nullable
    public String getAlias() {
        return alias;
    }

    @Override
    public void setAlias(String alias) {
        this.alias = alias;
    }

    @Override
    public Path getParentPath() {
        return parent;
    }

    @Override
    public RuntimeAssociation getProperty() {
        return association;
    }

    @Override
    public Association getAssociation() {
        return association;
    }

    @Override
    public List getAssociations() {
        return associations;
    }

    @Override
    public RuntimePersistentEntity getPersistentEntity() {
        return (RuntimePersistentEntity) association.getAssociatedEntity();
    }

    @Override
    protected List getCurrentPath() {
        return associated(getAssociations(), association);
    }

    private static List associated(List associations, Association association) {
        List newAssociations = new ArrayList<>(associations.size() + 1);
        newAssociations.addAll(associations);
        newAssociations.add(association);
        return newAssociations;
    }

    @Override
    public String toString() {
        return "RuntimePersistentAssociationPath{" +
            "parent=" + parent +
            ", association=" + association +
            ", associations=" + associations +
            '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy