Skip to content

Commit c3f1614

Browse files
committed
Add support for EntityGraphs
1 parent 061aaaf commit c3f1614

File tree

6 files changed

+57
-44
lines changed

6 files changed

+57
-44
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinySessionImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,17 @@ public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String m
507507
}
508508

509509
@Override
510-
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName) {
511-
throw new UnsupportedOperationException();
510+
public <T> EntityGraph<T> getEntityGraph(Class<T> rootType, String graphName) {
511+
return delegate.getEntityGraph( rootType, graphName );
512512
}
513513

514514
@Override
515-
public <T> EntityGraph<T> getEntityGraph(Class<T> rootType, String graphName) {
516-
throw new UnsupportedOperationException();
515+
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType) {
516+
return delegate.createEntityGraph( rootType );
517517
}
518518

519519
@Override
520-
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType) {
521-
throw new UnsupportedOperationException();
520+
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName) {
521+
return delegate.createEntityGraph( rootType, graphName );
522522
}
523523
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinyStatelessSessionImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,16 @@ public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String m
274274

275275
@Override
276276
public <T> EntityGraph<T> getEntityGraph(Class<T> rootType, String graphName) {
277-
throw new UnsupportedOperationException("Not yet implemented");
277+
return delegate.getEntityGraph( rootType, graphName );
278278
}
279279

280280
@Override
281281
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType) {
282-
throw new UnsupportedOperationException("Not yet implemented");
282+
return delegate.createEntityGraph( rootType );
283283
}
284284

285285
@Override
286286
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName) {
287-
throw new UnsupportedOperationException("Not yet implemented");
287+
return delegate.createEntityGraph( rootType, graphName );
288288
}
289289
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionImpl.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,12 +1829,22 @@ private void logRemoveOrphanBeforeUpdates(
18291829
}
18301830

