Javadoc work

This commit is contained in:
Steve Ebersole 2022-01-16 22:02:25 -06:00
parent 6ec996f1d5
commit 37094e3e80
27 changed files with 129 additions and 120 deletions

View File

@ -482,7 +482,7 @@ public class LoaderSelectBuilder {
applyFiltering( rootQuerySpec, rootTableGroup, pluralAttributeMapping, sqlAstCreationState );
applyOrdering( rootTableGroup, pluralAttributeMapping );
}
else if ( loadable instanceof Restrictable ) {
else {
applyFiltering( rootQuerySpec, rootTableGroup, (Restrictable) loadable, sqlAstCreationState );
}
@ -888,7 +888,7 @@ public class LoaderSelectBuilder {
currentBagRole = previousBagRole;
}
if ( entityGraphTraversalState != null && traversalResult != null ) {
entityGraphTraversalState.backtrack( traversalResult.getPreviousContext() );
entityGraphTraversalState.backtrack( traversalResult );
}
}
};

View File

@ -15,7 +15,6 @@ import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
@ -493,11 +492,6 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption
return false;
}
@Override
public DomainResult<?> asResult(DomainResultCreationState creationState) {
throw new UnsupportedOperationException();
}
@Override
public DomainResultAssembler<?> createAssembler(
FetchParentAccess parentAccess,

View File

@ -5985,7 +5985,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
fetchDepth--;
}
if ( entityGraphTraversalState != null && traversalResult != null ) {
entityGraphTraversalState.backtrack( traversalResult.getPreviousContext() );
entityGraphTraversalState.backtrack( traversalResult );
}
}
}

View File

