fix some warnings and clean up some typing issues

this is a general cleanup of the Session + Query hierarchies
This commit is contained in:
Gavin King 2021-12-09 15:41:52 +01:00 committed by Steve Ebersole
parent b91944c09a
commit a1e3f0cd6f
17 changed files with 221 additions and 304 deletions

View File

@ -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 <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> 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
<T> org.hibernate.query.Query<T> createQuery(String queryString, Class<T> 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
<T> org.hibernate.query.Query<T> createQuery(CriteriaQuery<T> 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
<R> org.hibernate.query.Query<R> createQuery(String queryString, Class<R> resultType);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
org.hibernate.query.Query createNamedQuery(String queryString);
@Override
<R> org.hibernate.query.Query<R> createNamedQuery(String name, Class<R> 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
<R> org.hibernate.query.Query<R> createQuery(CriteriaQuery<R> 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);
<T> org.hibernate.query.Query<T> createNamedQuery(String name, Class<T> resultType);
}

View File

@ -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}.
* <p/>
* 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
<T> org.hibernate.query.Query<T> createQuery(String queryString, Class<T> resultType);
<T> org.hibernate.query.Query<T> createQuery(CriteriaQuery<T> criteriaQuery);
org.hibernate.query.Query createQuery(CriteriaUpdate updateQuery);
org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);
<T> org.hibernate.query.Query<T> createNamedQuery(String name, Class<T> resultType);
//
// @Override
// <T> org.hibernate.query.Query<T> createQuery(String queryString, Class<T> resultType);
//
// @Override
// <T> org.hibernate.query.Query<T> createQuery(CriteriaQuery<T> criteriaQuery);
//
// @Override
// <R> org.hibernate.query.Query<R> createQuery(CriteriaUpdate<?> updateQuery);
//
// @Override
// <R> org.hibernate.query.Query<R> createQuery(CriteriaDelete<?> deleteQuery);
//
// @Override
// <T> org.hibernate.query.Query<T> createNamedQuery(String name, Class<T> 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> T doReturningWork(ReturningWork<T> 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" );
}
}

View File

