Skip to content

Commit f4eaa7f

Browse files
committed
add some accessor methods onto AbstractCommonQueryContract
1 parent 998575f commit f4eaa7f

File tree

6 files changed

+58
-52
lines changed

6 files changed

+58
-52
lines changed

hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
7777
import org.hibernate.sql.results.NoMoreOutputsException;
7878
import org.hibernate.type.BasicType;
79-
import org.hibernate.type.spi.TypeConfiguration;
8079

8180
import jakarta.persistence.CacheRetrieveMode;
8281
import jakarta.persistence.CacheStoreMode;
@@ -172,7 +171,7 @@ public ProcedureCallImpl(SharedSessionContractImplementor session, String proced
172171
resultClasses,
173172
resultSetMapping,
174173
synchronizedQuerySpaces::add,
175-
() -> getSession().getFactory()
174+
this::getSessionFactory
176175
);
177176
}
178177

@@ -205,7 +204,7 @@ public ProcedureCallImpl(
205204
resultSetMappingNames,
206205
resultSetMapping,
207206
synchronizedQuerySpaces::add,
208-
() -> getSession().getFactory()
207+
this::getSessionFactory
209208
);
210209
}
211210

@@ -232,7 +231,7 @@ public ProcedureCallImpl(
232231
memento.getResultSetMappingClasses(),
233232
resultSetMapping,
234233
synchronizedQuerySpaces::add,
235-
() -> getSession().getFactory()
234+
this::getSessionFactory
236235
);
237236

238237
applyOptions( memento );
@@ -265,7 +264,7 @@ public ProcedureCallImpl(
265264
resultTypes,
266265
resultSetMapping,
267266
synchronizedQuerySpaces::add,
268-
getSession()::getFactory
267+
this::getSessionFactory
269268
);
270269

271270
applyOptions( memento );
@@ -292,7 +291,7 @@ public ProcedureCallImpl(
292291
null,
293292
resultSetMapping,
294293
synchronizedQuerySpaces::add,
295-
() -> getSession().getFactory()
294+
this::getSessionFactory
296295
);
297296

298297
applyOptions( memento );
@@ -362,10 +361,6 @@ private void markAsFunctionCallRefRefCursor() {
362361
functionReturn = new FunctionReturnImpl<>( this, Types.REF_CURSOR );
363362
}
364363

