Skip to content

Commit d0fb16d

Browse files
committed
HHH-12713 - Make EntityGraph creation more convenient
- unify naming between 5.x and 6.0 wrt EntityGraph support added in 5.4
1 parent 3bf530d commit d0fb16d

File tree

60 files changed

+734
-512
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+734
-512
lines changed

hibernate-core/src/main/java/org/hibernate/engine/query/spi/EntityGraphQueryHint.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.hibernate.engine.internal.JoinSequence;
2020
import org.hibernate.graph.GraphSemantic;
2121
import org.hibernate.graph.RootGraph;
22+
import org.hibernate.graph.spi.AppliedGraph;
23+
import org.hibernate.graph.spi.RootGraphImplementor;
2224
import org.hibernate.hql.internal.ast.HqlSqlWalker;
2325
import org.hibernate.hql.internal.ast.tree.FromClause;
2426
import org.hibernate.hql.internal.ast.tree.FromElement;
@@ -37,30 +39,32 @@
3739
*
3840
* @author Brett Meyer
3941
*/
40-
public class EntityGraphQueryHint {
41-
private final RootGraph<?> graph;
42+
public class EntityGraphQueryHint implements AppliedGraph {
43+
private final RootGraphImplementor<?> graph;
4244
private final GraphSemantic semantic;
4345

4446
public EntityGraphQueryHint(String hintName, EntityGraph<?> graph) {
4547
assert hintName != null;
4648

4749
this.semantic = GraphSemantic.fromJpaHintName( hintName );
48-
this.graph = (RootGraph<?>) graph;
50+
this.graph = (RootGraphImplementor<?>) graph;
4951
}
5052

51-
public EntityGraphQueryHint(RootGraph<?> graph, GraphSemantic semantic ) {
53+
public EntityGraphQueryHint(RootGraphImplementor<?> graph, GraphSemantic semantic ) {
5254
this.semantic = semantic;
5355
this.graph = graph;
5456
}
5557

56-
public RootGraph<?> getGraph() {
57-
return graph;
58-
}
59-
58+
@Override
6059
public GraphSemantic getSemantic() {
6160
return semantic;
6261
}
6362

63+
@Override
64+
public RootGraphImplementor<?> getGraph() {
65+
return graph;
66+
}
67+
6468
public List<FromElement> toFromElements(FromClause fromClause, HqlSqlWalker walker) {
6569
// If a role already has an explicit fetch in the query, skip it in the graph.
6670
Map<String, FromElement> explicitFetches = new HashMap<String, FromElement>();

hibernate-core/src/main/java/org/hibernate/engine/spi/EffectiveEntityGraph.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.hibernate.Incubating;
1313
import org.hibernate.graph.GraphSemantic;
14+
import org.hibernate.graph.spi.AppliedGraph;
1415
import org.hibernate.graph.spi.RootGraphImplementor;
1516

1617
import org.jboss.logging.Logger;
@@ -27,7 +28,7 @@
2728
*
2829
* @author Steve Ebersole
2930
*/
30-
public class EffectiveEntityGraph implements Serializable {
31+
public class EffectiveEntityGraph implements AppliedGraph, Serializable {
3132
private static final Logger log = Logger.getLogger( EffectiveEntityGraph.class );
3233

3334
private final boolean allowOverwrite;
@@ -58,10 +59,12 @@ public EffectiveEntityGraph(boolean allowOverwrite) {
5859
this.allowOverwrite = allowOverwrite;
5960
}
6061

62+
@Override
6163
public GraphSemantic getSemantic() {
6264
return semantic;
6365
}
6466

67+
@Override
6568
public RootGraphImplementor<?> getGraph() {
6669
return graph;
6770
}

hibernate-core/src/main/java/org/hibernate/graph/internal/AbstractGraph.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
import org.hibernate.graph.spi.GraphImplementor;
2323
import org.hibernate.graph.spi.RootGraphImplementor;
2424
import org.hibernate.internal.util.collections.CollectionHelper;
25-
import org.hibernate.metamodel.model.domain.spi.AttributeImplementor;
26-
import org.hibernate.metamodel.model.domain.spi.EntityTypeImplementor;
27-
import org.hibernate.metamodel.model.domain.spi.ManagedTypeImplementor;
25+
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
26+
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
27+
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
2828

2929
/**
3030
* Base class for {@link RootGraph} and {@link SubGraph} implementations.
3131
*
3232
* @author Steve Ebersole
3333
*/
3434
public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements GraphImplementor<J> {
35-
private final ManagedTypeImplementor<J> managedType;
36-
private Map<AttributeImplementor<?,?>, AttributeNodeImplementor<?>> attrNodeMap;
35+
private final ManagedTypeDescriptor<J> managedType;
36+
private Map<PersistentAttributeDescriptor<?,?>, AttributeNodeImplementor<?>> attrNodeMap;
3737

3838
public AbstractGraph(
39-
ManagedTypeImplementor<J> managedType,
39+
ManagedTypeDescriptor<J> managedType,
4040
boolean mutable,
4141
SessionFactoryImplementor sessionFactory) {
4242
super( mutable, sessionFactory );
@@ -62,14 +62,14 @@ public SessionFactoryImplementor sessionFactory() {
6262
}
6363

6464
@Override
65-
public ManagedTypeImplementor<J> getGraphedType() {
65+
public ManagedTypeDescriptor<J> getGraphedType() {
6666
return managedType;
6767
}
6868

6969
@Override
7070
@SuppressWarnings("unchecked")
7171
public RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) {
72-
if ( getGraphedType() instanceof EntityTypeImplementor ) {
72+
if ( getGraphedType() instanceof EntityTypeDescriptor ) {
7373
return new RootGraphImpl( name, mutable, this );
7474
}
7575

@@ -88,7 +88,7 @@ public void merge(GraphImplementor<J>... others) {
8888
for ( GraphImplementor<J> other : others ) {
8989
for ( AttributeNodeImplementor<?> attributeNode : other.getAttributeNodeImplementors() ) {
9090
final AttributeNodeImplementor localAttributeNode = findAttributeNode(
91-
(AttributeImplementor) attributeNode.getAttributeDescriptor()
91+
(PersistentAttributeDescriptor) attributeNode.getAttributeDescriptor()
9292
);
9393
if ( localAttributeNode != null ) {
9494
// keep the local one, but merge in the incoming one
@@ -139,12 +139,12 @@ public AttributeNodeImplementor<?> addAttributeNode(AttributeNodeImplementor<?>
139139
@Override
140140
@SuppressWarnings("unchecked")
141141
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(String attributeName) {
142-
return findAttributeNode( (AttributeImplementor) managedType.getAttribute( attributeName ) );
142+
return findAttributeNode( (PersistentAttributeDescriptor) managedType.getAttribute( attributeName ) );
143143
}
144144

145145
@Override
146146
@SuppressWarnings("unchecked")
147-
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(AttributeImplementor<? extends J, AJ> attribute) {
147+
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute) {
148148
if ( attrNodeMap == null ) {
149149
return null;
150150
}
@@ -171,14 +171,14 @@ public <AJ> AttributeNodeImplementor<AJ> addAttributeNode(String attributeName)
171171
}
172172

173173
@Override
174-
public <AJ> AttributeNodeImplementor<AJ> addAttributeNode(AttributeImplementor<? extends J, AJ> attribute)
174+
public <AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute)
175175
throws CannotContainSubGraphException {
176176
return findOrCreateAttributeNode( attribute );
177177
}
178178

179179
@Override
180180
@SuppressWarnings("unchecked")
181-
public <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(AttributeImplementor<? extends J, AJ> attribute) {
181+
public <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute) {
182182
verifyMutability();
183183

184184
AttributeNodeImplementor attrNode = null;

hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java

+22-22
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import org.hibernate.graph.spi.AttributeNodeImplementor;
1818
import org.hibernate.graph.spi.SubGraphImplementor;
1919
import org.hibernate.internal.util.collections.CollectionHelper;
20-
import org.hibernate.metamodel.model.domain.spi.AttributeImplementor;
21-
import org.hibernate.metamodel.model.domain.spi.ManagedTypeImplementor;
22-
import org.hibernate.metamodel.model.domain.spi.SimpleTypeImplementor;
20+
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
21+
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
22+
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
2323

2424
import org.jboss.logging.Logger;
2525

@@ -31,15 +31,15 @@
3131
public class AttributeNodeImpl<J>
3232
extends AbstractGraphNode<J>
3333
implements AttributeNodeImplementor<J> {
34-
private final AttributeImplementor<?, J> attribute;
34+
private final PersistentAttributeDescriptor<?, J> attribute;
3535

3636
private Map<Class<? extends J>, SubGraphImplementor<? extends J>> subGraphMap;
3737
private Map<Class<? extends J>, SubGraphImplementor<? extends J>> keySubGraphMap;
3838

3939
@SuppressWarnings("WeakerAccess")
4040
public <X> AttributeNodeImpl(
4141
boolean mutable,
42-
AttributeImplementor<X, J> attribute,
42+
PersistentAttributeDescriptor<X, J> attribute,
4343
SessionFactoryImplementor sessionFactory) {
4444
this( mutable, attribute, null, null, sessionFactory );
4545
}
@@ -49,7 +49,7 @@ public <X> AttributeNodeImpl(
4949
*/
5050
private AttributeNodeImpl(
5151
boolean mutable,
52-
AttributeImplementor<?, J> attribute,
52+
PersistentAttributeDescriptor<?, J> attribute,
5353
Map<Class<? extends J>, SubGraphImplementor<? extends J>> subGraphMap,
5454
Map<Class<? extends J>, SubGraphImplementor<? extends J>> keySubGraphMap,
5555
SessionFactoryImplementor sessionFactory) {
@@ -65,7 +65,7 @@ public String getAttributeName() {
6565
}
6666

6767
@Override
68-
public AttributeImplementor<?, J> getAttributeDescriptor() {
68+
public PersistentAttributeDescriptor<?, J> getAttributeDescriptor() {
6969
return attribute;
7070
}
7171

@@ -102,11 +102,11 @@ public <S extends J> SubGraphImplementor<S> makeSubGraph(Class<S> subtype) {
102102
}
103103

104104
@Override
105-
public <S extends J> SubGraphImplementor<S> makeSubGraph(ManagedTypeImplementor<S> subtype) {
105+
public <S extends J> SubGraphImplementor<S> makeSubGraph(ManagedTypeDescriptor<S> subtype) {
106106
return internalMakeSubgraph( subtype );
107107
}
108108

109-
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(ManagedTypeImplementor<S> type) {
109+
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(ManagedTypeDescriptor<S> type) {
110110
assert type != null;
111111

112112
log.debugf( "Making sub-graph : ( (%s) %s )", type.getName(), getAttributeName() );
@@ -118,11 +118,11 @@ private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(ManagedTypeImp
118118
}
119119

120120
@SuppressWarnings("unchecked")
121-
private <T extends J> ManagedTypeImplementor<T> valueGraphTypeAsManaged() {
122-
final SimpleTypeImplementor<J> valueGraphType = (SimpleTypeImplementor) getAttributeDescriptor().getValueGraphType();
121+
private <T extends J> ManagedTypeDescriptor<T> valueGraphTypeAsManaged() {
122+
final SimpleTypeDescriptor<J> valueGraphType = (SimpleTypeDescriptor) getAttributeDescriptor().getValueGraphType();
123123

124-
if ( valueGraphType instanceof ManagedTypeImplementor ) {
125-
return (ManagedTypeImplementor) valueGraphType;
124+
if ( valueGraphType instanceof ManagedTypeDescriptor ) {
125+
return (ManagedTypeDescriptor) valueGraphType;
126126
}
127127

128128
throw new CannotContainSubGraphException(
@@ -141,7 +141,7 @@ private <T extends J> ManagedTypeImplementor<T> valueGraphTypeAsManaged() {
141141
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(Class<S> subType) {
142142
verifyMutability();
143143

144-
final ManagedTypeImplementor<S> managedType = valueGraphTypeAsManaged();
144+
final ManagedTypeDescriptor<S> managedType = valueGraphTypeAsManaged();
145145

146146
if ( subType == null ) {
147147
subType = managedType.getJavaType();
@@ -183,11 +183,11 @@ public <S extends J> SubGraphImplementor<S> makeKeySubGraph(Class<S> subtype) {
183183
}
184184

185185
@Override
186-
public <S extends J> SubGraphImplementor<S> makeKeySubGraph(ManagedTypeImplementor<S> subtype) {
186+
public <S extends J> SubGraphImplementor<S> makeKeySubGraph(ManagedTypeDescriptor<S> subtype) {
187187
return internalMakeKeySubgraph( subtype );
188188
}
189189

190-
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(ManagedTypeImplementor<S> type) {
190+
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(ManagedTypeDescriptor<S> type) {
191191

192192
log.debugf( "Making key sub-graph : ( (%s) %s )", type.getName(), getAttributeName() );
193193

@@ -201,9 +201,9 @@ private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(ManagedType
201201
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(Class<S> type) {
202202
verifyMutability();
203203

204-
final ManagedTypeImplementor<S> managedType = keyGraphTypeAsManaged();
204+
final ManagedTypeDescriptor<S> managedType = keyGraphTypeAsManaged();
205205

206-
final ManagedTypeImplementor<S> subType;
206+
final ManagedTypeDescriptor<S> subType;
207207

208208
if ( type == null ) {
209209
subType = managedType;
@@ -232,11 +232,11 @@ protected <S extends J> void internalAddKeySubGraph(Class<S> subType, SubGraph<S
232232
}
233233

234234
@SuppressWarnings("unchecked")
235-
private <T extends J> ManagedTypeImplementor<T> keyGraphTypeAsManaged() {
236-
final SimpleTypeImplementor<J> keyGraphType = (SimpleTypeImplementor) getAttributeDescriptor().getKeyGraphType();
235+
private <T extends J> ManagedTypeDescriptor<T> keyGraphTypeAsManaged() {
236+
final SimpleTypeDescriptor<J> keyGraphType = (SimpleTypeDescriptor) getAttributeDescriptor().getKeyGraphType();
237237

238-
if ( keyGraphType instanceof ManagedTypeImplementor ) {
239-
return (ManagedTypeImplementor) keyGraphType;
238+
if ( keyGraphType instanceof ManagedTypeDescriptor ) {
239+
return (ManagedTypeDescriptor) keyGraphType;
240240
}
241241

242242
throw new CannotContainSubGraphException(

hibernate-core/src/main/java/org/hibernate/graph/internal/RootGraphImpl.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import org.hibernate.graph.spi.GraphImplementor;
1515
import org.hibernate.graph.spi.RootGraphImplementor;
1616
import org.hibernate.graph.spi.SubGraphImplementor;
17-
import org.hibernate.metamodel.model.domain.spi.EntityTypeImplementor;
18-
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeImplementor;
17+
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
18+
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
1919

2020
/**
2121
* The Hibernate implementation of the JPA EntityGraph contract.
@@ -27,14 +27,14 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
2727

2828
public RootGraphImpl(
2929
String name,
30-
EntityTypeImplementor<J> entityType,
30+
EntityTypeDescriptor<J> entityType,
3131
boolean mutable,
3232
SessionFactoryImplementor sessionFactory) {
3333
super( entityType, mutable, sessionFactory );
3434
this.name = name;
3535
}
3636

37-
public RootGraphImpl(String name, EntityTypeImplementor<J> entityType, SessionFactoryImplementor sessionFactory) {
37+
public RootGraphImpl(String name, EntityTypeDescriptor<J> entityType, SessionFactoryImplementor sessionFactory) {
3838
this(
3939
name,
4040
entityType,
@@ -78,12 +78,12 @@ public <T1> SubGraph<? extends T1> addSubclassSubgraph(Class<? extends T1> type)
7878
}
7979

8080
@Override
81-
public boolean appliesTo(EntityTypeImplementor<? super J> entityType) {
81+
public boolean appliesTo(EntityTypeDescriptor<? super J> entityType) {
8282
if ( this.getGraphedType().equals( entityType ) ) {
8383
return true;
8484
}
8585

86-
IdentifiableTypeImplementor superType = entityType.getSupertype();
86+
IdentifiableTypeDescriptor superType = entityType.getSupertype();
8787
while ( superType != null ) {
8888
if ( superType.equals( entityType ) ) {
8989
return true;

hibernate-core/src/main/java/org/hibernate/graph/internal/SubGraphImpl.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88

99
import javax.persistence.metamodel.Attribute;
1010

11-
import org.hibernate.cfg.NotYetImplementedException;
1211
import org.hibernate.engine.spi.SessionFactoryImplementor;
1312
import org.hibernate.graph.spi.AttributeNodeImplementor;
1413
import org.hibernate.graph.spi.SubGraphImplementor;
15-
import org.hibernate.metamodel.model.domain.spi.ManagedTypeImplementor;
14+
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
1615

1716
/**
1817
* @author Steve Ebersole
1918
*/
2019
public class SubGraphImpl<J> extends AbstractGraph<J> implements SubGraphImplementor<J> {
2120
public SubGraphImpl(
22-
ManagedTypeImplementor<J> managedType,
21+
ManagedTypeDescriptor<J> managedType,
2322
boolean mutable,
2423
SessionFactoryImplementor sessionFactory) {
2524
super( managedType, mutable, sessionFactory );
@@ -54,12 +53,12 @@ public <AJ> AttributeNodeImplementor<AJ> addAttributeNode(Attribute<? extends J,
5453
}
5554

5655
@Override
57-
public boolean appliesTo(ManagedTypeImplementor<? super J> managedType) {
56+
public boolean appliesTo(ManagedTypeDescriptor<? super J> managedType) {
5857
if ( this.getGraphedType().equals( managedType ) ) {
5958
return true;
6059
}
6160

62-
ManagedTypeImplementor superType = managedType.getSuperType();
61+
ManagedTypeDescriptor superType = managedType.getSuperType();
6362
while ( superType != null ) {
6463
if ( superType.equals( managedType ) ) {
6564
return true;

0 commit comments

Comments
 (0)