18311831
@Override
1832-
public <T> EntityGraph<T> createEntityGraph(Class<T> entity, String name) {
1833-
throw new UnsupportedOperationException();
1832+
@SuppressWarnings("unchecked")
1833+
public <T> RootGraphImplementor<T> createEntityGraph(Class<T> entity, String name) {
1834+
RootGraphImplementor<?> entityGraph = createEntityGraph( name );
1835+
if ( !entityGraph.getGraphedType().getJavaType().equals( entity ) ) {
1836+
throw LOG.wrongEntityType();
1837+
}
1838+
return (RootGraphImplementor<T>) entityGraph;
18341839
}
18351840

18361841
@Override
1837-
public <T> EntityGraph<T> getEntityGraph(Class<T> entity, String name) {
1838-
throw new UnsupportedOperationException();
1842+
@SuppressWarnings("unchecked")
1843+
public <T> RootGraphImplementor<T> getEntityGraph(Class<T> entity, String name) {
1844+
RootGraphImplementor<?> entityGraph = getEntityGraph( name );
1845+
if ( !entityGraph.getGraphedType().getJavaType().equals( entity ) ) {
1846+
throw LOG.wrongEntityType();
1847+
}
1848+
return (RootGraphImplementor<T>) entityGraph;
18391849
}
18401850
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveStatelessSessionImpl.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,14 @@ else if ( isPersistentAttributeInterceptable( association ) ) {
597597
}
598598
}
599599

600+
601+
@Override
602+
public <T> RootGraphImplementor<T> createEntityGraph(Class<T> entity) {
603+
return new RootGraphImpl<>( null,
604+
getFactory().getJpaMetamodel().entity( entity ),
605+
getSessionFactory().getJpaMetamodel() );
606+
}
607+
600608
@Override
601609
@SuppressWarnings("unchecked")
602610
public <T> RootGraphImplementor<T> createEntityGraph(Class<T> entity, String name) {
@@ -607,6 +615,14 @@ public <T> RootGraphImplementor<T> createEntityGraph(Class<T> entity, String nam
607615
return (RootGraphImplementor<T>) entityGraph;
608616
}
609617

618+
private RootGraphImplementor<?> createEntityGraph(String graphName) {
619+
checkOpen();
620+
final RootGraphImplementor<?> named = getFactory().findEntityGraphByName( graphName );
621+
return named != null
622+
? named.makeRootGraph( graphName, true )
623+
: null;
624+
}
625+
610626
@Override
611627
@SuppressWarnings("unchecked")
612628
public <T> RootGraphImplementor<T> getEntityGraph(Class<T> entity, String name) {
@@ -617,6 +633,15 @@ public <T> RootGraphImplementor<T> getEntityGraph(Class<T> entity, String name)
617633
return (RootGraphImplementor<T>) entityGraph;
618634
}
619635

636+
private RootGraphImplementor<?> getEntityGraph(String graphName) {
637+
checkOpen();
638+
final RootGraphImplementor<?> named = getFactory().findEntityGraphByName( graphName );
639+
if ( named == null ) {
640+
throw new IllegalArgumentException( "Could not locate EntityGraph with given name : " + graphName );
641+
}
642+
return named;
643+
}
644+
620645
@Override
621646
public <R> ReactiveSqmQueryImplementor<R> createReactiveQuery(String queryString) {
622647
return createReactiveQuery( queryString, null );
@@ -1040,35 +1065,11 @@ public <R> ReactiveNativeQuery createReactiveNativeQuery(
10401065
throw LOG.notYetImplemented();
10411066
}
10421067

1043-
@Override
1044-
public <T> RootGraphImplementor<T> createEntityGraph(Class<T> entity) {
1045-
return new RootGraphImpl<>( null,
1046-
getFactory().getJpaMetamodel().entity( entity ),
1047-
getSessionFactory().getJpaMetamodel() );
1048-
}
1049-
1050-
private RootGraphImplementor<?> createEntityGraph(String graphName) {
1051-
checkOpen();
1052-
final RootGraphImplementor<?> named = getFactory().findEntityGraphByName( graphName );
1053-
return named != null
1054-
? named.makeRootGraph( graphName, true )
1055-
: null;
1056-
}
1057-
10581068
@Override
10591069
public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String mappingName) {
10601070
throw LOG.notYetImplemented();
10611071
}
10621072

1063-
private RootGraphImplementor<?> getEntityGraph(String graphName) {
1064-
checkOpen();
1065-
final RootGraphImplementor<?> named = getFactory().findEntityGraphByName( graphName );
1066-
if ( named == null ) {
1067-
throw new IllegalArgumentException( "Could not locate EntityGraph with given name : " + graphName );
1068-
}
1069-
return named;
1070-
}
1071-
10721073
@Override
10731074
public void close() {
10741075
throw LOG.nonReactiveMethodCall( "close(CompletableFuture<Void> closing)" );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/impl/StageSessionImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,17 +462,17 @@ public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String m
462462

463463
@Override
464464
public <T> EntityGraph<T> getEntityGraph(Class<T> rootType, String graphName) {
465-
throw new UnsupportedOperationException();
465+
return delegate.getEntityGraph( rootType, graphName );
466466
}
467467

468468
@Override
469469
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType) {
470-
throw new UnsupportedOperationException();
470+
return delegate.createEntityGraph( rootType );
471471
}
472472

473473
@Override
474474
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName) {
475-
throw new UnsupportedOperationException("Not yet implemented");
475+
return delegate.createEntityGraph( rootType, graphName );
476476
}
477477

478478
@Override

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/impl/StageStatelessSessionImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.function.Function;
1111

1212
import org.hibernate.LockMode;
13+
import org.hibernate.graph.spi.RootGraphImplementor;
1314
import org.hibernate.reactive.common.ResultSetMapping;
1415
import org.hibernate.reactive.pool.ReactiveConnection;
1516
import org.hibernate.reactive.session.ReactiveStatelessSession;
@@ -213,7 +214,8 @@ public boolean isMarkedForRollback() {
213214

214215
@Override
215216
public <T> CompletionStage<T> get(EntityGraph<T> entityGraph, Object id) {
216-
throw new UnsupportedOperationException("Not yet implemented");
217+
Class<T> entityClass = ( (RootGraphImplementor<T>) entityGraph ).getGraphedType().getJavaType();
218+
return delegate.reactiveGet( entityClass, id, null, entityGraph );
217219
}
218220

219221
@Override
@@ -268,16 +270,16 @@ public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String m
268270

269271
@Override
270272
public <T> EntityGraph<T> getEntityGraph(Class<T> rootType, String graphName) {
271-
throw new UnsupportedOperationException("Not yet implemented");
273+
return delegate.getEntityGraph( rootType, graphName );
272274
}
273275

274276
@Override
275277
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType) {
276-
throw new UnsupportedOperationException("Not yet implemented");
278+
return delegate.createEntityGraph( rootType );
277279
}
278280

279281
@Override
280282
public <T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName) {
281-
throw new UnsupportedOperationException("Not yet implemented");
283+
return delegate.createEntityGraph( rootType, graphName );
282284
}
283285
}

0 commit comments

Comments
 (0)