@ -58,10 +58,4 @@ public interface BiDirectionalFetch extends Fetch {
*/
NavigablePath getReferencedPath();
@Override
default DomainResult<?> asResult(DomainResultCreationState creationState) {
throw new UnsupportedOperationException(
"Entity Fetch references conversion to DomainResult not supported"
);
}
}

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.sql.results.graph;
import org.hibernate.Incubating;
/**
* Represents a result value in the domain query results. Acts as the producer for the
* {@link DomainResultAssembler} for this result as well as any {@link Initializer} instances needed
@ -19,6 +21,7 @@ package org.hibernate.sql.results.graph;
*
* @author Steve Ebersole
*/
@Incubating
public interface DomainResult<J> extends DomainResultGraphNode {
/**
* The result-variable (alias) associated with this result.

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.sql.results.graph;
import org.hibernate.Incubating;
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions;
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
import org.hibernate.type.descriptor.java.JavaType;
@ -18,6 +19,7 @@ import org.hibernate.type.descriptor.java.JavaType;
*
* @author Steve Ebersole
*/
@Incubating
public interface DomainResultAssembler<J> {
/**
* The main "assembly" contract. Assemble the result and return it.

View File

@ -8,6 +8,7 @@ package org.hibernate.sql.results.graph;
import java.util.List;
import org.hibernate.Incubating;
import org.hibernate.metamodel.mapping.AssociationKey;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.ModelPart;
@ -16,31 +17,56 @@ import org.hibernate.sql.ast.spi.SqlAliasBaseManager;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
/**
* Contains state related to building {@link DomainResult} and
* {@link Fetch} graphs
*
* @author Steve Ebersole
*/
@Incubating
public interface DomainResultCreationState {
/**
* Whether forcing the selection of the identifier is
* in effect for this creation
*/
default boolean forceIdentifierSelection(){
return true;
}
/**
* The underlying state for SQL AST creation
*/
SqlAstCreationState getSqlAstCreationState();
/**
* Access to the SQL alias helper
*/
default SqlAliasBaseManager getSqlAliasBaseManager() {
return (SqlAliasBaseManager) getSqlAstCreationState().getSqlAliasBaseGenerator();
}
default boolean registerVisitedAssociationKey(AssociationKey associationKey) {
/**
* Registers a circularity detection key
*/
default boolean registerVisitedAssociationKey(AssociationKey circularityKey) {
return false;
}
default void removeVisitedAssociationKey(AssociationKey associationKey){
/**
* Removes the registration of a circularity detection key
*/
default void removeVisitedAssociationKey(AssociationKey circularityKey){
}
default boolean isAssociationKeyVisited(AssociationKey associationKey){
/**
* Checks whether the given circularityKey is registered
*/
default boolean isAssociationKeyVisited(AssociationKey circularityKey){
return false;
}
/**
* Is this state accepting circularity detection keys?
*/
default boolean isRegisteringVisitedAssociationKeys(){
return false;
}

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.sql.results.graph;
import org.hibernate.Incubating;
import org.hibernate.query.NavigablePath;
import org.hibernate.type.descriptor.java.JavaType;
@ -16,6 +17,7 @@ import org.hibernate.type.descriptor.java.JavaType;
*
* @author Steve Ebersole
*/
@Incubating
public interface DomainResultGraphNode {
/**
* Does this node contain any non-scalar (sub-)results?

View File

@ -6,35 +6,36 @@
*/
package org.hibernate.sql.results.graph;
import org.hibernate.Incubating;
import org.hibernate.engine.FetchTiming;
import org.hibernate.graph.AttributeNode;
import org.hibernate.graph.spi.AttributeNodeImplementor;
import org.hibernate.graph.spi.GraphImplementor;
/**
* State used as part of applying entity graphs to
* Hibernate {@link DomainResult} / {@link Fetch} load graphs.
*
* @author Nathan Xu
*/
@Incubating
public interface EntityGraphTraversalState {
/**
* POJO class to store the result of applied entity graph traversal, including
* <ul>
* <li>previous entity graph node so later on {@link EntityGraphTraversalState} object can backtrack to it</li>
* <li>whether the new graph node should be eagerly loaded or not</li>
* <li>whether the new graph node fetching is joined</li>
* </ul>
* Details of a particular traversal within the entity graph
*/
class TraversalResult {
private final GraphImplementor<?> previousContext;
private final FetchTiming fetchTiming;
private final boolean joined;
private GraphImplementor previousContext;
private FetchTiming fetchTiming;
private boolean joined;
public TraversalResult(GraphImplementor previousContext, FetchTiming fetchTiming, boolean joined) {
public TraversalResult(GraphImplementor<?> previousContext, FetchTiming fetchTiming, boolean joined) {
this.previousContext = previousContext;
this.fetchTiming = fetchTiming;
this.joined = joined;
}
public GraphImplementor getPreviousContext() {
public GraphImplementor<?> getGraph() {
return previousContext;
}
@ -48,21 +49,23 @@ public interface EntityGraphTraversalState {
}
/**
* Backtrack to previous entity graph status before last travrsal.
* Traverses to the next part of the Jakarta Persistence entity graph relating to the
* given fetchable.
* <p/>
*
* The {@link AttributeNode} corresponding to the given `fetchable` is resolved.
*
* Depending on `exploreKeySubgraph`, either {@link AttributeNode#getSubGraphs()}
* or {@link AttributeNode#getKeySubGraphs()} will be used
*/
TraversalResult traverse(FetchParent parent, Fetchable fetchable, boolean exploreKeySubgraph);
/**
* Backtrack to previous entity graph status before last traversal.
* Mainly reset the current context entity graph node to the passed method parameter.
*
* @param previousContext The previous entity graph context node; should not be null
* @see #traverse(FetchParent, Fetchable, boolean)
*/
void backtrack(GraphImplementor previousContext);
/**
* Tries to traverse from parent to child node within entity graph and returns non-null {@code Result}.
*
* @param parent The FetchParent or traversal source node
* @param fetchable The Fetchable or traversal destination node
* @param exploreKeySubgraph true if only key sub graph is explored; false if key sub graph is excluded
* @return traversal result; never be null
*/
TraversalResult traverse(FetchParent parent, Fetchable fetchable, boolean exploreKeySubgraph);
void backtrack(TraversalResult previousContext);
}

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.sql.results.graph;
import org.hibernate.Incubating;
import org.hibernate.engine.FetchTiming;
import org.hibernate.query.NavigablePath;
@ -16,6 +17,7 @@ import org.hibernate.query.NavigablePath;
*
* @author Steve Ebersole
*/
@Incubating
public interface Fetch extends DomainResultGraphNode {
/**
* Get the property path to this fetch
@ -32,10 +34,6 @@ public interface Fetch extends DomainResultGraphNode {
* * inject the fetched instance into the parent and potentially inject
* the parent reference into the fetched instance if it defines
* such injection (e.g. {@link org.hibernate.annotations.Parent})
*
* todo (6.0) : remove?
* - this is never used. not sure its useful, and it creates a bi-directional link between
* Fetch#getParent and FetchParent#getFetches
*/
FetchParent getFetchParent();
@ -61,8 +59,6 @@ public interface Fetch extends DomainResultGraphNode {
return true;
}
DomainResult<?> asResult(DomainResultCreationState creationState);
/**
* Create the assembler for this fetch
*/

View File

@ -8,11 +8,11 @@ package org.hibernate.sql.results.graph;
import java.util.List;
import org.hibernate.Incubating;
import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.Association;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
import org.hibernate.query.EntityIdentifierNavigablePath;
@ -23,6 +23,7 @@ import org.hibernate.query.NavigablePath;
*
* @author Steve Ebersole
*/
@Incubating
public interface FetchParent extends DomainResultGraphNode {
/**
* This parent's mapping type
@ -34,17 +35,6 @@ public interface FetchParent extends DomainResultGraphNode {
*/
FetchableContainer getReferencedMappingType();
default FetchParent resolveContainingAssociationParent() {
final ModelPart referencedModePart = getReferencedModePart();
if ( referencedModePart instanceof Association ) {
return this;
}
if ( this instanceof Fetch ) {
( (Fetch) this ).getFetchParent().resolveContainingAssociationParent();
}
return null;
}
default NavigablePath resolveNavigablePath(Fetchable fetchable) {
final String fetchableName = fetchable.getFetchableName();
if ( NavigablePath.IDENTIFIER_MAPPER_PROPERTY.equals( fetchableName ) ) {

View File

@ -8,7 +8,6 @@ package org.hibernate.sql.results.graph;
import java.util.function.Consumer;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.query.NavigablePath;
/**

View File

@ -6,19 +6,35 @@
*/
package org.hibernate.sql.results.graph;
import org.hibernate.LockMode;
import org.hibernate.Incubating;
import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.query.NavigablePath;
/**
* Parts of the domain model that can be fetched
*
* @author Steve Ebersole
*/
@Incubating
public interface Fetchable extends ModelPart {
/**
* The name of the fetchable
*/
String getFetchableName();
/**
* The configured fetch timing and style
*/
FetchOptions getMappedFetchOptions();
/**
* Check whether this Fetchable is considered a circular fetch.
*
* @param fetchablePath The overall path within the graph
*
* @return The Fetch representing the circularity; {@code null} indicates the fetch is not circular
*/
default Fetch resolveCircularFetch(
NavigablePath fetchablePath,
FetchParent fetchParent,
@ -27,6 +43,13 @@ public interface Fetchable extends ModelPart {
return null;
}
/**
* Generates a Fetch of this fetchable
*
* @param fetchParent The parent of the Fetch we are generating
* @param fetchablePath The overall path within the graph
* @param fetchTiming The requested fetch timing
*/
Fetch generateFetch(
FetchParent fetchParent,
NavigablePath fetchablePath,
@ -35,6 +58,12 @@ public interface Fetchable extends ModelPart {
String resultVariable,
DomainResultCreationState creationState);
/**
* Should this Fetchable affect the fetch depth? E.g., composites
* would generally not increment the fetch depth.
*
* @see org.hibernate.cfg.AvailableSettings#MAX_FETCH_DEPTH
*/
default boolean incrementFetchDepth(){
return false;
}

View File

@ -12,9 +12,14 @@ import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.ModelPartContainer;
/**
* Container of {@link Fetchable} references
*
* @author Steve Ebersole
*/
public interface FetchableContainer extends ModelPartContainer {
/**
* The number of fetchables in the container
*/
int getNumberOfFetchables();
default void visitKeyFetchables(

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.sql.results.graph;
import org.hibernate.Incubating;
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.query.NavigablePath;
@ -18,6 +19,7 @@ import org.hibernate.sql.exec.spi.ExecutionContext;
*
* @author Steve Ebersole
*/
@Incubating
public interface Initializer {
NavigablePath getNavigablePath();

View File

@ -10,11 +10,9 @@ import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.results.ResultsHelper;
import org.hibernate.sql.results.graph.AssemblerCreationState;
import org.hibernate.sql.results.graph.UnfetchedBasicPartResultAssembler;
import org.hibernate.sql.results.graph.UnfetchedResultAssembler;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultAssembler;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.Fetch;
@ -24,6 +22,8 @@ import org.hibernate.sql.results.graph.Fetchable;
import org.hibernate.type.descriptor.java.JavaType;
/**
* Fetch for a basic-value
*
* @author Steve Ebersole
*/
public class BasicFetch<T> implements Fetch, BasicResultGraphNode<T> {
@ -98,18 +98,6 @@ public class BasicFetch<T> implements Fetch, BasicResultGraphNode<T> {
return fetchTiming == FetchTiming.IMMEDIATE;
}
@Override
public DomainResult<?> asResult(DomainResultCreationState creationState) {
return valuedMapping.createDomainResult(
navigablePath,
ResultsHelper.impl( creationState )
.getFromClauseAccess()
.getTableGroup( fetchParent.getNavigablePath() ),
getResultVariable(),
creationState
);
}
@Override
public FetchParent getFetchParent() {
return fetchParent;

View File

@ -16,6 +16,8 @@ import org.hibernate.sql.results.graph.FetchParentAccess;
import org.hibernate.type.descriptor.java.JavaType;
/**
* DomainResult for a basic-value
*
* @author Steve Ebersole
*/
public class BasicResult<T> implements DomainResult<T>, BasicResultGraphNode<T> {

View File

@ -9,8 +9,7 @@ package org.hibernate.sql.results.graph.basic;
import org.hibernate.sql.results.graph.DomainResult;
/**
* Represent a simple scalar return within a query result. Generally this would be values of basic (String, Integer,
* etc) or composite types.
* DomainResult for basic values
*
* @author Steve Ebersole
* @author Gail Badner

View File

@ -8,9 +8,6 @@ package org.hibernate.sql.results.graph.collection.internal;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.results.ResultsHelper;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.Fetch;
import org.hibernate.sql.results.graph.FetchParent;
@ -42,18 +39,6 @@ public abstract class CollectionFetch implements Fetch {
return fetchedAttribute;
}
@Override
public DomainResult<?> asResult(DomainResultCreationState creationState) {
return fetchedAttribute.createDomainResult(
fetchedPath,
ResultsHelper.impl( creationState )
.getFromClauseAccess()
.getTableGroup( fetchParent.getNavigablePath() ),
null,
creationState
);
}
@Override
public NavigablePath getNavigablePath() {
return fetchedPath;

View File

@ -7,11 +7,12 @@
package org.hibernate.sql.results.graph.embeddable;
import org.hibernate.sql.results.graph.FetchParentAccess;
import org.hibernate.sql.results.graph.Initializer;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.sql.results.graph.FetchParentAccess;
/**
* Special initializer contract for embeddables
*
* @author Steve Ebersole
*/
public interface EmbeddableInitializer extends FetchParentAccess {

View File

@ -9,6 +9,8 @@ package org.hibernate.sql.results.graph.embeddable;
import org.hibernate.sql.results.graph.DomainResult;
/**
* DomainResult specialization for embeddable-valued results
*
* @author Steve Ebersole
*/
public interface EmbeddableResult<T> extends EmbeddableResultGraphNode, DomainResult<T> {

View File

@ -10,14 +10,12 @@ import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.results.ResultsHelper;
import org.hibernate.sql.ast.SqlAstJoinType;
import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
import org.hibernate.sql.ast.tree.from.TableGroupProducer;
import org.hibernate.sql.results.graph.AbstractFetchParent;
import org.hibernate.sql.results.graph.AssemblerCreationState;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultAssembler;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.Fetch;
@ -123,18 +121,6 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
return super.resolveNavigablePath( fetchable );
}
@Override
public DomainResult<?> asResult(DomainResultCreationState creationState) {
return embeddedPartDescriptor.createDomainResult(
getNavigablePath(),
ResultsHelper.impl( creationState )
.getFromClauseAccess()
.getTableGroup( fetchParent.getNavigablePath() ),
null,
creationState
);
}
@Override
public EmbeddableMappingType getReferencedMappingType() {
return getFetchContainer();

View File

@ -6,11 +6,11 @@
*/
package org.hibernate.sql.results.graph.entity;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.Fetch;
/**
* Specialization of Fetch for entity-valued fetches
*
* @author Steve Ebersole
*/
public interface EntityFetch extends EntityResultGraphNode, Fetch {
@ -19,8 +19,4 @@ public interface EntityFetch extends EntityResultGraphNode, Fetch {
return true;
}
@Override
default DomainResult<?> asResult(DomainResultCreationState creationState) {
throw new UnsupportedOperationException( "EntityFetch -> DomainResult not supported" );
}
}

View File

@ -9,7 +9,7 @@ package org.hibernate.sql.results.graph.entity;
import org.hibernate.sql.results.graph.DomainResult;
/**
* Further defines a first-level Return that is a reference to an entity
* Specialization of DomainResult for entity-valued results
*
* @author Steve Ebersole
*/

View File

@ -14,6 +14,8 @@ import org.hibernate.metamodel.mapping.EntityValuedModelPart;
import org.hibernate.query.NavigablePath;
/**
* Fetchable which is entity-valued
*
* @author Steve Ebersole
*/
public interface EntityValuedFetchable extends Fetchable, EntityValuedModelPart {

View File

@ -9,6 +9,9 @@ package org.hibernate.sql.results.graph.instantiation;
import org.hibernate.sql.results.graph.DomainResult;
/**
* Specialization of DomainResult to model
* {@linkplain jakarta.persistence.ConstructorResult dynamic instantiation}
*
* @author Steve Ebersole
*/
public interface DynamicInstantiationResult<R> extends DomainResult<R> {

View File

@ -43,8 +43,8 @@ public class StandardEntityGraphTraversalStateImpl implements EntityGraphTravers
}
@Override
public void backtrack(GraphImplementor previousContext) {
currentGraphContext = previousContext;
public void backtrack(TraversalResult previousContext) {
currentGraphContext = previousContext.getGraph();
}
@Override