Skip to content

Commit 3ef6fa9

Browse files
committed
Graphpocalypse: actually let's just deprecate the makeXxxxSubGraph() operations...
... and delete the new ones I added. The reasoning here is that they just aren't properly typesafe, as you can see by the hoops I had to go through to actually implement them. And since the whole package is marked @Incubating, we're not committed to them.
1 parent b612512 commit 3ef6fa9

File tree

3 files changed

+20
-79
lines changed

3 files changed

+20
-79
lines changed

hibernate-core/src/main/java/org/hibernate/graph/AttributeNode.java

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77

88
import jakarta.persistence.Subgraph;
9-
import jakarta.persistence.metamodel.ManagedType;
10-
import org.hibernate.Incubating;
119
import org.hibernate.metamodel.model.domain.PersistentAttribute;
1210

1311
import java.util.Map;
@@ -99,23 +97,27 @@ public interface AttributeNode<J> extends GraphNode<J>, jakarta.persistence.Attr
9997
/**
10098
* Create and return a new value {@link SubGraph} rooted at this node,
10199
* or return an existing such {@link SubGraph} if there is one.
102-
* <p>
100+
*
101+
* @deprecated This operation is not properly type safe.
103102
* Note that {@code graph.addAttributeNode(att).makeSubGraph()} is a
104103
* synonym for {@code graph.addSubgraph(att)}.
105104
*
106105
* @see Graph#addSubgraph(jakarta.persistence.metamodel.Attribute)
107106
*/
107+
@Deprecated(since = "7.0")
108108
SubGraph<?> makeSubGraph();
109109

110110
/**
111111
* Create and return a new key {@link SubGraph} rooted at this node,
112112
* or return an existing such {@link SubGraph} if there is one.
113-
* <p>
113+
*
114+
* @deprecated This operation is not properly type safe.
114115
* Note that {@code graph.addAttributeNode(att).makeKeySubGraph()} is a
115116
* synonym for {@code graph.addMapKeySubgraph(att)}.
116117
*
117118
* @see Graph#addMapKeySubgraph(jakarta.persistence.metamodel.MapAttribute)
118119
*/
120+
@Deprecated(since = "7.0")
119121
SubGraph<?> makeKeySubGraph();
120122

121123
/**
@@ -125,14 +127,16 @@ public interface AttributeNode<J> extends GraphNode<J>, jakarta.persistence.Attr
125127
* <p>
126128
* If the given type is a proper subtype of the value type, the result
127129
* is a treated subgraph.
128-
* <p>
130+
*
131+
* @deprecated This operation is not properly type safe.
129132
* Note that {@code graph.addAttributeNode(att).makeSubGraph(cl)}
130133
* is a synonym for {@code graph.addTreatedSubgraph(att,cl)}.
131134
*
132135
* @param subtype The type or treated type of the value type
133136
*
134137
* @see Graph#addTreatedSubgraph(jakarta.persistence.metamodel.Attribute, Class)
135138
*/
139+
@Deprecated(since = "7.0")
136140
<S> SubGraph<S> makeSubGraph(Class<S> subtype);
137141

138142
/**
@@ -142,43 +146,15 @@ public interface AttributeNode<J> extends GraphNode<J>, jakarta.persistence.Attr
142146
* <p>
143147
* If the given type is a proper subtype of the key type, the result
144148
* is a treated subgraph.
145-
* <p>
149+
*
150+
* @deprecated This operation is not properly type safe.
146151
* Note that {@code graph.addAttributeNode(att).makeKeySubGraph(cl)}
147152
* is a synonym for {@code graph.addTreatedMapKeySubgraph(att,cl)}.
148153
*
149154
* @param subtype The type or treated type of the key type
150155
*
151156
* @see Graph#addTreatedMapKeySubgraph(jakarta.persistence.metamodel.MapAttribute,Class)
152157
*/
158+
@Deprecated(since = "7.0")
153159
<S> SubGraph<S> makeKeySubGraph(Class<S> subtype);
154-
155-
/**
156-
* Create and return a new value {@link SubGraph} rooted at this node,
157-
* with the given type, which may be a subtype of the value type,
158-
* or return an existing such {@link SubGraph} if there is one.
159-
* <p>
160-
* If the given type is a proper subtype of the value type, the result
161-
* is a treated subgraph.
162-
*
163-
* @param subtype The type or treated type of the value type
164-
*
165-
* @since 7.0
166-
*/
167-
@Incubating
168-
<S> SubGraph<S> makeSubGraph(ManagedType<S> subtype);
169-
170-
/**
171-
* Create and return a new value {@link SubGraph} rooted at this node,
172-
* with the given type, which may be a subtype of the key type,
173-
* or return an existing such {@link SubGraph} if there is one.
174-
* <p>
175-
* If the given type is a proper subtype of the key type, the result
176-
* is a treated subgraph.
177-
*
178-
* @param subtype The type or treated type of the key type
179-
*
180-
* @since 7.0
181-
*/
182-
@Incubating
183-
<S> SubGraph<S> makeKeySubGraph(ManagedType<S> subtype);
184160
}

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

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public SubGraphImplementor<K> getKeySubGraph() {
7777
return keySubgraph;
7878
}
7979

