1515import org .hibernate .HibernateException ;
1616import org .hibernate .QueryException ;
1717import org .hibernate .boot .Metadata ;
18- import org .hibernate .boot .query .NamedHqlQueryDefinition ;
19- import org .hibernate .boot .query .NamedNativeQueryDefinition ;
20- import org .hibernate .boot .query .NamedProcedureCallDefinition ;
2118import org .hibernate .boot .spi .MetadataImplementor ;
2219import org .hibernate .engine .spi .SessionFactoryImplementor ;
2320import org .hibernate .procedure .spi .NamedCallableQueryMemento ;
3330import org .hibernate .query .named .NamedQueryMemento ;
3431import org .hibernate .query .named .NamedResultSetMappingMemento ;
3532import org .hibernate .query .spi .QueryEngine ;
36- import org .hibernate .query .spi .QueryInterpretationCache ;
3733import org .hibernate .query .sql .spi .NamedNativeQueryMemento ;
3834import org .hibernate .query .sqm .UnknownEntityException ;
3935import org .hibernate .query .sqm .UnknownPathException ;
@@ -70,13 +66,14 @@ public NamedObjectRepositoryImpl(
7066 @ Override
7167 @ SuppressWarnings ("unchecked" )
7268 public <R > Map <String , TypedQueryReference <R >> getNamedQueries (Class <R > resultType ) {
73- final Map <String , TypedQueryReference <R >> namedQueries = new HashMap <>( sqmMementoMap .size () + sqlMementoMap .size () );
74- for ( Map .Entry <String , NamedSqmQueryMemento <?>> entry : sqmMementoMap .entrySet () ) {
69+ final Map <String , TypedQueryReference <R >> namedQueries =
70+ new HashMap <>( sqmMementoMap .size () + sqlMementoMap .size () );
71+ for ( var entry : sqmMementoMap .entrySet () ) {
7572 if ( resultType == entry .getValue ().getResultType () ) {
7673 namedQueries .put ( entry .getKey (), (TypedQueryReference <R >) entry .getValue () );
7774 }
7875 }
79- for ( Map . Entry < String , NamedNativeQueryMemento <?>> entry : sqlMementoMap .entrySet () ) {
76+ for ( var entry : sqlMementoMap .entrySet () ) {
8077 if ( resultType == entry .getValue ().getResultType () ) {
8178 namedQueries .put ( entry .getKey (), (TypedQueryReference <R >) entry .getValue () );
8279 }
@@ -106,7 +103,6 @@ public void registerNamedQuery(String name, Query query) {
106103 if ( queryImplementor != null ) {
107104 if ( queryImplementor instanceof NativeQueryImplementor <?> nativeQueryImplementor ) {
108105 registerNativeQueryMemento ( name , nativeQueryImplementor .toMemento ( name ) );
109-
110106 }
111107 else if ( queryImplementor instanceof SqmQueryImplementor <?> sqmQueryImplementor ) {
112108 registerSqmQueryMemento ( name , sqmQueryImplementor .toMemento ( name ) );
@@ -127,12 +123,12 @@ else if ( queryImplementor instanceof SqmQueryImplementor<?> sqmQueryImplementor
127123 @ Override
128124 public <R > TypedQueryReference <R > registerNamedQuery (String name , TypedQuery <R > query ) {
129125 if ( query instanceof NativeQueryImplementor <R > nativeQueryImplementor ) {
130- final NamedNativeQueryMemento < R > memento = nativeQueryImplementor .toMemento ( name );
126+ final var memento = nativeQueryImplementor .toMemento ( name );
131127 registerNativeQueryMemento ( name , memento );
132128 return memento ;
133129 }
134130 else if ( query instanceof SqmQueryImplementor <R > sqmQueryImplementor ) {
135- final NamedSqmQueryMemento < R > memento = sqmQueryImplementor .toMemento ( name );
131+ final var memento = sqmQueryImplementor .toMemento ( name );
136132 registerSqmQueryMemento ( name , memento );
137133 return memento ;
138134 }
@@ -238,55 +234,51 @@ public NamedQueryMemento<?> resolve(
238234 if ( namedQuery != null ) {
239235 return namedQuery ;
240236 }
241- final NamedHqlQueryDefinition <?> namedHqlQueryDefinition = bootMetamodel .getNamedHqlQueryMapping ( registrationName );
237+ final var namedHqlQueryDefinition = bootMetamodel .getNamedHqlQueryMapping ( registrationName );
242238 if ( namedHqlQueryDefinition != null ) {
243- final NamedSqmQueryMemento <?> resolved = namedHqlQueryDefinition .resolve ( sessionFactory );
244- sqmMementoMap .put ( namedHqlQueryDefinition .getRegistrationName (), resolved );
245- return resolved ;
239+ final var memento = namedHqlQueryDefinition .resolve ( sessionFactory );
240+ sqmMementoMap .put ( namedHqlQueryDefinition .getRegistrationName (), memento );
241+ return memento ;
246242 }
247- final NamedNativeQueryDefinition <?> namedNativeQueryDefinition = bootMetamodel .getNamedNativeQueryMapping ( registrationName );
243+ final var namedNativeQueryDefinition = bootMetamodel .getNamedNativeQueryMapping ( registrationName );
248244 if ( namedNativeQueryDefinition != null ) {
249- final NamedNativeQueryMemento <?> resolved = namedNativeQueryDefinition .resolve ( sessionFactory );
250- sqlMementoMap .put ( namedNativeQueryDefinition .getRegistrationName (), resolved );
251- return resolved ;
245+ final var memento = namedNativeQueryDefinition .resolve ( sessionFactory );
246+ sqlMementoMap .put ( namedNativeQueryDefinition .getRegistrationName (), memento );
247+ return memento ;
252248 }
253- final NamedProcedureCallDefinition namedCallableQueryDefinition = bootMetamodel .getNamedProcedureCallMapping ( registrationName );
249+ final var namedCallableQueryDefinition = bootMetamodel .getNamedProcedureCallMapping ( registrationName );
254250 if ( namedCallableQueryDefinition != null ) {
255- final NamedCallableQueryMemento resolved = namedCallableQueryDefinition .resolve ( sessionFactory );
256- callableMementoMap .put ( namedCallableQueryDefinition .getRegistrationName (), resolved );
257- return resolved ;
251+ final var memento = namedCallableQueryDefinition .resolve ( sessionFactory );
252+ callableMementoMap .put ( namedCallableQueryDefinition .getRegistrationName (), memento );
253+ return memento ;
258254 }
259255 return null ;
260256 }
261257
262258 @ Override
263259 public void prepare (SessionFactoryImplementor sessionFactory , Metadata bootMetamodel ) {
264260 bootMetamodel .visitNamedHqlQueryDefinitions (
265- namedHqlQueryDefinition -> {
266- final NamedSqmQueryMemento <?> resolved = namedHqlQueryDefinition .resolve ( sessionFactory );
267- sqmMementoMap .put ( namedHqlQueryDefinition .getRegistrationName (), resolved );
268- }
261+ namedHqlQueryDefinition ->
262+ sqmMementoMap .put ( namedHqlQueryDefinition .getRegistrationName (),
263+ namedHqlQueryDefinition .resolve ( sessionFactory ) )
269264 );
270265
271266 bootMetamodel .visitNamedNativeQueryDefinitions (
272- namedNativeQueryDefinition -> {
273- final NamedNativeQueryMemento <?> resolved = namedNativeQueryDefinition .resolve ( sessionFactory );
274- sqlMementoMap .put ( namedNativeQueryDefinition .getRegistrationName (), resolved );
275- }
267+ namedNativeQueryDefinition ->
268+ sqlMementoMap .put ( namedNativeQueryDefinition .getRegistrationName (),
269+ namedNativeQueryDefinition .resolve ( sessionFactory ) )
276270 );
277271
278272 bootMetamodel .visitNamedResultSetMappingDefinition (
279- namedResultSetMappingDefinition -> {
280- final NamedResultSetMappingMemento resolved = namedResultSetMappingDefinition .resolve ( () -> sessionFactory );
281- resultSetMappingMementoMap .put ( namedResultSetMappingDefinition .getRegistrationName (), resolved );
282- }
273+ namedResultSetMappingDefinition ->
274+ resultSetMappingMementoMap .put ( namedResultSetMappingDefinition .getRegistrationName (),
275+ namedResultSetMappingDefinition .resolve ( () -> sessionFactory ) )
283276 );
284277
285278 bootMetamodel .visitNamedProcedureCallDefinition (
286- namedProcedureCallDefinition -> {
287- final NamedCallableQueryMemento resolved = namedProcedureCallDefinition .resolve ( sessionFactory );
288- callableMementoMap .put ( namedProcedureCallDefinition .getRegistrationName (), resolved );
289- }
279+ namedProcedureCallDefinition ->
280+ callableMementoMap .put ( namedProcedureCallDefinition .getRegistrationName (),
281+ namedProcedureCallDefinition .resolve ( sessionFactory ) )
290282 );
291283
292284 }
@@ -297,18 +289,17 @@ public void prepare(SessionFactoryImplementor sessionFactory, Metadata bootMetam
297289
298290 @ Override
299291 public void validateNamedQueries (QueryEngine queryEngine ) {
300- final Map < String , HibernateException > errors = checkNamedQueries ( queryEngine );
292+ final var errors = checkNamedQueries ( queryEngine );
301293 if ( !errors .isEmpty () ) {
302294 int i = 0 ;
303295 final StringBuilder failingQueries = new StringBuilder ( "Errors in named queries: " );
304- for ( Map . Entry < String , HibernateException > entry : errors .entrySet () ) {
296+ for ( var entry : errors .entrySet () ) {
305297 QUERY_MESSAGE_LOGGER .namedQueryError ( entry .getKey (), entry .getValue () );
306298 failingQueries .append ( "\n " )
307299 .append (" [" ).append (++i ).append ("] Error in query named '" ).append ( entry .getKey () ).append ("'" )
308300 .append (": " ).append ( entry .getValue ().getMessage () );
309301 }
310- final NamedQueryValidationException exception =
311- new NamedQueryValidationException ( failingQueries .toString (), errors );
302+ final var exception = new NamedQueryValidationException ( failingQueries .toString (), errors );
312303 errors .values ().forEach ( exception ::addSuppressed );
313304 throw exception ;
314305 }
@@ -318,20 +309,17 @@ public void validateNamedQueries(QueryEngine queryEngine) {
318309 public Map <String , HibernateException > checkNamedQueries (QueryEngine queryEngine ) {
319310 Map <String ,HibernateException > errors = new HashMap <>();
320311
321- final QueryInterpretationCache interpretationCache = queryEngine .getInterpretationCache ();
312+ final var interpretationCache = queryEngine .getInterpretationCache ();
313+ final var hqlTranslator = queryEngine .getHqlTranslator ();
322314
323315 // Check named HQL queries
324316 log .tracef ( "Checking %s named HQL queries" , sqmMementoMap .size () );
325- for ( NamedSqmQueryMemento <?> hqlMemento : sqmMementoMap .values () ) {
317+ for ( var hqlMemento : sqmMementoMap .values () ) {
326318 final String queryString = hqlMemento .getHqlString ();
327319 final String registrationName = hqlMemento .getRegistrationName ();
328320 try {
329321 log .tracef ( "Checking named HQL query: %s" , registrationName );
330- interpretationCache .resolveHqlInterpretation (
331- queryString ,
332- null ,
333- queryEngine .getHqlTranslator ()
334- );
322+ interpretationCache .resolveHqlInterpretation ( queryString , null , hqlTranslator );
335323 }
336324 catch ( QueryException e ) {
337325 errors .put ( registrationName , e );
0 commit comments