Search in sources :

Example 1 with PersistentAssociationPath

use of io.micronaut.data.model.jpa.criteria.PersistentAssociationPath in project micronaut-data by micronaut-projects.

the class AbstractPersistentEntityJoinSupport method addJoin.

private <X, Y> PersistentAssociationPath<X, Y> addJoin(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<X, Y>) path;
}
Also used : Association(io.micronaut.data.model.Association) PersistentProperty(io.micronaut.data.model.PersistentProperty) PersistentAssociationPath(io.micronaut.data.model.jpa.criteria.PersistentAssociationPath)

Example 2 with PersistentAssociationPath

use of io.micronaut.data.model.jpa.criteria.PersistentAssociationPath in project micronaut-data by micronaut-projects.

the class Joiner method visitJoins.

private void visitJoins(Set<? extends jakarta.persistence.criteria.Join<?, ?>> joins) {
    for (jakarta.persistence.criteria.Join<?, ?> join : joins) {
        if (join instanceof PersistentAssociationPath) {
            PersistentAssociationPath persistentAssociationPath = (PersistentAssociationPath) join;
            if (persistentAssociationPath.getAssociationJoinType() == null) {
                continue;
            }
            joinIfNeeded(persistentAssociationPath, false);
            visitJoins(join.getJoins());
        }
    }
}
Also used : PersistentAssociationPath(io.micronaut.data.model.jpa.criteria.PersistentAssociationPath)

Example 3 with PersistentAssociationPath

use of io.micronaut.data.model.jpa.criteria.PersistentAssociationPath in project micronaut-data by micronaut-projects.

the class SourcePersistentEntityPath method get.

@Override
default <Y> PersistentPropertyPath<Y> get(String attributeName) {
    SourcePersistentProperty property = getPersistentEntity().getPropertyByName(attributeName);
    if (property == null) {
        throw new IllegalStateException("Cannot query entity [" + getPersistentEntity().getSimpleName() + "] on non-existent property: " + attributeName);
    }
    if (this instanceof PersistentAssociationPath) {
        PersistentAssociationPath<?, ?> associationPath = (PersistentAssociationPath) this;
        List<Association> associations = associationPath.getAssociations();
        List<Association> newAssociations = new ArrayList<>(associations.size() + 1);
        newAssociations.addAll(associations);
        newAssociations.add(associationPath.getAssociation());
        return new SourcePersistentPropertyPathImpl<>(this, newAssociations, property);
    }
    return new SourcePersistentPropertyPathImpl<>(this, Collections.emptyList(), property);
}
Also used : Association(io.micronaut.data.model.Association) SourcePersistentProperty(io.micronaut.data.processor.model.SourcePersistentProperty) ArrayList(java.util.ArrayList) PersistentAssociationPath(io.micronaut.data.model.jpa.criteria.PersistentAssociationPath)

Aggregations

PersistentAssociationPath (io.micronaut.data.model.jpa.criteria.PersistentAssociationPath)3 Association (io.micronaut.data.model.Association)2 PersistentProperty (io.micronaut.data.model.PersistentProperty)1 SourcePersistentProperty (io.micronaut.data.processor.model.SourcePersistentProperty)1 ArrayList (java.util.ArrayList)1