80-
@Override
80+
@Override @Deprecated
8181
public SubGraphImplementor<V> makeSubGraph() {
8282
verifyMutability();
8383
if ( valueSubgraph == null ) {
@@ -86,7 +86,7 @@ public SubGraphImplementor<V> makeSubGraph() {
8686
return valueSubgraph;
8787
}
8888

89-
@Override
89+
@Override @Deprecated
9090
public <S> SubGraphImplementor<S> makeSubGraph(Class<S> subtype) {
9191
final ManagedDomainType<V> managedType = asManagedType( valueGraphType );
9292
if ( !managedType.getBindableJavaType().isAssignableFrom( subtype ) ) {
@@ -99,21 +99,7 @@ public <S> SubGraphImplementor<S> makeSubGraph(Class<S> subtype) {
9999
return (SubGraphImplementor<S>) result;
100100
}
101101

102-
@Override
103-
public <S> SubGraphImplementor<S> makeSubGraph(ManagedType<S> subtype) {
104-
final ManagedDomainType<V> managedType = asManagedType( valueGraphType );
105-
final Class<S> javaType = subtype.getJavaType();
106-
if ( !managedType.getBindableJavaType().isAssignableFrom( javaType ) ) {
107-
throw new IllegalArgumentException( "Not a subtype: " + javaType.getName() );
108-
}
109-
@SuppressWarnings("unchecked")
110-
final ManagedDomainType<? extends V> castType = (ManagedDomainType<? extends V>) subtype;
111-
final SubGraphImplementor<? extends V> result = makeSubGraph().addTreatedSubgraph( castType );
112-
//noinspection unchecked
113-
return (SubGraphImplementor<S>) result;
114-
}
115-
116-
@Override
102+
@Override @Deprecated
117103
public SubGraphImplementor<K> makeKeySubGraph() {
118104
verifyMutability();
119105
checkMap();
@@ -123,7 +109,7 @@ public SubGraphImplementor<K> makeKeySubGraph() {
123109
return keySubgraph;
124110
}
125111

126-
@Override
112+
@Override @Deprecated
127113
public <S> SubGraphImplementor<S> makeKeySubGraph(Class<S> subtype) {
128114
checkMap();
129115
final ManagedDomainType<K> type = asManagedType( keyGraphType );
@@ -137,21 +123,6 @@ public <S> SubGraphImplementor<S> makeKeySubGraph(Class<S> subtype) {
137123
return (SubGraphImplementor<S>) result;
138124
}
139125

140-
@Override
141-
public <S> SubGraphImplementor<S> makeKeySubGraph(ManagedType<S> subtype) {
142-
checkMap();
143-
final ManagedDomainType<K> type = asManagedType( keyGraphType );
144-
final Class<S> javaType = subtype.getJavaType();
145-
if ( !type.getBindableJavaType().isAssignableFrom( javaType ) ) {
146-
throw new IllegalArgumentException( "Not a key subtype: " + javaType.getName() );
147-
}
148-
@SuppressWarnings("unchecked")
149-
final ManagedDomainType<? extends K> castType = (ManagedDomainType<? extends K>) subtype;
150-
final SubGraphImplementor<? extends K> result = makeKeySubGraph().addTreatedSubgraph( castType );
151-
//noinspection unchecked
152-
return (SubGraphImplementor<S>) result;
153-
}
154-
155126
private void checkMap() {
156127
if ( keyGraphType == null ) {
157128
throw new CannotContainSubGraphException( "Attribute '" + description() + "' is not a Map" );

hibernate-core/src/main/java/org/hibernate/graph/spi/AttributeNodeImplementor.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,18 @@ public interface AttributeNodeImplementor<J> extends AttributeNode<J>, GraphNode
2121
@Override
2222
AttributeNodeImplementor<J> makeCopy(boolean mutable);
2323

24-
@Override
24+
@Override @Deprecated
2525
SubGraphImplementor<?> makeSubGraph();
2626

27-
@Override
27+
@Override @Deprecated
2828
SubGraphImplementor<?> makeKeySubGraph();
2929

30-
@Override
30+
@Override @Deprecated
3131
<S> SubGraphImplementor<S> makeSubGraph(Class<S> subtype);
3232

33-
@Override
33+
@Override @Deprecated
3434
<S> SubGraphImplementor<S> makeKeySubGraph(Class<S> subtype);
3535

36-
@Override
37-
<S> SubGraphImplementor<S> makeSubGraph(ManagedType<S> subtype);
38-
39-
@Override
40-
<S> SubGraphImplementor<S> makeKeySubGraph(ManagedType<S> subtype);
41-
4236
void merge(AttributeNodeImplementor<J> other);
4337

4438
SubGraphImplementor<?> getSubGraph();

0 commit comments

Comments
 (0)