@ -6,8 +6,6 @@
*/
package org.hibernate;
import java.io.Closeable;
/**
* A command-oriented API for performing bulk operations against a database.
* <p/>
@ -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> T get(Class<T> 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> T get(Class<T> entityClass, Object id, LockMode lockMode);
/**
* Refresh the entity instance state from the database.

View File

@ -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 <T> QueryImplementor<T> createQuery(String queryString, Class<T> 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 <T> QueryImplementor<T> createQuery(String queryString, Class<T> 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 <T> QueryImplementor<T> createNamedQuery(String name, Class<T> 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> T merge(T object) {
return delegate.merge( object );
}
@Override
public Object merge(String entityName, Object object) {
public <T> T merge(String entityName, T object) {
return delegate.merge( entityName, object );
}

View File

@ -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:<ul>
* A Session, through this interface and SharedSessionContractImplementor, implements:
* <ul>
* <li>
* {@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
<T> QueryImplementor<T> createQuery(String queryString, Class<T> resultType);
@Override
<T> QueryImplementor<T> createNamedQuery(String name, Class<T> 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
<T> QueryImplementor<T> createQuery(CriteriaQuery<T> 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
<R> QueryImplementor<R> createQuery(String queryString, Class<R> resultType);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
QueryImplementor createNamedQuery(String queryString);
@Override
<R> QueryImplementor<R> createNamedQuery(String name, Class<R> resultType);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
NativeQueryImplementor createNativeQuery(String queryString);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
NativeQueryImplementor createNativeQuery(String queryString, String resultSetMappingName);
@Override
<R> QueryImplementor<R> createQuery(CriteriaQuery<R> criteriaQuery);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
QueryImplementor createQuery(CriteriaUpdate updateQuery);
@Override @SuppressWarnings({"rawtypes", "unchecked"})
QueryImplementor createQuery(CriteriaDelete deleteQuery);
}

View File

@ -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);

View File

@ -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 <T> QueryImplementor<T> createQuery(String queryString, Class<T> 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<Object> 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 {

View File

@ -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.
* <p/>
* Exposes two interfaces:<ul>
* <li>{@link Session} to the application</li>
@ -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 );

View File

@ -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" );
}

View File

@ -729,5 +729,5 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
NativeQuery<T> setProperties(Object bean);
@Override
NativeQuery<T> setProperties(Map bean);
NativeQuery<T> setProperties(Map<?,?> bean);
}

View File

@ -47,10 +47,9 @@ import org.hibernate.type.BasicTypeReference;
* @author Gavin King
* @author Steve Ebersole
*
* @param <R> The query result type (for typed queries)
* @param <R> The query result type, for typed queries, or {@code Object} for untyped queries
*/
@Incubating
@SuppressWarnings("UnusedDeclaration")
public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
/**
* Get the QueryProducer this Query originates from. Generally speaking,
@ -86,7 +85,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
* @apiNote This method calls {@link #applyGraph(RootGraph, GraphSemantic)} using
* {@link GraphSemantic#FETCH} as the semantic
*/
default Query<R> applyFetchGraph(RootGraph graph) {
default Query<R> applyFetchGraph(RootGraph<?> graph) {
return applyGraph( graph, GraphSemantic.FETCH );
}
@ -96,7 +95,8 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
* @apiNote This method calls {@link #applyGraph(RootGraph, GraphSemantic)} using
* {@link GraphSemantic#LOAD} as the semantic
*/
default Query<R> applyLoadGraph(RootGraph graph) {
@SuppressWarnings("UnusedDeclaration")
default Query<R> applyLoadGraph(RootGraph<?> graph) {
return applyGraph( graph, GraphSemantic.LOAD );
}
@ -640,40 +640,6 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
*/
<P> Query<R> setParameterList(int position, Collection<? extends P> values, AllowableParameterType<P> type);
// /**
// * Bind multiple values to a named query parameter. This is useful for binding
// * a list of values to an expression such as <tt>foo.bar in (:value_list)</tt>.
// *
// * @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<R> 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 <tt>foo.bar in (:value_list)</tt>.
// *
// * @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<R> 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 <tt>foo.bar in (:value_list)</tt>.
@ -744,62 +710,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
*
* @return {@code this}, for method chaining
*/
Query<R> 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<R> 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 <tt>0</tt>.
// * @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<R> 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 <P> Query<R> setParameter(QueryParameter<P> parameter, P val, Type type){
// return setParameter( parameter, val, (AllowableParameterType) type );
// }
Query<R> setProperties(Map<?,?> bean);
/**
* @deprecated (since 5.2) Use {@link #setTupleTransformer} or {@link #setResultListTransformer}

View File

@ -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);
<R> Query<R> 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);
<R> Query<R> 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);
<R> Query<R> 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);
<R> NativeQuery<R> 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);
<R> NativeQuery<R> 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);
<R> NativeQuery<R> 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);
<R> NativeQuery<R> getNamedNativeQuery(String name, String resultSetMapping);
<T> Query<T> createQuery(CriteriaQuery<T> criteriaQuery);
/**
* Create a Query for the given JPA {@link CriteriaQuery}
*
* @see jakarta.persistence.EntityManager#createQuery(CriteriaQuery)
*/
<R> Query<R> createQuery(CriteriaQuery<R> criteriaQuery);
Query createQuery(CriteriaUpdate updateQuery);
/**
* Create a Query for the given JPA {@link CriteriaUpdate}
*
* @see jakarta.persistence.EntityManager#createQuery(CriteriaUpdate)
*/
<R> Query<R> createQuery(CriteriaUpdate<?> updateQuery);
Query createQuery(CriteriaDelete deleteQuery);
/**
* Create a Query for the given JPA {@link CriteriaDelete}
*
* @see jakarta.persistence.EntityManager#createQuery(CriteriaDelete)
*/
<R> Query<R> createQuery(CriteriaDelete<?> deleteQuery);
}

View File

@ -1403,8 +1403,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
}
@Override
@SuppressWarnings( "rawtypes" )
public QueryImplementor<R> setProperties(Map map) {
public QueryImplementor<R> 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<R> implements QueryImplementor<R> {
}
}
else {
Class retType = object.getClass();
Class<?> retType = object.getClass();
if ( Collection.class.isAssignableFrom( retType ) ) {
setParameterList( paramName, (Collection) object );
}

View File

@ -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
<R> QueryImplementor<R> getNamedQuery(String queryName);
@Override
QueryImplementor getNamedQuery(String queryName);
@Override
QueryImplementor createQuery(String queryString);
<R> QueryImplementor<R> createQuery(String queryString);
@Override
<R> QueryImplementor<R> createQuery(String queryString, Class<R> resultClass);
@Override
Query createNamedQuery(String name);
<R> QueryImplementor<R> createNamedQuery(String name);
@Override
<R> QueryImplementor<R> createNamedQuery(String name, Class<R> resultClass);
@Override
NativeQueryImplementor createNativeQuery(String sqlString);
<R> NativeQueryImplementor<R> createNativeQuery(String sqlString);
@Override
<R> NativeQueryImplementor<R> createNativeQuery(String sqlString, Class<R> resultClass);
@Override
NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMappingName);
<R> NativeQueryImplementor<R> createNativeQuery(String sqlString, String resultSetMappingName);
@Override
NativeQueryImplementor getNamedNativeQuery(String name);
<R> NativeQueryImplementor<R> getNamedNativeQuery(String name);
NativeQueryImplementor getNamedNativeQuery(String name, String resultSetMapping);
@Override
<R> NativeQueryImplementor<R> getNamedNativeQuery(String name, String resultSetMapping);
}

View File

@ -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<R>
}
@Override
public NativeQueryImplementor<R> setProperties(Map map) {
public NativeQueryImplementor<R> setProperties(Map<?,?> map) {
super.setProperties( map );
return this;
}

View File

@ -278,7 +278,7 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
NativeQueryImplementor<R> setProperties(Object bean);
@Override
NativeQueryImplementor<R> setProperties(Map bean);
NativeQueryImplementor<R> setProperties(Map<?,?> bean);
@Override
NativeQueryImplementor<R> setParameter(

View File

@ -123,6 +123,7 @@ public class QuerySqmImpl<R>
/**
* Creates a Query instance from a named HQL memento
*/
@SuppressWarnings("unchecked")
public QuerySqmImpl(
NamedHqlQueryMemento memento,
Class<R> resultType,
@ -179,7 +180,7 @@ public class QuerySqmImpl<R>
if ( memento.getParameterTypes() != null ) {
for ( Map.Entry<String, String> 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<R>
/**
* Form used for HQL queries
*/
@SuppressWarnings("unchecked")
public QuerySqmImpl(
String hqlString,
HqlInterpretation hqlInterpretation,
@ -230,6 +232,7 @@ public class QuerySqmImpl<R>
/**
* Form used for criteria queries
*/
@SuppressWarnings("unchecked")
public QuerySqmImpl(
SqmStatement<R> sqmStatement,
Class<R> resultType,
@ -326,7 +329,10 @@ public class QuerySqmImpl<R>
}
}
private static <T> void checkQueryReturnType(SqmQuerySpec<T> querySpec, Class<T> resultClass, SessionFactoryImplementor sessionFactory) {
private static <T> void checkQueryReturnType(
SqmQuerySpec<T> querySpec,
Class<T> resultClass,
SessionFactoryImplementor sessionFactory) {
if ( resultClass == null ) {
// nothing to check
return;
@ -352,10 +358,10 @@ public class QuerySqmImpl<R>
}
}
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<R>
return sqmStatement;
}
@SuppressWarnings("unchecked")
public Class<R> getResultType() {
return resultType;
}
@ -785,8 +790,8 @@ public class QuerySqmImpl<R>
}
}
@SuppressWarnings("unchecked")
private SelectQueryPlan<R> buildAggregatedSelectQueryPlan(SqmSelectStatement<R>[] concreteSqmStatements) {
@SuppressWarnings("unchecked")
final SelectQueryPlan<R>[] 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<R>
);
}
return new AggregatedSelectQueryPlanImpl( aggregatedQueryPlans );
return new AggregatedSelectQueryPlanImpl<>( aggregatedQueryPlans );
}
private SelectQueryPlan<R> buildConcreteSelectQueryPlan(