From a1e3f0cd6f418766198a53212c76f8b950964539 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 9 Dec 2021 15:41:52 +0100 Subject: [PATCH] fix some warnings and clean up some typing issues this is a general cleanup of the Session + Query hierarchies --- .../src/main/java/org/hibernate/Session.java | 44 ++++++--- .../org/hibernate/SharedSessionContract.java | 55 +++++------ .../java/org/hibernate/StatelessSession.java | 8 +- .../engine/spi/SessionDelegatorBaseImpl.java | 81 +++++++-------- .../engine/spi/SessionImplementor.java | 78 +++++++-------- .../spi/SharedSessionContractImplementor.java | 3 +- .../AbstractSharedSessionContract.java | 58 +++++------ .../org/hibernate/internal/SessionImpl.java | 9 +- .../internal/StatelessSessionImpl.java | 2 +- .../java/org/hibernate/query/NativeQuery.java | 2 +- .../main/java/org/hibernate/query/Query.java | 99 +------------------ .../org/hibernate/query/QueryProducer.java | 35 +++++-- .../hibernate/query/spi/AbstractQuery.java | 5 +- .../query/spi/QueryProducerImplementor.java | 21 ++-- .../query/sql/internal/NativeQueryImpl.java | 4 +- .../query/sql/spi/NativeQueryImplementor.java | 2 +- .../query/sqm/internal/QuerySqmImpl.java | 19 ++-- 17 files changed, 221 insertions(+), 304 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/Session.java b/hibernate-core/src/main/java/org/hibernate/Session.java index 0001ee22b8..84d77762ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/Session.java +++ b/hibernate-core/src/main/java/org/hibernate/Session.java @@ -6,7 +6,6 @@ */ package org.hibernate; -import java.io.Closeable; import java.util.List; import jakarta.persistence.EntityGraph; import jakarta.persistence.EntityManager; @@ -14,7 +13,6 @@ import jakarta.persistence.FlushModeType; import jakarta.persistence.criteria.CriteriaDelete; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaUpdate; - import org.hibernate.graph.RootGraph; import org.hibernate.stat.SessionStatistics; @@ -79,7 +77,7 @@ import org.hibernate.stat.SessionStatistics; * @author Gavin King * @author Steve Ebersole */ -public interface Session extends SharedSessionContract, EntityManager, AutoCloseable, Closeable { +public interface Session extends SharedSessionContract, EntityManager { /** * Obtain a {@link Session} builder with the ability to grab certain information from this session. * @@ -956,9 +954,8 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose RootGraph getEntityGraph(String graphName); @Override - @SuppressWarnings({"unchecked", "RedundantCast"}) default List> getEntityGraphs(Class entityClass) { - return (List) getSessionFactory().findEntityGraphsByType( entityClass ); + return getSessionFactory().findEntityGraphsByType( entityClass ); } /** @@ -1092,21 +1089,36 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose */ void addEventListeners(SessionEventListener... listeners); - @Override - org.hibernate.query.Query createQuery(String queryString, Class resultType); + // The following declarations just override the JPA return type with our + // Hibernate Query type, as required by the declaration in QueryProducer - // Override the JPA return type with the one exposed in QueryProducer - @Override - org.hibernate.query.Query createQuery(CriteriaQuery criteriaQuery); + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + org.hibernate.query.Query getNamedQuery(String queryString); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + org.hibernate.query.Query createQuery(String queryString); - // Override the JPA return type with the one exposed in QueryProducer @Override + org.hibernate.query.Query createQuery(String queryString, Class resultType); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + org.hibernate.query.Query createNamedQuery(String queryString); + + @Override + org.hibernate.query.Query createNamedQuery(String name, Class resultType); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + org.hibernate.query.NativeQuery createNativeQuery(String queryString); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + org.hibernate.query.NativeQuery createNativeQuery(String queryString, String resultSetMappingName); + + @Override + org.hibernate.query.Query createQuery(CriteriaQuery criteriaQuery); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) org.hibernate.query.Query createQuery(CriteriaUpdate updateQuery); - // Override the JPA return type with the one exposed in QueryProducer - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery); - - - org.hibernate.query.Query createNamedQuery(String name, Class resultType); } diff --git a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java index 9f07f6ec42..4829cfe8ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java @@ -6,30 +6,23 @@ */ package org.hibernate; +import java.io.Closeable; import java.io.Serializable; -import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.criteria.CriteriaBuilder; -import jakarta.persistence.criteria.CriteriaDelete; -import jakarta.persistence.criteria.CriteriaQuery; -import jakarta.persistence.criteria.CriteriaUpdate; import org.hibernate.jdbc.ReturningWork; import org.hibernate.jdbc.Work; import org.hibernate.procedure.ProcedureCall; import org.hibernate.query.QueryProducer; -import org.hibernate.query.UnknownSqlResultSetMappingException; import org.hibernate.query.criteria.HibernateCriteriaBuilder; /** - * Contract methods shared between {@link Session} and {@link StatelessSession}. - *

- * NOTE : Poorly named. "shared" simply indicates that its a unified contract between {@link Session} and - * {@link StatelessSession}. - * + * Declares operations that are common between {@link Session} and {@link StatelessSession}. + * * @author Steve Ebersole */ -public interface SharedSessionContract extends QueryProducer, Serializable { +public interface SharedSessionContract extends QueryProducer, Closeable, Serializable { /** * Obtain the tenant identifier associated with this session. * @@ -77,12 +70,6 @@ public interface SharedSessionContract extends QueryProducer, Serializable { */ Transaction getTransaction(); - @Override - org.hibernate.query.Query createQuery(String queryString); - - @Override - org.hibernate.query.Query getNamedQuery(String queryName); - /** * Gets a ProcedureCall based on a named template * @@ -112,7 +99,7 @@ public interface SharedSessionContract extends QueryProducer, Serializable { * * @return The representation of the procedure call. */ - ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses); + ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses); /** * Creates a call to a stored procedure with specific result set entity mappings. @@ -153,7 +140,7 @@ public interface SharedSessionContract extends QueryProducer, Serializable { * * @return The representation of the procedure call. */ - ProcedureCall createStoredProcedureQuery(String procedureName, Class... resultClasses); + ProcedureCall createStoredProcedureQuery(String procedureName, Class... resultClasses); /** * Creates a call to a stored procedure with specific result set entity mappings. @@ -198,17 +185,21 @@ public interface SharedSessionContract extends QueryProducer, Serializable { * @throws IllegalStateException if the StatelessSession has been closed */ HibernateCriteriaBuilder getCriteriaBuilder(); - - @Override - org.hibernate.query.Query createQuery(String queryString, Class resultType); - - org.hibernate.query.Query createQuery(CriteriaQuery criteriaQuery); - - org.hibernate.query.Query createQuery(CriteriaUpdate updateQuery); - - org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery); - - org.hibernate.query.Query createNamedQuery(String name, Class resultType); +// +// @Override +// org.hibernate.query.Query createQuery(String queryString, Class resultType); +// +// @Override +// org.hibernate.query.Query createQuery(CriteriaQuery criteriaQuery); +// +// @Override +// org.hibernate.query.Query createQuery(CriteriaUpdate updateQuery); +// +// @Override +// org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery); +// +// @Override +// org.hibernate.query.Query createNamedQuery(String name, Class resultType); /** * Controller for allowing users to perform JDBC related work using the Connection managed by this Session. @@ -217,7 +208,7 @@ public interface SharedSessionContract extends QueryProducer, Serializable { * @throws HibernateException Generally indicates wrapped {@link java.sql.SQLException} */ default void doWork(Work work) throws HibernateException { - throw new UnsupportedOperationException( "The doWork method has not been implemented in this implementation of org.hibernate.engine.spi.SharedSessionContractImplemento" ); + throw new UnsupportedOperationException( "The doWork method has not been implemented in this implementation of org.hibernate.engine.spi.SharedSessionContractImplementor" ); } /** @@ -232,7 +223,7 @@ public interface SharedSessionContract extends QueryProducer, Serializable { * @throws HibernateException Generally indicates wrapped {@link java.sql.SQLException} */ default T doReturningWork(ReturningWork work) throws HibernateException { - throw new UnsupportedOperationException( "The doReturningWork method has not been implemented in this implementation of org.hibernate.engine.spi.SharedSessionContractImplemento" ); + throw new UnsupportedOperationException( "The doReturningWork method has not been implemented in this implementation of org.hibernate.engine.spi.SharedSessionContractImplementor" ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/StatelessSession.java b/hibernate-core/src/main/java/org/hibernate/StatelessSession.java index fcb32eac7f..c13551a7c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/StatelessSession.java +++ b/hibernate-core/src/main/java/org/hibernate/StatelessSession.java @@ -6,8 +6,6 @@ */ package org.hibernate; -import java.io.Closeable; - /** * A command-oriented API for performing bulk operations against a database. *

@@ -24,7 +22,7 @@ import java.io.Closeable; * * @author Gavin King */ -public interface StatelessSession extends SharedSessionContract, AutoCloseable, Closeable { +public interface StatelessSession extends SharedSessionContract { /** * Close the stateless session and release the JDBC connection. */ @@ -97,7 +95,7 @@ public interface StatelessSession extends SharedSessionContract, AutoCloseable, * * @return a detached entity instance */ - Object get(Class entityClass, Object id); + T get(Class entityClass, Object id); /** * Retrieve a row, obtaining the specified lock mode. @@ -119,7 +117,7 @@ public interface StatelessSession extends SharedSessionContract, AutoCloseable, * * @return a detached entity instance */ - Object get(Class entityClass, Object id, LockMode lockMode); + T get(Class entityClass, Object id, LockMode lockMode); /** * Refresh the entity instance state from the database. diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java index 0a5f3678fe..76f3942452 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java @@ -6,7 +6,6 @@ */ package org.hibernate.engine.spi; -import java.sql.Connection; import java.util.List; import java.util.Map; import java.util.Set; @@ -16,7 +15,6 @@ import jakarta.persistence.EntityGraph; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.FlushModeType; import jakarta.persistence.LockModeType; -import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.criteria.CriteriaDelete; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaUpdate; @@ -54,6 +52,7 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.procedure.ProcedureCall; import org.hibernate.query.criteria.HibernateCriteriaBuilder; import org.hibernate.query.spi.QueryImplementor; +import org.hibernate.query.spi.QueryProducerImplementor; import org.hibernate.query.sql.spi.NativeQueryImplementor; import org.hibernate.resource.jdbc.spi.JdbcSessionContext; import org.hibernate.resource.transaction.spi.TransactionCoordinator; @@ -134,7 +133,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { } @Override - public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException { + public void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException { delegate.initializeCollection( collection, writing ); } @@ -448,29 +447,8 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { return delegate.getEntityGraphs( entityClass ); } - @Override - public QueryImplementor getNamedQuery(String name) { - return delegate.getNamedQuery( name ); - } - - @Override - public NativeQueryImplementor getNamedNativeQuery(String name) { - return delegate.getNamedNativeQuery( name ); - } - - @Override - public NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping) { - return delegate.getNamedNativeQuery( name, resultSetMapping ); - } - - @Override - public QueryImplementor createQuery(String queryString) { - return delegate.createQuery( queryString ); - } - - @Override - public QueryImplementor createQuery(String queryString, Class resultType) { - return delegate.createQuery( queryString, resultType ); + private QueryProducerImplementor queryDelegate() { + return delegate; } @Override @@ -478,39 +456,64 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { return delegate.createQuery( criteriaQuery ); } - @Override + @Override @SuppressWarnings("rawtypes") public QueryImplementor createQuery(CriteriaUpdate updateQuery) { return delegate.createQuery( updateQuery ); } - @Override + @Override @SuppressWarnings("rawtypes") public QueryImplementor createQuery(CriteriaDelete deleteQuery) { return delegate.createQuery( deleteQuery ); } + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + public QueryImplementor getNamedQuery(String name) { + return queryDelegate().getNamedQuery( name ); + } + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + public NativeQueryImplementor getNamedNativeQuery(String name) { + return queryDelegate().getNamedNativeQuery( name ); + } + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + public NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping) { + return queryDelegate().getNamedNativeQuery( name, resultSetMapping ); + } + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + public QueryImplementor createQuery(String queryString) { + return queryDelegate().createQuery( queryString ); + } + @Override + public QueryImplementor createQuery(String queryString, Class resultType) { + return queryDelegate().createQuery( queryString, resultType ); + } + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public QueryImplementor createNamedQuery(String name) { - return delegate.createNamedQuery( name ); + return queryDelegate().createNamedQuery( name ); } @Override public QueryImplementor createNamedQuery(String name, Class resultClass) { - return delegate.createNamedQuery( name, resultClass ); + return queryDelegate().createNamedQuery( name, resultClass ); } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public NativeQueryImplementor createNativeQuery(String sqlString) { - return delegate.createNativeQuery( sqlString ); + return queryDelegate().createNativeQuery( sqlString ); } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass) { - return delegate.createNativeQuery( sqlString, resultClass ); + return queryDelegate().createNativeQuery( sqlString, resultClass ); } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName) { - return delegate.createNativeQuery( sqlString, resultSetMappingName ); + return queryDelegate().createNativeQuery( sqlString, resultSetMappingName ); } @Override @@ -578,7 +581,7 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { } @Override - public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { + public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { return delegate.createStoredProcedureCall( procedureName, resultClasses ); } @@ -733,12 +736,12 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { } @Override - public Object merge(Object object) { + public T merge(T object) { return delegate.merge( object ); } @Override - public Object merge(String entityName, Object object) { + public T merge(String entityName, T object) { return delegate.merge( entityName, object ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java index 1d806c3c6b..ba371ca467 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java @@ -26,7 +26,8 @@ import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; * {@link org.hibernate.type.Type}, {@link EntityPersister} * and {@link org.hibernate.persister.collection.CollectionPersister} implementations. * - * A Session, through this interface and SharedSessionContractImplementor, implements:

    + * A Session, through this interface and SharedSessionContractImplementor, implements: + *
      *
    • * {@link org.hibernate.resource.jdbc.spi.JdbcSessionOwner} to drive the behavior of the * {@link org.hibernate.resource.jdbc.spi.JdbcSessionContext} delegate @@ -82,46 +83,6 @@ public interface SessionImplementor extends Session, SharedSessionContractImplem void forceFlush(EntityEntry e) throws HibernateException; - @Override - QueryImplementor createQuery(String queryString); - - @Override - QueryImplementor createQuery(String queryString, Class resultType); - - @Override - QueryImplementor createNamedQuery(String name, Class resultType); - - @Override - QueryImplementor createNamedQuery(String name); - - @Override - NativeQueryImplementor createNativeQuery(String sqlString); - - @Override - @SuppressWarnings("unchecked") - NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass); - - @Override - NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName); - - @Override - NativeQueryImplementor getNamedNativeQuery(String name); - - @Override - NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping); - - @Override - QueryImplementor getNamedQuery(String queryName); - - @Override - QueryImplementor createQuery(CriteriaQuery criteriaQuery); - - @Override - QueryImplementor createQuery(CriteriaUpdate updateQuery); - - @Override - QueryImplementor createQuery(CriteriaDelete deleteQuery); - /** * @deprecated OperationalContext should cover this overload I believe; Gail? */ @@ -157,4 +118,39 @@ public interface SessionImplementor extends Session, SharedSessionContractImplem */ @Deprecated void removeOrphanBeforeUpdates(String entityName, Object child); + + + // The following declarations just override the JPA return type with our + // Hibernate QueryImplementor type, as required by the declaration in + // QueryProducerImplementor + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + QueryImplementor getNamedQuery(String queryString); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + QueryImplementor createQuery(String queryString); + + @Override + QueryImplementor createQuery(String queryString, Class resultType); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + QueryImplementor createNamedQuery(String queryString); + + @Override + QueryImplementor createNamedQuery(String name, Class resultType); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + NativeQueryImplementor createNativeQuery(String queryString); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + NativeQueryImplementor createNativeQuery(String queryString, String resultSetMappingName); + + @Override + QueryImplementor createQuery(CriteriaQuery criteriaQuery); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + QueryImplementor createQuery(CriteriaUpdate updateQuery); + + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + QueryImplementor createQuery(CriteriaDelete deleteQuery); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java index 9afcb29edc..46d586ac89 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java @@ -259,7 +259,7 @@ public interface SharedSessionContractImplementor /** * Initialize the collection (if not already initialized) */ - void initializeCollection(PersistentCollection collection, boolean writing) + void initializeCollection(PersistentCollection collection, boolean writing) throws HibernateException; /** @@ -301,7 +301,6 @@ public interface SharedSessionContractImplementor /** * Return the identifier of the persistent object, or null if * not associated with the session - * @return */ Object getContextEntityIdentifier(Object object); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index e1ffb2e78a..5ce00ddbc7 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -68,7 +68,6 @@ import org.hibernate.query.sql.internal.NativeQueryImpl; import org.hibernate.query.sql.spi.NamedNativeQueryMemento; import org.hibernate.query.sql.spi.NativeQueryImplementor; import org.hibernate.query.sqm.internal.QuerySqmImpl; -import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; import org.hibernate.query.sqm.tree.select.SqmQueryGroup; import org.hibernate.query.sqm.tree.select.SqmQuerySpec; @@ -216,7 +215,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont * Override the implementation provided on SharedSessionContractImplementor * which is not very efficient: this method is hot in Hibernate Reactive, and could * be hot in some ORM contexts as well. - * @return */ @Override public Integer getConfiguredJdbcBatchSize() { @@ -255,7 +253,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont if ( statementInspector == null ) { // If there is no StatementInspector specified, map to the call // to the (deprecated) Interceptor#onPrepareStatement method - return (StatementInspector) interceptor::onPrepareStatement; + return interceptor::onPrepareStatement; } return statementInspector; } @@ -635,13 +633,12 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // dynamic HQL handling - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public QueryImplementor createQuery(String queryString) { return createQuery( queryString, null ); } @Override - @SuppressWarnings("unchecked") public QueryImplementor createQuery(String queryString, Class resultClass) { checkOpen(); pulseTransactionCoordinator(); @@ -676,18 +673,14 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // dynamic native (SQL) query handling - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public NativeQueryImplementor createNativeQuery(String sqlString) { - return getNativeQueryImplementor( sqlString ); - } - - protected NativeQueryImplementor getNativeQueryImplementor(String queryString) { checkOpen(); pulseTransactionCoordinator(); delayedAfterCompletion(); try { - NativeQueryImpl query = new NativeQueryImpl( queryString, this ); + NativeQueryImpl query = new NativeQueryImpl<>(sqlString, this); if ( StringHelper.isEmpty( query.getComment() ) ) { query.setComment( "dynamic native SQL query" ); } @@ -699,8 +692,9 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } - @Override - @SuppressWarnings("unchecked") + @Override @SuppressWarnings({"rawtypes", "unchecked"}) + //note: we're doing something a bit funny here to work around + // the classing signatures declared by the supertypes public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass) { checkOpen(); pulseTransactionCoordinator(); @@ -721,13 +715,13 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName) { checkOpen(); pulseTransactionCoordinator(); delayedAfterCompletion(); - final NativeQueryImplementor query; + final NativeQueryImplementor query; try { if ( StringHelper.isNotEmpty( resultSetMappingName ) ) { final NamedResultSetMappingMemento resultSetMappingMemento = getFactory().getQueryEngine() @@ -738,10 +732,10 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont throw new HibernateException( "Could not resolve specified result-set mapping name : " + resultSetMappingName ); } - query = new NativeQueryImpl( sqlString, resultSetMappingMemento, this ); + query = new NativeQueryImpl<>( sqlString, resultSetMappingMemento, this ); } else { - query = new NativeQueryImpl( sqlString, this ); + query = new NativeQueryImpl<>( sqlString, this ); } } catch (RuntimeException he) { @@ -755,12 +749,12 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // named query handling - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public QueryImplementor getNamedQuery(String queryName) { return buildNamedQuery( queryName, null ); } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public QueryImplementor createNamedQuery(String name) { return buildNamedQuery( name, null ); } @@ -847,10 +841,10 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } - protected void applyQuerySettingsAndHints(Query query) { + protected void applyQuerySettingsAndHints(Query query) { } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public NativeQueryImplementor getNamedNativeQuery(String queryName) { final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine() .getNamedObjectRepository() @@ -863,7 +857,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont throw getExceptionConverter().convert( new IllegalArgumentException( "No query defined for that name [" + queryName + "]" ) ); } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public NativeQueryImplementor getNamedNativeQuery(String queryName, String resultSetMapping) { final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine() .getNamedObjectRepository() @@ -905,16 +899,16 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont @SuppressWarnings("UnnecessaryLocalVariable") public ProcedureCall createStoredProcedureCall(String procedureName) { checkOpen(); - final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName ); + final ProcedureCall procedureCall = new ProcedureCallImpl<>( this, procedureName ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; } @Override @SuppressWarnings("UnnecessaryLocalVariable") - public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { + public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { checkOpen(); - final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName, resultClasses ); + final ProcedureCall procedureCall = new ProcedureCallImpl<>( this, procedureName, resultClasses ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; } @@ -923,7 +917,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont @SuppressWarnings("UnnecessaryLocalVariable") public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) { checkOpen(); - final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName, resultSetMappings ); + final ProcedureCall procedureCall = new ProcedureCallImpl<>( this, procedureName, resultSetMappings ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; } @@ -932,16 +926,16 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont @SuppressWarnings("UnnecessaryLocalVariable") public ProcedureCall createStoredProcedureQuery(String procedureName) { checkOpen(); - final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName ); + final ProcedureCall procedureCall = new ProcedureCallImpl<>( this, procedureName ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; } @Override @SuppressWarnings("UnnecessaryLocalVariable") - public ProcedureCall createStoredProcedureQuery(String procedureName, Class... resultClasses) { + public ProcedureCall createStoredProcedureQuery(String procedureName, Class... resultClasses) { checkOpen(); - final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName, resultClasses ); + final ProcedureCall procedureCall = new ProcedureCallImpl<>( this, procedureName, resultClasses ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; } @@ -950,7 +944,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont @SuppressWarnings("UnnecessaryLocalVariable") public ProcedureCall createStoredProcedureQuery(String procedureName, String... resultSetMappings) { checkOpen(); - final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName, resultSetMappings ); + final ProcedureCall procedureCall = new ProcedureCallImpl<>( this, procedureName, resultSetMappings ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; } @@ -1002,7 +996,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public QueryImplementor createQuery(CriteriaUpdate criteriaUpdate) { checkOpen(); try { @@ -1017,7 +1011,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } - @Override + @Override @SuppressWarnings({"rawtypes", "unchecked"}) public QueryImplementor createQuery(CriteriaDelete criteriaDelete) { checkOpen(); try { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 96f9334212..e3d4d3a720 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -139,7 +139,6 @@ import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.FlushModeType; import jakarta.persistence.LockModeType; import jakarta.persistence.PersistenceException; -import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.TransactionRequiredException; import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_SCOPE; @@ -152,7 +151,7 @@ import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE; /** - * Concrete implementation of a Session. + * Concrete implementation of a the {@link Session} API. *

      * Exposes two interfaces:

        *
      • {@link Session} to the application
      • @@ -283,7 +282,7 @@ public class SessionImpl return this.lockOptions; } - protected void applyQuerySettingsAndHints(Query query) { + protected void applyQuerySettingsAndHints(Query query) { final LockOptions lockOptionsForRead = getLockOptionsForRead(); if ( lockOptionsForRead.getLockMode() != LockMode.NONE ) { query.setLockMode( getLockMode( lockOptionsForRead.getLockMode() ) ); @@ -1645,7 +1644,7 @@ public class SessionImpl } @Override - public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { + public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { checkOpen(); // checkTransactionSynchStatus(); return super.createStoredProcedureCall( procedureName, resultClasses ); @@ -1658,7 +1657,7 @@ public class SessionImpl } @Override - public void initializeCollection(PersistentCollection collection, boolean writing) { + public void initializeCollection(PersistentCollection collection, boolean writing) { checkOpenOrWaitingForAutoClose(); pulseTransactionCoordinator(); InitializeCollectionEvent event = new InitializeCollectionEvent( collection, this ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index ba0e980b46..645e83db05 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -247,7 +247,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen @Override public void initializeCollection( - PersistentCollection collection, + PersistentCollection collection, boolean writing) throws HibernateException { throw new SessionException( "collections cannot be fetched by a stateless session" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java b/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java index 437d785a89..c88fe46b32 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java @@ -729,5 +729,5 @@ public interface NativeQuery extends Query, SynchronizeableQuery { NativeQuery setProperties(Object bean); @Override - NativeQuery setProperties(Map bean); + NativeQuery setProperties(Map bean); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/Query.java b/hibernate-core/src/main/java/org/hibernate/query/Query.java index f19ba70cd0..15a32f88f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/Query.java +++ b/hibernate-core/src/main/java/org/hibernate/query/Query.java @@ -47,10 +47,9 @@ import org.hibernate.type.BasicTypeReference; * @author Gavin King * @author Steve Ebersole * - * @param The query result type (for typed queries) + * @param The query result type, for typed queries, or {@code Object} for untyped queries */ @Incubating -@SuppressWarnings("UnusedDeclaration") public interface Query extends TypedQuery, CommonQueryContract { /** * Get the QueryProducer this Query originates from. Generally speaking, @@ -86,7 +85,7 @@ public interface Query extends TypedQuery, CommonQueryContract { * @apiNote This method calls {@link #applyGraph(RootGraph, GraphSemantic)} using * {@link GraphSemantic#FETCH} as the semantic */ - default Query applyFetchGraph(RootGraph graph) { + default Query applyFetchGraph(RootGraph graph) { return applyGraph( graph, GraphSemantic.FETCH ); } @@ -96,7 +95,8 @@ public interface Query extends TypedQuery, CommonQueryContract { * @apiNote This method calls {@link #applyGraph(RootGraph, GraphSemantic)} using * {@link GraphSemantic#LOAD} as the semantic */ - default Query applyLoadGraph(RootGraph graph) { + @SuppressWarnings("UnusedDeclaration") + default Query applyLoadGraph(RootGraph graph) { return applyGraph( graph, GraphSemantic.LOAD ); } @@ -640,40 +640,6 @@ public interface Query extends TypedQuery, CommonQueryContract { */

        Query setParameterList(int position, Collection values, AllowableParameterType

        type); -// /** -// * Bind multiple values to a named query parameter. This is useful for binding -// * a list of values to an expression such as foo.bar in (:value_list). -// * -// * @param name the name of the parameter -// * @param values a collection of values to list -// * @param type the Hibernate type of the values -// * -// * @return {@code this}, for method chaining -// * -// * @deprecated Use {@link #setParameterList(String, Object[], AllowableParameterType)} -// */ -// @Deprecated -// default Query setParameterList(String name, Object[] values, Type type){ -// return setParameter( name, values, (AllowableParameterType)type ); -// } - -// /** -// * Bind multiple values to a named query parameter. This is useful for binding -// * a list of values to an expression such as foo.bar in (:value_list). -// * -// * @param position the parameter positional label -// * @param values a collection of values to list -// * @param type the Hibernate type of the values -// * -// * @return {@code this}, for method chaining -// * -// * @deprecated Use {@link #setParameterList(String, Object[], AllowableParameterType)} -// */ -// @Deprecated -// default Query setParameterList(int position, Object[] values, Type type){ -// return setParameter( position, values, (AllowableParameterType)type ); -// } - /** * Bind multiple values to a named query parameter. This is useful for binding * a list of values to an expression such as foo.bar in (:value_list). @@ -744,62 +710,7 @@ public interface Query extends TypedQuery, CommonQueryContract { * * @return {@code this}, for method chaining */ - Query setProperties(Map bean); - - - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // deprecations - - -// /** -// * Bind a named query parameter using the supplied Type -// * -// * @param name the name of the parameter -// * @param val the possibly-null parameter value -// * @param type the Hibernate type -// * -// * @return {@code this}, for method chaining -// * -// * @deprecated Use {@link #setParameter(String, Object, AllowableParameterType)} -// */ -// @Deprecated -// default Query setParameter(String name, Object val, Type type){ -// return setParameter( name, val, (AllowableParameterType) type ); -// } - -// /** -// * Bind a value to a JDBC-style query parameter. -// * -// * @param position the position of the parameter in the query -// * string, numbered from 0. -// * @param val the possibly-null parameter value -// * @param type the Hibernate type -// * -// * @return {@code this}, for method chaining -// * -// * @deprecated Use {@link #setParameter(int, Object, AllowableParameterType)} -// */ -// @Deprecated -// default Query setParameter(int position, Object val, Type type) { -// return setParameter( position, val, (AllowableParameterType) type ); -// } - -// /** -// * Bind a query parameter using the supplied Type -// * -// * @param parameter The query parameter memento -// * @param val the possibly-null parameter value -// * @param type the Hibernate type -// * -// * @return {@code this}, for method chaining -// * -// * @deprecated Use {@link #setParameter(QueryParameter, Object, AllowableParameterType)} -// */ -// @Deprecated -// default

        Query setParameter(QueryParameter

        parameter, P val, Type type){ -// return setParameter( parameter, val, (AllowableParameterType) type ); -// } + Query setProperties(Map bean); /** * @deprecated (since 5.2) Use {@link #setTupleTransformer} or {@link #setResultListTransformer} diff --git a/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java b/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java index 42fe9f69bb..d6a34a57bc 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java @@ -31,7 +31,7 @@ public interface QueryProducer { * defined with the given name or if the query string is * found to be invalid */ - Query getNamedQuery(String queryName); + Query getNamedQuery(String queryName); /** * Create a {@link Query} instance for the given HQL/JPQL query string. @@ -42,7 +42,7 @@ public interface QueryProducer { * * @see jakarta.persistence.EntityManager#createQuery(String) */ - Query createQuery(String queryString); + Query createQuery(String queryString); /** * Create a typed {@link Query} instance for the given HQL/JPQL query string. @@ -69,7 +69,7 @@ public interface QueryProducer { * * @see jakarta.persistence.EntityManager#createNamedQuery(String) */ - Query createNamedQuery(String name); + Query createNamedQuery(String name); /** * The JPA-defined named, typed query creation method. This form can only @@ -98,7 +98,7 @@ public interface QueryProducer { * * @see jakarta.persistence.EntityManager#createNativeQuery(String) */ - NativeQuery createNativeQuery(String sqlString); + NativeQuery createNativeQuery(String sqlString); /** * Create a NativeQuery instance for the given native (SQL) query using @@ -125,7 +125,7 @@ public interface QueryProducer { * @see jakarta.persistence.EntityManager#createNativeQuery(String,Class) * @see jakarta.persistence.SqlResultSetMapping */ - NativeQuery createNativeQuery(String sqlString, String resultSetMappingName); + NativeQuery createNativeQuery(String sqlString, String resultSetMappingName); /** * Get a NativeQuery instance for a named native SQL query @@ -134,7 +134,7 @@ public interface QueryProducer { * * @return The NativeQuery instance for manipulation and execution */ - NativeQuery getNamedNativeQuery(String name); + NativeQuery getNamedNativeQuery(String name); /** * Get a NativeQuery instance for a named native SQL query @@ -143,11 +143,26 @@ public interface QueryProducer { * * @return The NativeQuery instance for manipulation and execution */ - NativeQuery getNamedNativeQuery(String name, String resultSetMapping); + NativeQuery getNamedNativeQuery(String name, String resultSetMapping); - Query createQuery(CriteriaQuery criteriaQuery); + /** + * Create a Query for the given JPA {@link CriteriaQuery} + * + * @see jakarta.persistence.EntityManager#createQuery(CriteriaQuery) + */ + Query createQuery(CriteriaQuery criteriaQuery); - Query createQuery(CriteriaUpdate updateQuery); + /** + * Create a Query for the given JPA {@link CriteriaUpdate} + * + * @see jakarta.persistence.EntityManager#createQuery(CriteriaUpdate) + */ + Query createQuery(CriteriaUpdate updateQuery); - Query createQuery(CriteriaDelete deleteQuery); + /** + * Create a Query for the given JPA {@link CriteriaDelete} + * + * @see jakarta.persistence.EntityManager#createQuery(CriteriaDelete) + */ + Query createQuery(CriteriaDelete deleteQuery); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java index 78a9cf39ea..272654538b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java @@ -1403,8 +1403,7 @@ public abstract class AbstractQuery implements QueryImplementor { } @Override - @SuppressWarnings( "rawtypes" ) - public QueryImplementor setProperties(Map map) { + public QueryImplementor setProperties(Map map) { for ( String paramName : getParameterMetadata().getNamedParameterNames() ) { final Object object = map.get( paramName ); if ( object == null ) { @@ -1413,7 +1412,7 @@ public abstract class AbstractQuery implements QueryImplementor { } } else { - Class retType = object.getClass(); + Class retType = object.getClass(); if ( Collection.class.isAssignableFrom( retType ) ) { setParameterList( paramName, (Collection) object ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryProducerImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryProducerImplementor.java index 9ac6e87aa2..ef156134ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryProducerImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryProducerImplementor.java @@ -9,7 +9,6 @@ package org.hibernate.query.spi; import org.hibernate.CacheMode; import org.hibernate.FlushMode; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.query.Query; import org.hibernate.query.QueryProducer; import org.hibernate.query.sql.spi.NativeQueryImplementor; @@ -27,35 +26,33 @@ public interface QueryProducerImplementor extends QueryProducer { // todo : define list/scroll/iterate methods here... - - // overrides... + @Override + QueryImplementor getNamedQuery(String queryName); @Override - QueryImplementor getNamedQuery(String queryName); - - @Override - QueryImplementor createQuery(String queryString); + QueryImplementor createQuery(String queryString); @Override QueryImplementor createQuery(String queryString, Class resultClass); @Override - Query createNamedQuery(String name); + QueryImplementor createNamedQuery(String name); @Override QueryImplementor createNamedQuery(String name, Class resultClass); @Override - NativeQueryImplementor createNativeQuery(String sqlString); + NativeQueryImplementor createNativeQuery(String sqlString); @Override NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass); @Override - NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName); + NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName); @Override - NativeQueryImplementor getNamedNativeQuery(String name); + NativeQueryImplementor getNamedNativeQuery(String name); - NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping); + @Override + NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index 906b63db60..2f6cc739a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -11,13 +11,11 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.ZonedDateTime; -import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -1459,7 +1457,7 @@ public class NativeQueryImpl } @Override - public NativeQueryImplementor setProperties(Map map) { + public NativeQueryImplementor setProperties(Map map) { super.setProperties( map ); return this; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java index b79c2b0211..d2d2fcd7a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java @@ -278,7 +278,7 @@ public interface NativeQueryImplementor extends QueryImplementor, NativeQu NativeQueryImplementor setProperties(Object bean); @Override - NativeQueryImplementor setProperties(Map bean); + NativeQueryImplementor setProperties(Map bean); @Override NativeQueryImplementor setParameter( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java index b8be3f15e6..c7078df5ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java @@ -123,6 +123,7 @@ public class QuerySqmImpl /** * Creates a Query instance from a named HQL memento */ + @SuppressWarnings("unchecked") public QuerySqmImpl( NamedHqlQueryMemento memento, Class resultType, @@ -179,7 +180,7 @@ public class QuerySqmImpl if ( memento.getParameterTypes() != null ) { for ( Map.Entry entry : memento.getParameterTypes().entrySet() ) { final QueryParameterImplementor parameter = parameterMetadata.getQueryParameter( entry.getKey() ); - final BasicType type = getSessionFactory().getTypeConfiguration() + final BasicType type = getSessionFactory().getTypeConfiguration() .getBasicTypeRegistry() .getRegisteredType( entry.getValue() ); parameter.applyAnticipatedType( type ); @@ -190,6 +191,7 @@ public class QuerySqmImpl /** * Form used for HQL queries */ + @SuppressWarnings("unchecked") public QuerySqmImpl( String hqlString, HqlInterpretation hqlInterpretation, @@ -230,6 +232,7 @@ public class QuerySqmImpl /** * Form used for criteria queries */ + @SuppressWarnings("unchecked") public QuerySqmImpl( SqmStatement sqmStatement, Class resultType, @@ -326,7 +329,10 @@ public class QuerySqmImpl } } - private static void checkQueryReturnType(SqmQuerySpec querySpec, Class resultClass, SessionFactoryImplementor sessionFactory) { + private static void checkQueryReturnType( + SqmQuerySpec querySpec, + Class resultClass, + SessionFactoryImplementor sessionFactory) { if ( resultClass == null ) { // nothing to check return; @@ -352,10 +358,10 @@ public class QuerySqmImpl } } - final SqmSelection sqmSelection = selections.get( 0 ); + final SqmSelection sqmSelection = selections.get( 0 ); if ( sqmSelection.getSelectableNode() instanceof SqmParameter ) { - final SqmParameter sqmParameter = (SqmParameter) sqmSelection.getSelectableNode(); + final SqmParameter sqmParameter = (SqmParameter) sqmSelection.getSelectableNode(); // we may not yet know a selection type if ( sqmParameter.getNodeType() == null || sqmParameter.getNodeType().getExpressableJavaTypeDescriptor() == null ) { @@ -552,7 +558,6 @@ public class QuerySqmImpl return sqmStatement; } - @SuppressWarnings("unchecked") public Class getResultType() { return resultType; } @@ -785,8 +790,8 @@ public class QuerySqmImpl } } - @SuppressWarnings("unchecked") private SelectQueryPlan buildAggregatedSelectQueryPlan(SqmSelectStatement[] concreteSqmStatements) { + @SuppressWarnings("unchecked") final SelectQueryPlan[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ]; // todo (6.0) : we want to make sure that certain thing (ResultListTransformer, etc) only get applied at the aggregator-level @@ -799,7 +804,7 @@ public class QuerySqmImpl ); } - return new AggregatedSelectQueryPlanImpl( aggregatedQueryPlans ); + return new AggregatedSelectQueryPlanImpl<>( aggregatedQueryPlans ); } private SelectQueryPlan buildConcreteSelectQueryPlan(