365-
private TypeConfiguration getTypeConfiguration() {
366-
return getSessionFactory().getTypeConfiguration();
367-
}
368-
369364
@Override
370365
public ProcedureCallImpl<R> markAsFunctionCall(Class<?> resultType) {
371366
final BasicType<?> basicType = getTypeConfiguration().getBasicTypeForJavaType( resultType );
@@ -418,7 +413,7 @@ public ProcedureCallImplementor<R> registerStoredProcedureParameter(int position
418413
registerParameter( position, type, mode );
419414
}
420415
catch (HibernateException he) {
421-
throw getSession().getExceptionConverter().convert( he );
416+
throw getExceptionConverter().convert( he );
422417
}
423418
catch (RuntimeException e) {
424419
getSession().markForRollbackOnly();
@@ -437,7 +432,7 @@ public ProcedureCallImplementor<R> registerStoredProcedureParameter(
437432
registerParameter( parameterName, type, mode );
438433
}
439434
catch (HibernateException he) {
440-
throw getSession().getExceptionConverter().convert( he );
435+
throw getExceptionConverter().convert( he );
441436
}
442437
catch (RuntimeException e) {
443438
getSession().markForRollbackOnly();
@@ -457,7 +452,7 @@ public ProcedureCallImplementor<R> registerStoredProcedureParameter(
457452
registerParameter( position, type, mode );
458453
}
459454
catch (HibernateException he) {
460-
throw getSession().getExceptionConverter().convert( he );
455+
throw getExceptionConverter().convert( he );
461456
}
462457
catch (RuntimeException e) {
463458
getSession().markForRollbackOnly();
@@ -476,7 +471,7 @@ public ProcedureCallImplementor<R> registerStoredProcedureParameter(
476471
registerParameter( parameterName, type, mode );
477472
}
478473
catch (HibernateException he) {
479-
throw getSession().getExceptionConverter().convert( he );
474+
throw getExceptionConverter().convert( he );
480475
}
481476
catch (RuntimeException e) {
482477
getSession().markForRollbackOnly();
@@ -726,7 +721,7 @@ public ProcedureCallImplementor<R> addSynchronizedQuerySpace(String querySpace)
726721
@Override
727722
public ProcedureCallImplementor<R> addSynchronizedEntityName(String entityName) {
728723
final EntityPersister entityDescriptor =
729-
getSession().getFactory().getMappingMetamodel()
724+
this.getSessionFactory().getMappingMetamodel()
730725
.getEntityDescriptor( entityName );
731726
addSynchronizedQuerySpaces( entityDescriptor );
732727
return this;
@@ -739,7 +734,7 @@ protected void addSynchronizedQuerySpaces(EntityPersister persister) {
739734
@Override
740735
public ProcedureCallImplementor<R> addSynchronizedEntityClass(@SuppressWarnings("rawtypes") Class entityClass) {
741736
final EntityPersister entityDescriptor =
742-
getSession().getFactory().getMappingMetamodel()
737+
this.getSessionFactory().getMappingMetamodel()
743738
.getEntityDescriptor( entityClass );
744739
addSynchronizedQuerySpaces( entityDescriptor );
745740
return this;
@@ -810,7 +805,7 @@ public boolean execute() {
810805
return false;
811806
}
812807
catch (HibernateException he) {
813-
throw getSession().getExceptionConverter().convert( he );
808+
throw getExceptionConverter().convert( he );
814809
}
815810
catch (RuntimeException e) {
816811
getSession().markForRollbackOnly();
@@ -892,7 +887,7 @@ else if ( rtn instanceof UpdateCountOutput updateCount ) {
892887
return -1;
893888
}
894889
catch (HibernateException he) {
895-
throw getSession().getExceptionConverter().convert( he );
890+
throw getExceptionConverter().convert( he );
896891
}
897892
catch (RuntimeException e) {
898893
getSession().markForRollbackOnly();
@@ -922,7 +917,7 @@ protected List<R> doList() {
922917
return null;
923918
}
924919
catch (HibernateException he) {
925-
throw getSession().getExceptionConverter().convert( he );
920+
throw getExceptionConverter().convert( he );
926921
}
927922
catch (RuntimeException e) {
928923
getSession().markForRollbackOnly();

hibernate-core/src/main/java/org/hibernate/query/spi/AbstractCommonQueryContract.java

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import org.hibernate.FlushMode;
1616
import org.hibernate.Internal;
17+
import org.hibernate.engine.spi.ExceptionConverter;
18+
import org.hibernate.engine.spi.SessionFactoryImplementor;
1719
import org.hibernate.query.QueryArgumentException;
1820
import org.hibernate.query.QueryFlushMode;
1921
import org.hibernate.HibernateException;
@@ -28,8 +30,6 @@
2830
import org.hibernate.graph.spi.RootGraphImplementor;
2931
import org.hibernate.jpa.internal.util.ConfigurationHelper;
3032
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
31-
import org.hibernate.metamodel.RuntimeMetamodels;
32-
import org.hibernate.metamodel.model.domain.JpaMetamodel;
3333
import org.hibernate.metamodel.model.domain.ManagedDomainType;
3434
import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies;
3535
import org.hibernate.property.access.spi.Getter;
@@ -112,10 +112,22 @@ protected AbstractCommonQueryContract(AbstractCommonQueryContract original) {
112112
this.queryOptions = original.queryOptions;
113113
}
114114

115-
public SharedSessionContractImplementor getSession() {
115+
public final SharedSessionContractImplementor getSession() {
116116
return session;
117117
}
118118

119+
public final SessionFactoryImplementor getSessionFactory() {
120+
return session.getFactory();
121+
}
122+
123+
public final TypeConfiguration getTypeConfiguration() {
124+
return session.getFactory().getTypeConfiguration();
125+
}
126+
127+
protected final ExceptionConverter getExceptionConverter() {
128+
return session.getExceptionConverter();
129+
}
130+
119131
protected int getIntegerLiteral(JpaExpression<Number> expression, int defaultValue) {
120132
if ( expression == null ) {
121133
return defaultValue;
@@ -379,14 +391,16 @@ protected void applyGraph(String graphString, GraphSemantic graphSemantic) {
379391
);
380392
}
381393

382-
final RuntimeMetamodels runtimeMetamodels = getSession().getFactory().getRuntimeMetamodels();
383-
final JpaMetamodel jpaMetamodel = runtimeMetamodels.getJpaMetamodel();
394+
final var factory = getSessionFactory();
384395

385-
final String entityName = runtimeMetamodels.getImportedName( graphString.substring( 0, separatorPosition ).trim() );
396+
final String entityName =
397+
factory.getMappingMetamodel()
398+
.getImportedName( graphString.substring( 0, separatorPosition ).trim() );
386399
final String graphNodes = graphString.substring( separatorPosition + 1, terminatorPosition );
387400

388-
final RootGraphImpl<?> rootGraph = new RootGraphImpl<>( null, jpaMetamodel.entity( entityName ) );
389-
GraphParser.parseInto( (EntityGraph<?>) rootGraph, graphNodes, getSession().getSessionFactory() );
401+
final RootGraphImpl<?> rootGraph =
402+
new RootGraphImpl<>( null, factory.getJpaMetamodel().entity( entityName ) );
403+
GraphParser.parseInto( (EntityGraph<?>) rootGraph, graphNodes, getSessionFactory() );
390404
applyGraph( rootGraph, graphSemantic );
391405
}
392406

@@ -587,7 +601,7 @@ public QueryParameterImplementor<?> getParameter(String name) {
587601
return getParameterMetadata().getQueryParameter( name );
588602
}
589603
catch ( HibernateException e ) {
590-
throw getSession().getExceptionConverter().convert( e );
604+
throw getExceptionConverter().convert( e );
591605
}
592606
}
593607

@@ -608,7 +622,7 @@ public <T> QueryParameterImplementor<T> getParameter(String name, Class<T> type)
608622
return parameter;
609623
}
610624
catch ( HibernateException e ) {
611-
throw getSession().getExceptionConverter().convert( e );
625+
throw getExceptionConverter().convert( e );
612626
}
613627
}
614628

@@ -619,7 +633,7 @@ public QueryParameterImplementor<?> getParameter(int position) {
619633
return getParameterMetadata().getQueryParameter( position );
620634
}
621635
catch ( HibernateException e ) {
622-
throw getSession().getExceptionConverter().convert( e );
636+
throw getExceptionConverter().convert( e );
623637
}
624638
}
625639

@@ -639,7 +653,7 @@ public <T> QueryParameterImplementor<T> getParameter(int position, Class<T> type
639653
return parameter;
640654
}
641655
catch ( HibernateException e ) {
642-
throw getSession().getExceptionConverter().convert( e );
656+
throw getExceptionConverter().convert( e );
643657
}
644658
}
645659

@@ -652,7 +666,7 @@ public <T> QueryParameterImplementor<T> getParameter(int position, Class<T> type
652666
protected abstract boolean resolveJdbcParameterTypeIfNecessary();
653667

654668
private <P> JavaType<P> getJavaType(Class<P> javaType) {
655-
return getSession().getFactory().getTypeConfiguration().getJavaTypeRegistry()
669+
return getTypeConfiguration().getJavaTypeRegistry()
656670
.getDescriptor( javaType );
657671
}
658672

@@ -667,7 +681,7 @@ else if ( parameter.getPosition() != null ) {
667681
return locateBinding( parameter.getPosition() );
668682
}
669683

670-
throw getSession().getExceptionConverter().convert(
684+
throw getExceptionConverter().convert(
671685
new IllegalArgumentException( "Could not resolve binding for given parameter reference [" + parameter + "]" )
672686
);
673687
}
@@ -788,7 +802,7 @@ private boolean isInstance(Type<?> parameterType, Object value) {
788802
}
789803

790804
private NodeBuilder getNodeuilder() {
791-
return getSession().getFactory().getQueryEngine().getCriteriaBuilder();
805+
return getSessionFactory().getQueryEngine().getCriteriaBuilder();
792806
}
793807

794808
@Override
@@ -835,7 +849,7 @@ public CommonQueryContract setParameter(int position, Object value) {
835849
}
836850

837851
private boolean isRegisteredAsBasicType(Class<?> valueClass) {
838-
return getSession().getFactory().getTypeConfiguration().getBasicTypeForJavaType( valueClass ) != null;
852+
return getTypeConfiguration().getBasicTypeForJavaType( valueClass ) != null;
839853
}
840854

841855
@Override
@@ -1028,14 +1042,16 @@ public <P> CommonQueryContract setParameterList(int position, Collection<? exten
10281042
}
10291043

10301044
private <P> Type<P> getParamType(Class<P> javaType) {
1031-
final TypeConfiguration typeConfiguration = getSession().getFactory().getTypeConfiguration();
1032-
final BasicType<P> basicType = typeConfiguration.standardBasicTypeForJavaType( javaType );
1045+
final BasicType<P> basicType =
1046+
getTypeConfiguration()
1047+
.standardBasicTypeForJavaType( javaType );
10331048
if ( basicType != null ) {
10341049
return basicType;
10351050
}
10361051
else {
1037-
final JpaMetamodel metamodel = getSession().getFactory().getJpaMetamodel();
1038-
final ManagedDomainType<P> managedDomainType = metamodel.managedType( javaType );
1052+
final ManagedDomainType<P> managedDomainType =
1053+
getSessionFactory().getJpaMetamodel()
1054+
.managedType( javaType );
10391055
if ( managedDomainType != null ) {
10401056
return managedDomainType;
10411057
}
@@ -1157,7 +1173,7 @@ protected <T> Type<T> determineType(String namedParam, Class<? extends T> retTyp
11571173
type = getParameterMetadata().getQueryParameter( namedParam ).getHibernateType();
11581174
}
11591175
if ( type == null && retType != null ) {
1160-
type = getSession().getFactory().getMappingMetamodel().resolveParameterBindType( retType );
1176+
type = getSessionFactory().getMappingMetamodel().resolveParameterBindType( retType );
11611177
}
11621178
if ( retType!= null && !retType.isAssignableFrom( type.getJavaType() ) ) {
11631179
throw new IllegalStateException( "Parameter not of expected type: " + retType.getName() );

hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ public int executeUpdate() throws HibernateException {
646646
throw new IllegalStateException( e );
647647
}
648648
catch (HibernateException e) {
649-
throw getSession().getExceptionConverter().convert( e );
649+
throw getExceptionConverter().convert( e );
650650
}
651651
finally {
652652
afterQueryHandlingFetchProfiles( success, fetchProfiles );

hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.hibernate.NonUniqueResultException;
3030
import org.hibernate.ScrollMode;
3131
import org.hibernate.UnknownProfileException;
32-
import org.hibernate.engine.spi.SessionFactoryImplementor;
3332
import org.hibernate.engine.spi.SharedSessionContractImplementor;
3433
import org.hibernate.graph.GraphSemantic;
3534
import org.hibernate.graph.spi.AppliedGraph;
@@ -150,7 +149,7 @@ public List<R> list() {
150149
throw new IllegalStateException( e );
151150
}
152151
catch (HibernateException he) {
153-
throw getSession().getExceptionConverter().convert( he, getQueryOptions().getLockOptions() );
152+
throw getExceptionConverter().convert( he, getQueryOptions().getLockOptions() );
154153
}
155154
finally {
156155
afterQueryHandlingFetchProfiles( success, fetchProfiles );
@@ -279,7 +278,7 @@ public R getSingleResult() {
279278
return uniqueElement( list );
280279
}
281280
catch ( HibernateException e ) {
282-
throw getSession().getExceptionConverter().convert( e, getQueryOptions().getLockOptions() );
281+
throw getExceptionConverter().convert( e, getQueryOptions().getLockOptions() );
283282
}
284283
}
285284

@@ -311,7 +310,7 @@ public R getSingleResultOrNull() {
311310
return uniqueElement( list() );
312311
}
313312
catch ( HibernateException e ) {
314-
throw getSession().getExceptionConverter().convert( e, getLockOptions() );
313+
throw getExceptionConverter().convert( e, getLockOptions() );
315314
}
316315
}
317316

@@ -383,7 +382,7 @@ public SelectionQuery<R> setEntityGraph(EntityGraph<? super R> graph, GraphSeman
383382

384383
@Override
385384
public SelectionQuery<R> enableFetchProfile(String profileName) {
386-
if ( getSession().getFactory().containsFetchProfileDefinition( profileName ) ) {
385+
if ( this.getSessionFactory().containsFetchProfileDefinition( profileName ) ) {
387386
getQueryOptions().enableFetchProfile( profileName );
388387
return this;
389388
}
@@ -837,8 +836,4 @@ public SelectionQuery<R> setProperties(Object bean) {
837836
super.setProperties( bean );
838837
return this;
839838
}
840-
841-
public SessionFactoryImplementor getSessionFactory() {
842-
return getSession().getFactory();
843-
}
844839
}

hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ private boolean shouldFlush() {
691691
final FlushMode flushMode = getQueryOptions().getFlushMode();
692692
return switch ( flushMode == null ? getSession().getHibernateFlushMode() : flushMode ) {
693693
// The JPA spec requires that we auto-flush before native queries
694-
case AUTO -> getSession().getFactory().getSessionFactoryOptions().isJpaBootstrap();
694+
case AUTO -> getSessionFactory().getSessionFactoryOptions().isJpaBootstrap();
695695
case ALWAYS -> true;
696696
default -> false;
697697
};

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public int executeUpdate() {
520520
throw new IllegalStateException( e );
521521
}
522522
catch (HibernateException e) {
523-
throw getSession().getExceptionConverter().convert( e );
523+
throw getExceptionConverter().convert( e );
524524
}
525525
finally {
526526
afterQueryHandlingFetchProfiles( success, fetchProfiles );

0 commit comments

Comments
 (0)