diff --git a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java index c03e63bd2ad7..184e9da8b18f 100644 --- a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java @@ -13,7 +13,6 @@ import jakarta.persistence.TypedQueryReference; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.spi.FilterDefinition; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.graph.GraphParser; import org.hibernate.graph.InvalidGraphException; import org.hibernate.graph.RootGraph; @@ -108,7 +107,7 @@ * SingularAttribute<Book,String>}. * *

- * Use of these statically-typed metamodel references is the preferred way of + * Use of these statically typed metamodel references is the preferred way of * working with the {@linkplain jakarta.persistence.criteria.CriteriaBuilder * criteria query API}, and with {@linkplain EntityGraph}s. *

@@ -266,7 +265,7 @@ default void inSession(Consumer action) { * @since 6.3 */ default void inStatelessSession(Consumer action) { - try ( StatelessSession session = openStatelessSession() ) { + try ( var session = openStatelessSession() ) { action.accept( session ); } } @@ -308,7 +307,7 @@ default void inStatelessTransaction(Consumer action) { * @see #fromTransaction(Function) */ default R fromSession(Function action) { - try ( Session session = openSession() ) { + try ( var session = openSession() ) { return action.apply( session ); } } @@ -331,7 +330,7 @@ default R fromSession(Function action) { * @since 6.3 */ default R fromStatelessSession(Function action) { - try ( StatelessSession session = openStatelessSession() ) { + try ( var session = openStatelessSession() ) { return action.apply( session ); } } @@ -522,9 +521,7 @@ default RootGraph createEntityGraph(Class entityType) { * * @since 7.0 */ - default RootGraph parseEntityGraph(Class rootEntityClass, CharSequence graphText) { - return GraphParser.parse( rootEntityClass, graphText.toString(), unwrap( SessionFactoryImplementor.class ) ); - } + RootGraph parseEntityGraph(Class rootEntityClass, CharSequence graphText); /** * Creates a {@link RootGraph} for the given {@code rootEntityName} and parses the graph @@ -543,9 +540,8 @@ default RootGraph parseEntityGraph(Class rootEntityClass, CharSequence * * @since 7.0 */ - default RootGraph parseEntityGraph(String rootEntityName, CharSequence graphText) { - return GraphParser.parse( rootEntityName, graphText.toString(), unwrap( SessionFactoryImplementor.class ) ); - } + @Incubating + RootGraph parseEntityGraph(String rootEntityName, CharSequence graphText); /** * Creates a {@link RootGraph} based on the passed string representation. Here, the @@ -560,9 +556,8 @@ default RootGraph parseEntityGraph(String rootEntityName, CharSequence gr * * @since 7.0 */ - default RootGraph parseEntityGraph(CharSequence graphText) { - return GraphParser.parse( graphText.toString(), unwrap( SessionFactoryImplementor.class ) ); - } + @Incubating + RootGraph parseEntityGraph(CharSequence graphText); /** * Obtain the set of names of all {@linkplain org.hibernate.annotations.FilterDef diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/NamedGraphCreator.java b/hibernate-core/src/main/java/org/hibernate/boot/model/NamedGraphCreator.java index 026af3d8f896..098fbbe844e2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/NamedGraphCreator.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/NamedGraphCreator.java @@ -4,17 +4,16 @@ */ package org.hibernate.boot.model; +import org.hibernate.graph.spi.GraphParserEntityClassResolver; +import org.hibernate.graph.spi.GraphParserEntityNameResolver; import org.hibernate.graph.spi.RootGraphImplementor; -import org.hibernate.metamodel.model.domain.EntityDomainType; - -import java.util.function.Function; /** * @author Steve Ebersole */ @FunctionalInterface public interface NamedGraphCreator { - RootGraphImplementor createEntityGraph( - Function, EntityDomainType> entityDomainClassResolver, - Function> entityDomainNameResolver); + RootGraphImplementor createEntityGraph( + GraphParserEntityClassResolver entityDomainClassResolver, + GraphParserEntityNameResolver entityDomainNameResolver); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorJpa.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorJpa.java index 9aebd53de1c2..852df030cc65 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorJpa.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorJpa.java @@ -6,17 +6,18 @@ import jakarta.persistence.NamedAttributeNode; import jakarta.persistence.NamedEntityGraph; +import org.checkerframework.checker.nullness.qual.NonNull; import org.hibernate.AnnotationException; import org.hibernate.boot.model.NamedGraphCreator; import org.hibernate.graph.internal.RootGraphImpl; import org.hibernate.graph.spi.AttributeNodeImplementor; +import org.hibernate.graph.spi.GraphParserEntityClassResolver; +import org.hibernate.graph.spi.GraphParserEntityNameResolver; import org.hibernate.graph.spi.GraphImplementor; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.graph.spi.SubGraphImplementor; import org.hibernate.metamodel.model.domain.EntityDomainType; -import java.util.function.Function; - import static org.hibernate.internal.util.StringHelper.isNotEmpty; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; @@ -36,16 +37,16 @@ class NamedGraphCreatorJpa implements NamedGraphCreator { } @Override - public RootGraphImplementor createEntityGraph( - Function, EntityDomainType> entityDomainClassResolver, - Function> entityDomainNameResolver) { - //noinspection unchecked - final var rootEntityType = - (EntityDomainType) - entityDomainNameResolver.apply( jpaEntityName ); + public RootGraphImplementor createEntityGraph( + GraphParserEntityClassResolver entityDomainClassResolver, + GraphParserEntityNameResolver entityDomainNameResolver) { + return createGraph( (EntityDomainType) + entityDomainNameResolver.resolveEntityName( jpaEntityName ) ); + } + + private @NonNull RootGraphImplementor createGraph(EntityDomainType rootEntityType) { final var entityGraph = createRootGraph( name, rootEntityType, annotation.includeAllAttributes() ); - final var subclassSubgraphs = annotation.subclassSubgraphs(); if ( subclassSubgraphs != null ) { for ( var subclassSubgraph : subclassSubgraphs ) { @@ -59,11 +60,9 @@ public RootGraphImplementor createEntityGraph( entityGraph.addTreatedSubgraph( subgraphType.asSubclass( graphJavaType ) ) ); } } - if ( annotation.attributeNodes() != null ) { applyNamedAttributeNodes( annotation.attributeNodes(), annotation, entityGraph ); } - return entityGraph; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorParsed.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorParsed.java index a264f3521fd2..ed0ca3054e50 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorParsed.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NamedGraphCreatorParsed.java @@ -6,6 +6,7 @@ import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.hibernate.UnknownEntityTypeException; import org.hibernate.annotations.NamedEntityGraph; @@ -13,13 +14,12 @@ import org.hibernate.grammars.graph.GraphLanguageLexer; import org.hibernate.grammars.graph.GraphLanguageParser; import org.hibernate.graph.InvalidGraphException; -import org.hibernate.graph.internal.parse.EntityNameResolver; +import org.hibernate.graph.spi.GraphParserEntityClassResolver; +import org.hibernate.graph.spi.GraphParserEntityNameResolver; import org.hibernate.graph.internal.parse.GraphParsing; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.metamodel.model.domain.EntityDomainType; -import java.util.function.Function; - import static org.hibernate.internal.util.StringHelper.nullIfEmpty; /** @@ -41,43 +41,52 @@ class NamedGraphCreatorParsed implements NamedGraphCreator { } @Override - public RootGraphImplementor createEntityGraph( - Function, EntityDomainType> entityDomainClassResolver, - Function> entityDomainNameResolver) { - final GraphLanguageLexer lexer = new GraphLanguageLexer( CharStreams.fromString( annotation.graph() ) ); - final GraphLanguageParser parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); - final GraphLanguageParser.GraphContext graphContext = parser.graph(); - - final EntityNameResolver entityNameResolver = new EntityNameResolver() { - @Override - public EntityDomainType resolveEntityName(String entityName) { - //noinspection unchecked - final EntityDomainType entityDomainType = (EntityDomainType) entityDomainNameResolver.apply( entityName ); - if ( entityDomainType != null ) { - return entityDomainType; - } - throw new UnknownEntityTypeException( entityName ); - } - }; + public RootGraphImplementor createEntityGraph( + GraphParserEntityClassResolver entityDomainClassResolver, + GraphParserEntityNameResolver entityDomainNameResolver) { + final var lexer = new GraphLanguageLexer( CharStreams.fromString( annotation.graph() ) ); + final var parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); + final var graphContext = parser.graph(); + final var typeIndicator = graphContext.typeIndicator(); if ( entityType == null ) { - if ( graphContext.typeIndicator() == null ) { + if ( typeIndicator == null ) { throw new InvalidGraphException( "Expecting graph text to include an entity name : " + annotation.graph() ); } - final String jpaEntityName = graphContext.typeIndicator().TYPE_NAME().toString(); - //noinspection unchecked - final EntityDomainType entityDomainType = (EntityDomainType) entityDomainNameResolver.apply( jpaEntityName ); + final String jpaEntityName = typeIndicator.TYPE_NAME().toString(); + final var entityDomainType = entityDomainNameResolver.resolveEntityName( jpaEntityName ); final String name = this.name == null ? jpaEntityName : this.name; - return GraphParsing.parse( name, entityDomainType, graphContext.attributeList(), entityNameResolver ); + return parse( entityDomainNameResolver, name, entityDomainType, graphContext ); } else { - if ( graphContext.typeIndicator() != null ) { + if ( typeIndicator != null ) { throw new InvalidGraphException( "Expecting graph text to not include an entity name : " + annotation.graph() ); } - //noinspection unchecked - final EntityDomainType entityDomainType = (EntityDomainType) entityDomainClassResolver.apply( (Class) entityType ); + final var entityDomainType = entityDomainClassResolver.resolveEntityClass( entityType ); final String name = this.name == null ? entityDomainType.getName() : this.name; - return GraphParsing.parse( name, entityDomainType, graphContext.attributeList(), entityNameResolver ); + return parse( entityDomainNameResolver, name, entityDomainType, graphContext ); + } + } + + private static @NonNull RootGraphImplementor parse( + GraphParserEntityNameResolver entityDomainNameResolver, + String name, + EntityDomainType entityDomainType, + GraphLanguageParser.GraphContext graphContext) { + return GraphParsing.parse( name, entityDomainType, graphContext.attributeList(), + entityName -> resolve( entityName, entityDomainNameResolver ) ); + } + + private static @NonNull EntityDomainType resolve( + String entityName, GraphParserEntityNameResolver entityDomainNameResolver) { + final var entityDomainType = + (EntityDomainType) + entityDomainNameResolver.resolveEntityName( entityName ); + if ( entityDomainType == null ) { + throw new UnknownEntityTypeException( entityName ); + } + else { + return entityDomainType; } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NaturalIdBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NaturalIdBinder.java index 626c1d6d4081..98d5f8a5d6ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NaturalIdBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/NaturalIdBinder.java @@ -53,7 +53,7 @@ private static Identifier uniqueKeyName(MetadataBuildingContext context, Annotat private static void addColumnsToUniqueKey(AnnotatedColumns columns, Identifier name) { final var collector = columns.getBuildingContext().getMetadataCollector(); - final Table table = columns.getTable(); + final var table = columns.getTable(); final var uniqueKey = table.getOrCreateUniqueKey( name.render( collector.getDatabase().getDialect() ) ); final var property = columns.resolveProperty(); if ( property.isComposite() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java index 84831c176e26..a83bf40786a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java @@ -23,6 +23,8 @@ import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.EntityCopyObserverFactory; import org.hibernate.event.spi.EventEngine; +import org.hibernate.graph.GraphParser; +import org.hibernate.graph.RootGraph; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.event.service.spi.EventListenerGroups; import org.hibernate.metamodel.model.domain.JpaMetamodel; @@ -322,4 +324,18 @@ default JdbcSelectWithActionsBuilder getJdbcSelectWithActionsBuilder(){ return new JdbcSelectWithActions.Builder(); } + @Override + default RootGraph parseEntityGraph(Class rootEntityClass, CharSequence graphText) { + return GraphParser.parse( rootEntityClass, graphText.toString(), unwrap( SessionFactoryImplementor.class ) ); + } + + @Override @Incubating + default RootGraph parseEntityGraph(String rootEntityName, CharSequence graphText) { + return GraphParser.parse( rootEntityName, graphText.toString(), unwrap( SessionFactoryImplementor.class ) ); + } + + @Override @Incubating + default RootGraph parseEntityGraph(CharSequence graphText) { + return GraphParser.parse( graphText.toString(), unwrap( SessionFactoryImplementor.class ) ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/graph/GraphParser.java b/hibernate-core/src/main/java/org/hibernate/graph/GraphParser.java index 0bfcb46624ad..ae5ca1086929 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/GraphParser.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/GraphParser.java @@ -9,6 +9,7 @@ import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Subgraph; +import org.hibernate.Incubating; import org.hibernate.SessionFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; @@ -89,6 +90,7 @@ public static RootGraph parse( * * @since 7.0 */ + @Incubating public static RootGraph parse( final String rootEntityName, final CharSequence graphText, @@ -96,7 +98,8 @@ public static RootGraph parse( if ( graphText == null ) { return null; } - return GraphParsing.parse( + //noinspection unchecked + return (RootGraph) GraphParsing.parse( rootEntityName, graphText.toString(), sessionFactory.unwrap( SessionFactoryImplementor.class ) @@ -117,16 +120,18 @@ public static RootGraph parse( * * @since 7.0 */ - public static RootGraph parse( + @Incubating + public static RootGraph parse( final CharSequence graphText, final SessionFactory sessionFactory) { if ( graphText == null ) { return null; } - return GraphParsing.parse( + //noinspection unchecked + return (RootGraph) GraphParsing.parse( graphText.toString(), sessionFactory.unwrap( SessionFactoryImplementor.class ) - ); + ); } /** @@ -153,7 +158,8 @@ public static RootGraph parse( return GraphParsing.parse( rootType, graphText.toString(), - entityManager.getEntityManagerFactory().unwrap( SessionFactoryImplementor.class ) + entityManager.getEntityManagerFactory() + .unwrap( SessionFactoryImplementor.class ) ); } @@ -190,13 +196,12 @@ public static void parseInto( * * @throws InvalidGraphException if the textual representation is invalid. */ - @SuppressWarnings("unchecked") public static void parseInto( - final EntityGraph graph, + final EntityGraph graph, final CharSequence graphText, final EntityManager entityManager) { parseInto( - (GraphImplementor) graph, + (GraphImplementor) graph, graphText, ( (SessionImplementor) entityManager ).getSessionFactory() ); @@ -211,13 +216,12 @@ public static void parseInto( * * @throws InvalidGraphException if the textual representation is invalid. */ - @SuppressWarnings("unchecked") - public static void parseInto( - final Subgraph graph, + public static void parseInto( + final Subgraph graph, final CharSequence graphText, final EntityManager entityManager) { parseInto( - (GraphImplementor) graph, + (GraphImplementor) graph, graphText, ( (SessionImplementor) entityManager ).getSessionFactory() ); @@ -232,12 +236,12 @@ public static void parseInto( * * @throws InvalidGraphException if the textual representation is invalid. */ - public static void parseInto( - final Graph graph, + public static void parseInto( + final Graph graph, final CharSequence graphText, final EntityManagerFactory entityManagerFactory) { parseInto( - (GraphImplementor) graph, + (GraphImplementor) graph, graphText, (SessionFactoryImplementor) entityManagerFactory ); @@ -252,13 +256,12 @@ public static void parseInto( * * @throws InvalidGraphException if the textual representation is invalid. */ - @SuppressWarnings("unchecked") - public static void parseInto( - final EntityGraph graph, + public static void parseInto( + final EntityGraph graph, final CharSequence graphText, final EntityManagerFactory entityManagerFactory) { parseInto( - (GraphImplementor) graph, + (GraphImplementor) graph, graphText, (SessionFactoryImplementor) entityManagerFactory ); @@ -273,13 +276,12 @@ public static void parseInto( * * @throws InvalidGraphException if the textual representation is invalid. */ - @SuppressWarnings("unchecked") - public static void parseInto( - final Subgraph graph, + public static void parseInto( + final Subgraph graph, final CharSequence graphText, final EntityManagerFactory entityManagerFactory) { parseInto( - (GraphImplementor) graph, + (GraphImplementor) graph, graphText, (SessionFactoryImplementor) entityManagerFactory ); @@ -289,8 +291,6 @@ public static void parseInto( * Parses the textual graph representation as {@linkplain GraphParser described above} * into the specified graph. * - * @param The Java type for the ManagedType described by `graph` - * * @param graph The target graph. This is the graph that will be populated * by this process * @param graphText Textual representation of the graph @@ -298,8 +298,8 @@ public static void parseInto( * * @throws InvalidGraphException if the textual representation is invalid. */ - private static void parseInto( - GraphImplementor graph, + private static void parseInto( + GraphImplementor graph, final CharSequence graphText, SessionFactoryImplementor sessionFactory) { if ( graphText != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java index 6856698ea440..dd25ee52bc47 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java @@ -258,13 +258,13 @@ public SubGraphImplementor makeSubGraph() { @Override @Deprecated public SubGraphImplementor makeSubGraph(Class subtype) { - final ManagedDomainType managedType = asManagedType( valueGraphType ); + final var managedType = asManagedType( valueGraphType ); if ( !managedType.getJavaType().isAssignableFrom( subtype ) ) { throw new IllegalArgumentException( "Not a subtype: " + subtype.getName() ); } @SuppressWarnings("unchecked") - final Class castSuptype = (Class) subtype; - final SubGraphImplementor result = makeSubGraph().addTreatedSubgraph( castSuptype ); + final var castSuptype = (Class) subtype; + final var result = makeSubGraph().addTreatedSubgraph( castSuptype ); //noinspection unchecked return (SubGraphImplementor) result; } @@ -282,13 +282,13 @@ public SubGraphImplementor makeKeySubGraph() { @Override @Deprecated public SubGraphImplementor makeKeySubGraph(Class subtype) { checkMap(); - final ManagedDomainType type = asManagedType( keyGraphType ); + final var type = asManagedType( keyGraphType ); if ( !type.getJavaType().isAssignableFrom( subtype ) ) { throw new IllegalArgumentException( "Not a key subtype: " + subtype.getName() ); } @SuppressWarnings("unchecked") - final Class castType = (Class) subtype; - final SubGraphImplementor result = makeKeySubGraph().addTreatedSubgraph( castType ); + final var castType = (Class) subtype; + final var result = makeKeySubGraph().addTreatedSubgraph( castType ); //noinspection unchecked return (SubGraphImplementor) result; } @@ -323,7 +323,7 @@ public String toString() { public void merge(AttributeNodeImplementor that) { assert that.isMutable() == isMutable(); assert that.getAttributeDescriptor() == attribute; - final SubGraphImplementor otherValueSubgraph = that.getValueSubgraph(); + final var otherValueSubgraph = that.getValueSubgraph(); if ( otherValueSubgraph != null ) { if ( valueSubgraph == null ) { valueSubgraph = otherValueSubgraph.makeCopy( isMutable() ); @@ -333,7 +333,7 @@ public void merge(AttributeNodeImplementor that) { valueSubgraph.mergeInternal( otherValueSubgraph ); } } - final SubGraphImplementor otherKeySubgraph = that.getKeySubgraph(); + final var otherKeySubgraph = that.getKeySubgraph(); if ( otherKeySubgraph != null ) { if ( keySubgraph == null ) { keySubgraph = otherKeySubgraph.makeCopy( isMutable() ); @@ -351,7 +351,8 @@ public Map, SubGraphImplementor> getSubGraphs() { return emptyMap(); } else { - final HashMap, SubGraphImplementor> map = new HashMap<>( valueSubgraph.getTreatedSubgraphs() ); + final HashMap, SubGraphImplementor> map = + new HashMap<>( valueSubgraph.getTreatedSubgraphs() ); map.put( attribute.getValueGraphType().getJavaType(), valueSubgraph ); return map; } @@ -363,7 +364,8 @@ public Map, SubGraphImplementor> getKeySubGraphs() { return emptyMap(); } else { - final HashMap, SubGraphImplementor> map = new HashMap<>( keySubgraph.getTreatedSubgraphs() ); + final HashMap, SubGraphImplementor> map = + new HashMap<>( keySubgraph.getTreatedSubgraphs() ); map.put( attribute.getKeyGraphType().getJavaType(), keySubgraph ); return map; } diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/GraphImpl.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/GraphImpl.java index b28471f203f8..0a78778d88e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/GraphImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/GraphImpl.java @@ -156,19 +156,19 @@ public void mergeInternal(GraphImplementor graph) { } private void mergeNode(PersistentAttribute attribute, AttributeNodeImplementor node) { - final AttributeNodeImplementor existingNode = getNodeForPut( attribute ); + final var existingNode = getNodeForPut( attribute ); if ( existingNode == null ) { attributeNodes.put( attribute, node.makeCopy( isMutable() ) ); } else { - // keep the local one, but merge in the incoming one + // keep the local one but merge in the incoming one mergeNode( node, existingNode ); } } private void mergeGraph(SubGraphImplementor subgraph) { - final Class javaType = subgraph.getClassType(); - final SubGraphImplementor existing = getTreatedSubgraphForPut( javaType ); + final var javaType = subgraph.getClassType(); + final var existing = getTreatedSubgraphForPut( javaType ); if ( existing == null ) { treatedSubgraphs.put( javaType, subgraph.makeCopy( isMutable() ) ); } @@ -197,12 +197,12 @@ public List> getAttributeNodeList() { @Override public AttributeNodeImplementor findAttributeNode(String attributeName) { - final PersistentAttribute attribute = findAttributeInSupertypes( attributeName ); + final var attribute = findAttributeInSupertypes( attributeName ); @SuppressWarnings("unchecked") // The JPA API is unsafe by nature - final PersistentAttribute persistentAttribute = (PersistentAttribute) attribute; - final AttributeNodeImplementor node = attribute == null ? null : findAttributeNode( persistentAttribute ); + final var persistentAttribute = (PersistentAttribute) attribute; + final var node = attribute == null ? null : findAttributeNode( persistentAttribute ); if ( node == null && treatedSubgraphs != null ) { - for ( SubGraphImplementor subgraph : treatedSubgraphs.values() ) { + for ( var subgraph : treatedSubgraphs.values() ) { final AttributeNodeImplementor subgraphNode = subgraph.findAttributeNode( attributeName ); if ( subgraphNode != null ) { return subgraphNode; @@ -264,7 +264,7 @@ public void addAttributeNodes(String... attributeNames) { @Override @SafeVarargs public final void addAttributeNodes(Attribute... attributes) { - for ( Attribute attribute : attributes ) { + for ( var attribute : attributes ) { addAttributeNode( attribute ); } } @@ -290,9 +290,9 @@ public void removeAttributeNodes(Attribute.PersistentAttributeType nodeType) { @Override public AttributeNodeImplementor findOrCreateAttributeNode(PersistentAttribute attribute) { verifyMutability(); - final AttributeNodeImplementor node = getNodeForPut( attribute ); + final var node = getNodeForPut( attribute ); if ( node == null ) { - final AttributeNodeImplementor newAttrNode = AttributeNodeImpl.create( attribute, isMutable() ); + final var newAttrNode = AttributeNodeImpl.create( attribute, isMutable() ); attributeNodes.put( attribute, newAttrNode ); return newAttrNode; } @@ -303,9 +303,9 @@ public AttributeNodeImplementor findOrCreateAttributeNode(Persisten private AttributeNodeImplementor findOrCreateAttributeNode(PluralPersistentAttribute attribute) { verifyMutability(); - final AttributeNodeImplementor node = getNodeForPut( attribute ); + final var node = getNodeForPut( attribute ); if ( node == null ) { - final AttributeNodeImplementor newAttrNode = AttributeNodeImpl.create( attribute, isMutable() ); + final var newAttrNode = AttributeNodeImpl.create( attribute, isMutable() ); attributeNodes.put( attribute, newAttrNode ); return newAttrNode; } @@ -316,9 +316,9 @@ private AttributeNodeImplementor findOrCreateAttributeNode(PluralPe private AttributeNodeImplementor,V,K> findOrCreateAttributeNode(MapPersistentAttribute attribute) { verifyMutability(); - final AttributeNodeImplementor,V,K> node = getNodeForPut( attribute ); + final var node = getNodeForPut( attribute ); if ( node == null ) { - final AttributeNodeImplementor,V,K> newAttrNode = AttributeNodeImpl.create( attribute, isMutable() ); + final var newAttrNode = AttributeNodeImpl.create( attribute, isMutable() ); attributeNodes.put( attribute, newAttrNode ); return newAttrNode; } @@ -329,21 +329,21 @@ private AttributeNodeImplementor,V,K> findOrCreateAttributeNode(M @Override public AttributeNodeImplementor findOrCreateAttributeNode(String attributeName) { - final PersistentAttribute attribute = getAttribute( attributeName ); + final var attribute = getAttribute( attributeName ); @SuppressWarnings("unchecked") // The JPA API is unsafe by nature - final PersistentAttribute persistentAttribute = (PersistentAttribute) attribute; + final var persistentAttribute = (PersistentAttribute) attribute; return findOrCreateAttributeNode( persistentAttribute ); } private PersistentAttribute findAttributeInSupertypes(String attributeName) { - final PersistentAttribute attribute = managedType.findAttributeInSuperTypes( attributeName ); + final var attribute = managedType.findAttributeInSuperTypes( attributeName ); return attribute instanceof SqmPathSource sqmPathSource && sqmPathSource.isGeneric() ? managedType.findConcreteGenericAttribute( attributeName ) : attribute; } private PersistentAttribute getAttribute(String attributeName) { - final PersistentAttribute attribute = managedType.getAttribute( attributeName ); + final var attribute = managedType.getAttribute( attributeName ); return attribute instanceof SqmPathSource sqmPathSource && sqmPathSource.isGeneric() ? managedType.findConcreteGenericAttribute( attributeName ) : attribute; @@ -470,10 +470,10 @@ public SubGraphImplementor addTreatedSubgraph(ManagedType ty return (SubGraphImplementor) this; } else { - final Class javaType = type.getJavaType(); - final SubGraphImplementor castSubgraph = getTreatedSubgraphForPut( javaType ); + final var javaType = type.getJavaType(); + final var castSubgraph = getTreatedSubgraphForPut( javaType ); if ( castSubgraph == null ) { - final SubGraphImpl subgraph = new SubGraphImpl<>( (ManagedDomainType) type, true ); + final var subgraph = new SubGraphImpl<>( (ManagedDomainType) type, true ); treatedSubgraphs.put( javaType, subgraph ); return subgraph; } @@ -495,7 +495,7 @@ public Map, SubGraphImplementor> getTreatedSubgr @Override public String toString() { - final StringBuilder builder = new StringBuilder( "Graph[" ).append( managedType.getTypeName() ); + final var builder = new StringBuilder( "Graph[" ).append( managedType.getTypeName() ); if ( attributeNodes != null ) { builder.append( ", nodes=" ) .append( attributeNodes.values().stream() diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/EntityNameResolverSessionFactory.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/EntityNameResolverSessionFactory.java deleted file mode 100644 index 88f601c9d6d0..000000000000 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/EntityNameResolverSessionFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.graph.internal.parse; - -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.model.domain.EntityDomainType; - -/** - * @author Steve Ebersole - */ -public class EntityNameResolverSessionFactory implements EntityNameResolver { - private final SessionFactoryImplementor sessionFactory; - - public EntityNameResolverSessionFactory(SessionFactoryImplementor sessionFactory) { - this.sessionFactory = sessionFactory; - } - - @Override - public EntityDomainType resolveEntityName(String entityName) { - //noinspection unchecked - return (EntityDomainType) sessionFactory.getJpaMetamodel().findEntityType( entityName ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java index e02e5f06ee03..1377b8678ac1 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java @@ -10,6 +10,7 @@ import org.hibernate.graph.GraphNode; import org.hibernate.graph.InvalidGraphException; import org.hibernate.graph.spi.AttributeNodeImplementor; +import org.hibernate.graph.spi.GraphParserEntityNameResolver; import org.hibernate.graph.spi.GraphImplementor; import org.hibernate.graph.spi.SubGraphImplementor; import org.hibernate.internal.util.StringHelper; @@ -24,13 +25,13 @@ * @author Steve Ebersole */ public class GraphParser extends GraphLanguageParserBaseVisitor> { - private final EntityNameResolver entityNameResolver; + private final GraphParserEntityNameResolver entityNameResolver; private final Stack> graphStack = new StandardStack<>(); private final Stack> attributeNodeStack = new StandardStack<>(); private final Stack graphSourceStack = new StandardStack<>(); - public GraphParser(EntityNameResolver entityNameResolver) { + public GraphParser(GraphParserEntityNameResolver entityNameResolver) { this.entityNameResolver = entityNameResolver; } @@ -38,10 +39,10 @@ public GraphParser(EntityNameResolver entityNameResolver) { * @apiNote It is important that this form only be used after the session-factory is fully * initialized, especially the {@linkplain SessionFactoryImplementor#getJpaMetamodel()} JPA metamodel}. * - * @see GraphParser#GraphParser(EntityNameResolver) + * @see GraphParser#GraphParser(GraphParserEntityNameResolver) */ public GraphParser(SessionFactoryImplementor sessionFactory) { - this( new EntityNameResolverSessionFactory( sessionFactory ) ); + this( sessionFactory.getJpaMetamodel()::findEntityType ); } public Stack> getGraphStack() { @@ -81,7 +82,7 @@ public AttributeNodeImplementor visitAttributeNode(GraphLanguageParser.At subGraphCreator = pathQualifierType.getSubGraphCreator(); } - final AttributeNodeImplementor attributeNode = resolveAttributeNode( attributeName ); + final var attributeNode = resolveAttributeNode( attributeName ); if ( attributeNodeContext.subGraph() != null ) { attributeNodeStack.push( attributeNode ); @@ -109,10 +110,10 @@ public AttributeNodeImplementor visitAttributeNode(GraphLanguageParser.At } private AttributeNodeImplementor resolveAttributeNode(String attributeName) { - final GraphImplementor currentGraph = graphStack.getCurrent(); + final var currentGraph = graphStack.getCurrent(); assert currentGraph != null; - final AttributeNodeImplementor attributeNode = currentGraph.findOrCreateAttributeNode( attributeName ); + final var attributeNode = currentGraph.findOrCreateAttributeNode( attributeName ); assert attributeNode != null; return attributeNode; @@ -132,7 +133,9 @@ private PathQualifierType resolvePathQualifier(String qualifier) { @Override public SubGraphImplementor visitSubGraph(GraphLanguageParser.SubGraphContext subGraphContext) { - final String subTypeName = subGraphContext.typeIndicator() == null ? null : subGraphContext.typeIndicator().TYPE_NAME().getText(); + final String subTypeName = + subGraphContext.typeIndicator() == null ? null + : subGraphContext.typeIndicator().TYPE_NAME().getText(); if ( PARSING_LOGGER.isTraceEnabled() ) { PARSING_LOGGER.tracef( @@ -142,8 +145,8 @@ public SubGraphImplementor visitSubGraph(GraphLanguageParser.SubGraphContext ); } - final AttributeNodeImplementor attributeNode = attributeNodeStack.getCurrent(); - final SubGraphGenerator subGraphCreator = graphSourceStack.getCurrent(); + final var attributeNode = attributeNodeStack.getCurrent(); + final var subGraphCreator = graphSourceStack.getCurrent(); final SubGraphImplementor subGraph = subGraphCreator.createSubGraph( attributeNode, diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParsing.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParsing.java index 2c8be74ef601..332ce3885fef 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParsing.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParsing.java @@ -6,12 +6,15 @@ import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.grammars.graph.GraphLanguageLexer; import org.hibernate.grammars.graph.GraphLanguageParser; +import org.hibernate.grammars.graph.GraphLanguageParser.GraphContext; import org.hibernate.graph.InvalidGraphException; import org.hibernate.graph.internal.RootGraphImpl; +import org.hibernate.graph.spi.GraphParserEntityNameResolver; import org.hibernate.graph.spi.GraphImplementor; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.metamodel.model.domain.EntityDomainType; @@ -22,91 +25,55 @@ * @author Steve Ebersole */ public class GraphParsing { + public static RootGraphImplementor parse( - Class entityClass, + EntityDomainType entityDomainType, String graphText, SessionFactoryImplementor sessionFactory) { if ( graphText == null ) { return null; } - final GraphLanguageLexer lexer = new GraphLanguageLexer( CharStreams.fromString( graphText ) ); - final GraphLanguageParser parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); - final GraphLanguageParser.GraphContext graphContext = parser.graph(); - + final var graphContext = parseText( graphText ); if ( graphContext.typeIndicator() != null ) { // todo : an alternative here would be to simply validate that the entity type // from the text matches the passed one... - throw new InvalidGraphException( "Expecting graph text to not include an entity name : " + graphText ); + throw new InvalidGraphException( "Expecting graph text to not include an entity name: " + graphText ); } - final EntityDomainType entityType = sessionFactory.getJpaMetamodel().entity( entityClass ); - return parse( entityType, graphContext.attributeList(), sessionFactory ); + return parse( entityDomainType, graphContext.attributeList(), sessionFactory ); } public static RootGraphImplementor parse( - EntityDomainType entityDomainType, + Class entityClass, String graphText, SessionFactoryImplementor sessionFactory) { - if ( graphText == null ) { - return null; - } - - final GraphLanguageLexer lexer = new GraphLanguageLexer( CharStreams.fromString( graphText ) ); - final GraphLanguageParser parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); - final GraphLanguageParser.GraphContext graphContext = parser.graph(); - - if ( graphContext.typeIndicator() != null ) { - // todo : an alternative here would be to simply validate that the entity type - // from the text matches the passed one... - throw new InvalidGraphException( "Expecting graph text to not include an entity name : " + graphText ); - } - - return parse( entityDomainType, graphContext.attributeList(), sessionFactory ); + return parse( sessionFactory.getJpaMetamodel().entity( entityClass ), + graphText, sessionFactory ); } - public static RootGraphImplementor parse( + public static RootGraphImplementor parse( String entityName, String graphText, SessionFactoryImplementor sessionFactory) { - if ( graphText == null ) { - return null; - } - - final GraphLanguageLexer lexer = new GraphLanguageLexer( CharStreams.fromString( graphText ) ); - final GraphLanguageParser parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); - final GraphLanguageParser.GraphContext graphContext = parser.graph(); - - if ( graphContext.typeIndicator() != null ) { - // todo : an alternative here would be to simply validate that the entity type - // from the text matches the passed one... - throw new InvalidGraphException( "Expecting graph text to not include an entity name : " + graphText ); - } - - //noinspection unchecked - final EntityDomainType entityType = (EntityDomainType) sessionFactory.getJpaMetamodel().entity( entityName ); - return parse( entityType, graphContext.attributeList(), sessionFactory ); + return parse( sessionFactory.getJpaMetamodel().entity( entityName ), + graphText, sessionFactory ); } - public static RootGraphImplementor parse( + public static RootGraphImplementor parse( String graphText, SessionFactoryImplementor sessionFactory) { if ( graphText == null ) { return null; } - final GraphLanguageLexer lexer = new GraphLanguageLexer( CharStreams.fromString( graphText ) ); - final GraphLanguageParser parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); - final GraphLanguageParser.GraphContext graphContext = parser.graph(); - + final var graphContext = parseText( graphText ); if ( graphContext.typeIndicator() == null ) { - throw new InvalidGraphException( "Expecting graph text to include an entity name : " + graphText ); + throw new InvalidGraphException( "Expecting graph text to include an entity name: " + graphText ); } final String entityName = graphContext.typeIndicator().TYPE_NAME().getText(); - - //noinspection unchecked - final EntityDomainType entityType = (EntityDomainType) sessionFactory.getJpaMetamodel().entity( entityName ); + final var entityType = sessionFactory.getJpaMetamodel().entity( entityName ); return parse( entityType, graphContext.attributeList(), sessionFactory ); } @@ -114,34 +81,29 @@ public static RootGraphImplementor parse( EntityDomainType rootType, GraphLanguageParser.AttributeListContext attributeListContext, SessionFactoryImplementor sessionFactory) { - return parse( rootType, attributeListContext, new EntityNameResolverSessionFactory( sessionFactory ) ); + return parse( rootType, attributeListContext, sessionFactory.getJpaMetamodel()::findEntityType ); } public static RootGraphImplementor parse( EntityDomainType rootType, GraphLanguageParser.AttributeListContext attributeListContext, - EntityNameResolver entityNameResolver) { + GraphParserEntityNameResolver entityNameResolver) { return parse( null, rootType, attributeListContext, entityNameResolver ); } + private static @NonNull GraphContext parseText(String graphText) { + final var lexer = new GraphLanguageLexer( CharStreams.fromString( graphText ) ); + final var parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); + return parser.graph(); + } + public static RootGraphImplementor parse( @Nullable String name, EntityDomainType rootType, GraphLanguageParser.AttributeListContext attributeListContext, - EntityNameResolver entityNameResolver) { + GraphParserEntityNameResolver entityNameResolver) { final RootGraphImpl targetGraph = new RootGraphImpl<>( name, rootType ); - - final GraphParser visitor = new GraphParser( entityNameResolver ); - visitor.getGraphStack().push( targetGraph ); - try { - visitor.visitAttributeList( attributeListContext ); - } - finally { - visitor.getGraphStack().pop(); - - assert visitor.getGraphStack().isEmpty(); - } - + visitGraph( targetGraph, entityNameResolver, attributeListContext ); return targetGraph; } @@ -153,25 +115,28 @@ public static void parseInto( GraphImplementor targetGraph, CharSequence graphString, SessionFactoryImplementor sessionFactory) { - final GraphLanguageLexer lexer = new GraphLanguageLexer( CharStreams.fromString( graphString.toString() ) ); - final GraphLanguageParser parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); - final GraphLanguageParser.GraphContext graphContext = parser.graph(); - + final var graphContext = parseText( graphString.toString() ); if ( graphContext.typeIndicator() != null ) { // todo : throw an exception? Log warning? Ignore? // for now, ignore } + visitGraph( targetGraph, + sessionFactory.getJpaMetamodel()::findEntityType, + graphContext.attributeList() ); + } + private static void visitGraph( + GraphImplementor targetGraph, + GraphParserEntityNameResolver entityNameResolver, + GraphLanguageParser.AttributeListContext attributeList) { // Build an instance of this class as a visitor - final GraphParser visitor = new GraphParser( sessionFactory ); - + final var visitor = new GraphParser( entityNameResolver ); visitor.getGraphStack().push( targetGraph ); try { - visitor.visitAttributeList( graphContext.attributeList() ); + visitor.visitAttributeList( attributeList ); } finally { visitor.getGraphStack().pop(); - assert visitor.getGraphStack().isEmpty(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/PathQualifierType.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/PathQualifierType.java index 3687da5df37f..f9973dcf3e49 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/PathQualifierType.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/PathQualifierType.java @@ -5,7 +5,7 @@ package org.hibernate.graph.internal.parse; -import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.graph.spi.GraphParserEntityNameResolver; import org.hibernate.metamodel.model.domain.ManagedDomainType; /** @@ -23,12 +23,13 @@ public enum PathQualifierType { : attributeNode.addValueSubgraph().addTreatedSubgraph( managedType( subtypeName, entityNameResolver ) ) ); - private static ManagedDomainType managedType(String subtypeName, EntityNameResolver entityNameResolver) { - final EntityDomainType entityDomainType = entityNameResolver.resolveEntityName( subtypeName ); + private static ManagedDomainType managedType(String subtypeName, GraphParserEntityNameResolver resolver) { + final var entityDomainType = resolver.resolveEntityName( subtypeName ); if ( entityDomainType == null ) { throw new IllegalArgumentException( "Unknown managed type: " + subtypeName ); } - return entityDomainType; + //noinspection unchecked + return (ManagedDomainType) entityDomainType; } private final SubGraphGenerator subGraphCreator; diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/SubGraphGenerator.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/SubGraphGenerator.java index f575b2b9a624..295c33d93f64 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/SubGraphGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/SubGraphGenerator.java @@ -5,6 +5,7 @@ package org.hibernate.graph.internal.parse; import org.hibernate.graph.spi.AttributeNodeImplementor; +import org.hibernate.graph.spi.GraphParserEntityNameResolver; import org.hibernate.graph.spi.SubGraphImplementor; /** @@ -15,5 +16,5 @@ public interface SubGraphGenerator { SubGraphImplementor createSubGraph( AttributeNodeImplementor attributeNode, String subTypeName, - EntityNameResolver entityNameResolver); + GraphParserEntityNameResolver entityNameResolver); } diff --git a/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphParserEntityClassResolver.java b/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphParserEntityClassResolver.java new file mode 100644 index 000000000000..7210cddaae5f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphParserEntityClassResolver.java @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.graph.spi; + +import org.hibernate.Incubating; +import org.hibernate.metamodel.model.domain.EntityDomainType; + +/** + * @author Gavin King + * + * @since 7.2 + */ +@Incubating +@FunctionalInterface +public interface GraphParserEntityClassResolver { + EntityDomainType resolveEntityClass(Class entityClass); +} diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/EntityNameResolver.java b/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphParserEntityNameResolver.java similarity index 51% rename from hibernate-core/src/main/java/org/hibernate/graph/internal/parse/EntityNameResolver.java rename to hibernate-core/src/main/java/org/hibernate/graph/spi/GraphParserEntityNameResolver.java index 10073e2468b4..3734bd8b4086 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/EntityNameResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphParserEntityNameResolver.java @@ -2,14 +2,18 @@ * SPDX-License-Identifier: Apache-2.0 * Copyright Red Hat Inc. and Hibernate Authors */ -package org.hibernate.graph.internal.parse; +package org.hibernate.graph.spi; +import org.hibernate.Incubating; import org.hibernate.metamodel.model.domain.EntityDomainType; /** * @author Steve Ebersole + * + * @since 7.2 */ +@Incubating @FunctionalInterface -public interface EntityNameResolver { - EntityDomainType resolveEntityName(String entityName); +public interface GraphParserEntityNameResolver { + EntityDomainType resolveEntityName(String entityName); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java index f9c319934dd6..25554e1a5d4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java @@ -126,8 +126,9 @@ public RepresentationMode getRepresentationMode() { @Override public void visitAttributes(Consumer> action) { visitDeclaredAttributes( action ); - if ( getSuperType() != null ) { - getSuperType().visitAttributes( action ); + final var superType = getSuperType(); + if ( superType != null ) { + superType.visitAttributes( action ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java index 8fcf2003a79a..4c085a9b4546 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java @@ -125,8 +125,9 @@ public SimpleDomainType getKeyGraphType() { @Override public boolean isAssociation() { - return getPersistentAttributeType() == PersistentAttributeType.ONE_TO_MANY - || getPersistentAttributeType() == PersistentAttributeType.MANY_TO_MANY; + final var persistentAttributeType = getPersistentAttributeType(); + return persistentAttributeType == PersistentAttributeType.ONE_TO_MANY + || persistentAttributeType == PersistentAttributeType.MANY_TO_MANY; } @Override @@ -147,8 +148,8 @@ public Class getBindableJavaType() { @SuppressWarnings("unchecked") @Override public SqmPath createSqmPath(SqmPath lhs, @Nullable SqmPathSource intermediatePathSource) { - // We need an unchecked cast here : PluralPersistentAttribute implements path source with its element type - // but resolving paths from it must produce collection-typed expressions. + // We need an unchecked cast here: PluralPersistentAttribute implements PathSource with + // its element type, but resolving paths from it must produce collection-typed expressions. return (SqmPath) new SqmPluralValuedSimplePath<>( PathHelper.append( lhs, this, intermediatePathSource ), this, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyDiscriminatorSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyDiscriminatorSqmPathSource.java index a49b01080e81..64ea52e4f7d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyDiscriminatorSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyDiscriminatorSqmPathSource.java @@ -12,7 +12,6 @@ import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.domain.SqmDomainType; import org.hibernate.query.sqm.tree.domain.SqmPath; -import org.hibernate.spi.NavigablePath; import org.hibernate.type.BasicType; import org.hibernate.type.descriptor.java.JavaType; @@ -38,10 +37,11 @@ public AnyDiscriminatorSqmPathSource( @Override public SqmPath createSqmPath(SqmPath lhs, @Nullable SqmPathSource intermediatePathSource) { - final NavigablePath navigablePath = + final var path = lhs.getNavigablePath(); + final var navigablePath = intermediatePathSource == null - ? lhs.getNavigablePath() - : lhs.getNavigablePath().append( intermediatePathSource.getPathName() ); + ? path + : path.append( intermediatePathSource.getPathName() ); return new AnyDiscriminatorSqmPath<>( navigablePath, pathModel, lhs, lhs.nodeBuilder() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingDomainTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingDomainTypeImpl.java index 81e7b9977877..1145ed937e8a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingDomainTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingDomainTypeImpl.java @@ -6,7 +6,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.hibernate.mapping.Any; -import org.hibernate.mapping.Column; import org.hibernate.metamodel.model.domain.AnyMappingDomainType; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.metamodel.model.domain.SimpleDomainType; @@ -18,8 +17,6 @@ import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.internal.ConvertedBasicTypeImpl; -import java.util.List; - import static jakarta.persistence.metamodel.Type.PersistenceType.ENTITY; import static org.hibernate.metamodel.mapping.internal.AnyDiscriminatorPart.determineDiscriminatorConverter; @@ -40,10 +37,9 @@ public AnyMappingDomainTypeImpl( this.anyType = anyType; this.baseJtd = baseJtd; - final MetaType discriminatorType = (MetaType) anyType.getDiscriminatorType(); - final BasicType discriminatorBaseType = (BasicType) discriminatorType.getBaseType(); - final NavigableRole navigableRole = resolveNavigableRole( bootAnyMapping ); - + final var discriminatorType = (MetaType) anyType.getDiscriminatorType(); + final var discriminatorBaseType = (BasicType) discriminatorType.getBaseType(); + final var navigableRole = resolveNavigableRole( bootAnyMapping ); anyDiscriminatorType = new ConvertedBasicTypeImpl( navigableRole.getFullPath(), discriminatorBaseType.getJdbcType(), @@ -73,13 +69,14 @@ public String getTypeName() { } private NavigableRole resolveNavigableRole(Any bootAnyMapping) { - final StringBuilder buffer = new StringBuilder(); - if ( bootAnyMapping.getTable() != null ) { - buffer.append( bootAnyMapping.getTable().getName() ); + final var buffer = new StringBuilder(); + final var table = bootAnyMapping.getTable(); + if ( table != null ) { + buffer.append( table.getName() ); } buffer.append( "(" ); - final List columns = bootAnyMapping.getColumns(); + final var columns = bootAnyMapping.getColumns(); for ( int i = 0; i < columns.size(); i++ ) { buffer.append( columns.get( i ).getName() ); if ( i+1 < columns.size() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ArrayTupleType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ArrayTupleType.java index f25f1eb7e394..c06524882631 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ArrayTupleType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ArrayTupleType.java @@ -53,7 +53,7 @@ public String getTypeName() { } private static JavaType[] getTypeDescriptors(SqmExpressible[] components) { - final JavaType[] typeDescriptors = new JavaType[components.length]; + final var typeDescriptors = new JavaType[components.length]; for ( int i = 0; i < components.length; i++ ) { typeDescriptors[i] = components[i].getExpressibleJavaType(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java index cd699971ba16..6b909090f748 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java @@ -48,8 +48,8 @@ public String getTypeName() { @Override public @Nullable SqmPathSource findSubPathSource(String name) { - String path = pathModel.getPathName(); - String pathDesc = path == null || path.startsWith( "{" ) ? " " : " '" + pathModel.getPathName() + "' "; + final String path = pathModel.getPathName(); + final String pathDesc = path == null || path.startsWith( "{" ) ? " " : " '" + pathModel.getPathName() + "' "; throw new TerminalPathException( "Terminal path" + pathDesc + "has no attribute '" + name + "'" ); } @@ -85,8 +85,8 @@ public boolean isGeneric() { @Override public String toString() { - return "BasicSqmPathSource(" + - getPathName() + " : " + getJavaType().getSimpleName() + - ")"; + return "BasicSqmPathSource(" + + getPathName() + " : " + getJavaType().getSimpleName() + + ")"; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddableTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddableTypeImpl.java index 223e6ee38cc1..d308d62873c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddableTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddableTypeImpl.java @@ -34,6 +34,7 @@ public class EmbeddableTypeImpl extends AbstractManagedType implements SqmEmbeddableDomainType, Serializable { + @SuppressWarnings("FieldCanBeLocal") private final boolean isDynamic; private final EmbeddedDiscriminatorSqmPathSource discriminatorPathSource; private final List> subtypes = new ArrayList<>(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityDiscriminatorSqmPath.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityDiscriminatorSqmPath.java index 4abc6181c474..093b7d59238e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityDiscriminatorSqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityDiscriminatorSqmPath.java @@ -80,6 +80,7 @@ public EntityDiscriminatorSqmPath copy(SqmCopyContext context) { public X accept(SemanticQueryWalker walker) { return entityDescriptor.hasSubclasses() ? walker.visitDiscriminatorPath( this ) - : walker.visitEntityTypeLiteralExpression( new SqmLiteralEntityType( entityDomainType, nodeBuilder() ) ); + : walker.visitEntityTypeLiteralExpression( + new SqmLiteralEntityType( entityDomainType, nodeBuilder() ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityPersisterConcurrentMap.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityPersisterConcurrentMap.java index db13d7b2e468..85526604475c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityPersisterConcurrentMap.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityPersisterConcurrentMap.java @@ -7,10 +7,11 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import org.hibernate.persister.entity.EntityPersister; +import static java.util.stream.Collectors.toUnmodifiableMap; + /** * Concurrent Map implementation of mappings entity name -> EntityPersister. * Concurrency is optimised for read operations; write operations will @@ -26,10 +27,7 @@ public final class EntityPersisterConcurrentMap { public EntityPersister get(final String name) { final var entityPersisterHolder = map.get( name ); - if ( entityPersisterHolder != null ) { - return entityPersisterHolder.entityPersister; - } - return null; + return entityPersisterHolder == null ? null : entityPersisterHolder.entityPersister; } public EntityPersister[] values() { @@ -55,10 +53,10 @@ public String[] keys() { } private void recomputeValues() { - //Assumption: the write lock is being held (synchronize on this) + //Assumption: the write lock is held (synchronize on this) final int size = map.size(); - final EntityPersister[] newValues = new EntityPersister[size]; - final String[] newKeys = new String[size]; + final var newValues = new EntityPersister[size]; + final var newKeys = new String[size]; int i = 0; for ( var entry : map.entrySet() ) { newValues[i] = entry.getValue().entityPersister; @@ -75,7 +73,7 @@ private void recomputeValues() { */ @Deprecated(forRemoval = true) public Map convertToMap() { - return map.entrySet().stream().collect( Collectors.toUnmodifiableMap( + return map.entrySet().stream().collect( toUnmodifiableMap( Map.Entry::getKey, e -> e.getValue().entityPersister ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java index 0fa0b6261c57..6a7a91821778 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java @@ -23,7 +23,6 @@ import org.hibernate.metamodel.model.domain.IdentifiableDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; -import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor; import org.hibernate.query.PathException; import org.hibernate.query.sqm.SqmPathSource; @@ -153,7 +152,7 @@ public SqmEntityDomainType getPathType() { @Override public @Nullable SqmPathSource findSubPathSource(String name) { - final PersistentAttribute attribute = super.findAttribute( name ); + final var attribute = super.findAttribute( name ); if ( attribute != null ) { return (SqmPathSource) attribute; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java index f0ffc1f23837..36a76ab9f4cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java @@ -355,7 +355,7 @@ public > E enumValue(EnumJavaType enumType, String enumValu @Override public JavaType getJavaConstantType(String className, String fieldName) { try { - final Field referencedField = getJavaField( className, fieldName ); + final var referencedField = getJavaField( className, fieldName ); if ( referencedField != null ) { return getTypeConfiguration().getJavaTypeRegistry() .resolveDescriptor( referencedField.getType() ); @@ -370,7 +370,7 @@ public JavaType getJavaConstantType(String className, String fieldName) { @Override public T getJavaConstant(String className, String fieldName) { try { - final Field referencedField = getJavaField( className, fieldName ); + final var referencedField = getJavaField( className, fieldName ); //noinspection unchecked return (T) referencedField.get( null ); } @@ -451,7 +451,7 @@ private ImportInfo resolveImport(final String name) { return importInfo; } else { - //then check the negative cache, to avoid bothering the classloader unnecessarily + //then check the negative cache to avoid bothering the classloader unnecessarily if ( knownInvalidnameToImportMap.containsKey( name ) ) { return null; } @@ -490,14 +490,14 @@ private void applyNamedEntityGraphs(Collection named CORE_LOGGER.tracef( "Applying named entity graph [name=%s, source=%s]", definition.name(), definition.source() ); - final RootGraphImplementor graph = definition.graphCreator().createEntityGraph( - (entityClass) -> { + final var graph = definition.graphCreator().createEntityGraph( + entityClass -> { if ( managedTypeByClass.get( entityClass ) instanceof EntityDomainType match ) { return match; } throw new IllegalArgumentException( "Cannot resolve entity class : " + entityClass.getName() ); }, - (jpaEntityName) -> { + jpaEntityName -> { for ( var entry : managedTypeByName.entrySet() ) { if ( entry.getValue() instanceof EntityDomainType possibility && jpaEntityName.equals( possibility.getName() ) ) { @@ -554,14 +554,14 @@ public EntityDomainType resolveEntityReference(Class javaType) { if ( managedType.getPersistenceType() == Type.PersistenceType.ENTITY // see if we should add EntityDomainType as one of the matching descriptors. && javaType.isAssignableFrom( managedType.getJavaType() ) ) { - // the queried type is assignable from the type of the current entity-type - // we should add it to the collecting set of matching descriptors. it should + // The queried type is assignable from the type of the current entity type. + // We should add it to the collecting set of matching descriptors. It should // be added aside from a few cases... - // if the managed-type has a super type and the java type is assignable from the super type, - // do not add the managed type as the super itself will get added and the initializers for - // entity mappings already handle loading subtypes - adding it would be redundant and lead to - // incorrect results + // If the managed type has a supertype and the java type is assignable from the super type, + // do not add the managed type as the supertype itself will get added and the initializers + // for entity mappings already handle loading subtypes - adding it would be redundant and + // lead to incorrect results final var superType = managedType.getSuperType(); if ( superType == null || superType.getPersistenceType() != Type.PersistenceType.ENTITY diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java index 13549780a83f..4f5cb67470a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java @@ -9,7 +9,6 @@ import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.mapping.EntityIdentifierMapping; import org.hibernate.metamodel.model.domain.IdentifiableDomainType; -import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.domain.SqmDomainType; @@ -89,7 +88,7 @@ public SqmMappedSuperclassDomainType getPathType() { @Override public @Nullable SqmPathSource findSubPathSource(String name) { - final PersistentAttribute attribute = findAttribute( name ); + final var attribute = findAttribute( name ); if ( attribute != null ) { return (SqmPathSource) attribute; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PathHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PathHelper.java index b9889b827173..3a30d128b970 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PathHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PathHelper.java @@ -11,8 +11,9 @@ public class PathHelper { public static NavigablePath append(SqmPath lhs, SqmPathSource rhs, @Nullable SqmPathSource intermediatePathSource) { + final var navigablePath = lhs.getNavigablePath(); return intermediatePathSource == null - ? lhs.getNavigablePath().append( rhs.getPathName() ) - : lhs.getNavigablePath().append( intermediatePathSource.getPathName() ).append( rhs.getPathName() ); + ? navigablePath.append( rhs.getPathName() ) + : navigablePath.append( intermediatePathSource.getPathName() ).append( rhs.getPathName() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java index a47add5cdde1..028144d45019 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java @@ -86,7 +86,7 @@ public static PersistentAttribute build( attributeMetadata.getMember() ); - final Class javaClass = attributeJtd.getJavaTypeClass(); + final var javaClass = attributeJtd.getJavaTypeClass(); if ( Map.class.equals( javaClass ) ) { return new MapAttributeImpl( builder ); } @@ -124,7 +124,7 @@ else if ( Collection.class.isAssignableFrom( javaClass ) ) { private static SimpleDomainType determineListIndexOrMapKeyType( PluralAttributeMetadata attributeMetadata, MetadataContext metadataContext) { - final Class javaType = attributeMetadata.getJavaType(); + final var javaType = attributeMetadata.getJavaType(); if ( Map.class.isAssignableFrom( javaType ) ) { return (SimpleDomainType) determineSimpleType( attributeMetadata.getMapKeyValueContext(), metadataContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java index 28f1f9c3565d..de34e2d38051 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java @@ -17,11 +17,9 @@ import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.query.SemanticException; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmBindableType; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.hql.spi.SqmCreationState; -import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmSingularJoin; @@ -38,6 +36,7 @@ import org.hibernate.type.descriptor.java.JavaType; import static jakarta.persistence.metamodel.Bindable.BindableType.SINGULAR_ATTRIBUTE; +import static org.hibernate.query.sqm.internal.SqmMappingModelHelper.resolveSqmPathSource; import static org.hibernate.query.sqm.spi.SqmCreationHelper.buildSubNavigablePath; import static org.hibernate.query.sqm.spi.SqmCreationHelper.determineAlias; @@ -77,7 +76,7 @@ public SingularAttributeImpl( this.isVersion = isVersion; this.isOptional = isOptional; - this.sqmPathSource = SqmMappingModelHelper.resolveSqmPathSource( + this.sqmPathSource = resolveSqmPathSource( name, this, attributeType, @@ -157,15 +156,14 @@ public SqmJoin createSqmJoin( @Nullable String alias, boolean fetched, SqmCreationState creationState) { - final NodeBuilder nodeBuilder = creationState.getCreationContext().getNodeBuilder(); + final var nodeBuilder = creationState.getCreationContext().getNodeBuilder(); if ( getType() instanceof AnyMappingDomainType ) { throw new SemanticException( "An @Any attribute cannot be join fetched" ); } else if ( sqmPathSource.getPathType() instanceof BasicPluralType ) { final SqmSetReturningFunction setReturningFunction = nodeBuilder.unnestArray( lhs.get( getName() ) ); - //noinspection unchecked - final SqmFunctionJoin join = new SqmFunctionJoin<>( + final var join = new SqmFunctionJoin<>( createNavigablePath( lhs, alias ), setReturningFunction, true, @@ -232,11 +230,11 @@ public NavigablePath createNavigablePath(SqmPath parent, @Nullable String ali "LHS cannot be null for a sub-navigable reference - " + getName() ); } - final SqmPathSource parentPathSource = parent.getResolvedModel(); - final NavigablePath parentNavigablePath = - parentPathSource instanceof PluralPersistentAttribute - ? parent.getNavigablePath().append( CollectionPart.Nature.ELEMENT.getName() ) - : parent.getNavigablePath(); + final var navigablePath = parent.getNavigablePath(); + final var parentNavigablePath = + parent.getResolvedModel() instanceof PluralPersistentAttribute + ? navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ) + : navigablePath; if ( getDeclaringType() instanceof IdentifiableDomainType declaringType && !declaringType.hasSingleIdAttribute() ) { return new EntityIdentifierNavigablePath( parentNavigablePath, null ) @@ -291,7 +289,7 @@ public boolean isOptional() { @Override public boolean isAssociation() { - final PersistentAttributeType persistentAttributeType = getPersistentAttributeType(); + final var persistentAttributeType = getPersistentAttributeType(); return persistentAttributeType == PersistentAttributeType.MANY_TO_ONE || persistentAttributeType == PersistentAttributeType.ONE_TO_ONE; }