remove wildcards from APIs in Query hierarchy

I hate doing this but it's necessary since Query is often
used as a raw type, and the wildcards result in additional
compiler warnings at the usage site

Also clean up some other warnings I encountered in this code
This commit is contained in:
Gavin King 2021-12-12 12:12:43 +01:00
parent 82aff7cd8a
commit 8a68ee49c1
10 changed files with 119 additions and 128 deletions

View File

@ -46,8 +46,8 @@ public interface SynchronizeableQuery<T> {
*/
default SynchronizeableQuery<T> addSynchronizedQuerySpace(String... querySpaces) {
if ( querySpaces != null ) {
for ( int i = 0; i < querySpaces.length; i++ ) {
addSynchronizedQuerySpace( querySpaces[i] );
for (String querySpace : querySpaces) {
addSynchronizedQuerySpace(querySpace);
}
}
return this;
@ -84,8 +84,8 @@ public interface SynchronizeableQuery<T> {
*/
default SynchronizeableQuery<T> addSynchronizedEntityName(String... entityNames) throws MappingException {
if ( entityNames != null ) {
for ( int i = 0; i < entityNames.length; i++ ) {
addSynchronizedEntityName( entityNames[i] );
for (String entityName : entityNames) {
addSynchronizedEntityName(entityName);
}
}
return this;
@ -101,16 +101,15 @@ public interface SynchronizeableQuery<T> {
*
* @throws MappingException Indicates the given class could not be resolved as an entity
*/
@SuppressWarnings( "rawtypes" )
SynchronizeableQuery<T> addSynchronizedEntityClass(Class entityClass) throws MappingException;
SynchronizeableQuery<T> addSynchronizedEntityClass(@SuppressWarnings("rawtypes") Class entityClass) throws MappingException;
/**
* Adds one-or-more entities (by class) whose tables should be added as synchronized spaces
*/
default SynchronizeableQuery<T> addSynchronizedEntityClass(Class<?>... entityClasses) throws MappingException {
if ( entityClasses != null ) {
for ( int i = 0; i < entityClasses.length; i++ ) {
addSynchronizedEntityClass( entityClasses[i] );
for (Class<?> entityClass : entityClasses) {
addSynchronizedEntityClass(entityClass);
}
}
return this;

View File

@ -222,7 +222,7 @@ public interface ProcedureCall
@Override
ProcedureCall addSynchronizedEntityName(String entityName) throws MappingException;
@Override
@Override @SuppressWarnings("rawtypes")
ProcedureCall addSynchronizedEntityClass(Class entityClass) throws MappingException;
@Override

View File

@ -744,7 +744,7 @@ public class ProcedureCallImpl<R>
}
@Override
public ProcedureCallImplementor<R> addSynchronizedEntityClass(Class entityClass) {
public ProcedureCallImplementor<R> addSynchronizedEntityClass(@SuppressWarnings("rawtypes") Class entityClass) {
addSynchronizedQuerySpaces( getSession().getFactory().getMetamodel().entityPersister( entityClass.getName() ) );
return this;
}
@ -801,12 +801,12 @@ public class ProcedureCallImpl<R>
}
@Override
protected void applyEntityGraphQueryHint(String hintName, RootGraphImplementor entityGraph) {
protected void applyEntityGraphQueryHint(String hintName, @SuppressWarnings("rawtypes") RootGraphImplementor entityGraph) {
throw new IllegalStateException( "EntityGraph hints are not supported for ProcedureCall/StoredProcedureQuery" );
}
@Override
public Query<R> applyGraph(RootGraph<?> graph, GraphSemantic semantic) {
public Query<R> applyGraph(@SuppressWarnings("rawtypes") RootGraph graph, GraphSemantic semantic) {
throw new IllegalStateException( "EntityGraph hints are not supported for ProcedureCall/StoredProcedureQuery" );
}
@ -819,8 +819,7 @@ public class ProcedureCallImpl<R>
@Override
public boolean execute() {
try {
final Output rtn = outputs().getCurrent();
return ResultSetOutput.class.isInstance( rtn );
return outputs().getCurrent() instanceof ResultSetOutput;
}
catch (NoMoreOutputsException e) {
return false;
@ -887,7 +886,7 @@ public class ProcedureCallImpl<R>
@Override
public boolean hasMoreResults() {
return outputs().goToNext() && ResultSetOutput.class.isInstance( outputs().getCurrent() );
return outputs().goToNext() && outputs().getCurrent() instanceof ResultSetOutput;
}
@Override
@ -897,7 +896,7 @@ public class ProcedureCallImpl<R>
if ( rtn == null ) {
return -1;
}
else if ( UpdateCountOutput.class.isInstance( rtn ) ) {
else if ( rtn instanceof UpdateCountOutput ) {
return ( (UpdateCountOutput) rtn ).getUpdateCount();
}
else {
@ -923,7 +922,7 @@ public class ProcedureCallImpl<R>
}
try {
final Output rtn = outputs().getCurrent();
if ( !ResultSetOutput.class.isInstance( rtn ) ) {
if ( !(rtn instanceof ResultSetOutput) ) {
throw new IllegalStateException( "Current CallableStatement ou was not a ResultSet, but getResultList was called" );
}

View File

@ -92,7 +92,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @return {@code this}, for method chaining
*/
NativeQuery<T> addScalar(String columnAlias, BasicTypeReference<?> type);
NativeQuery<T> addScalar(String columnAlias, @SuppressWarnings("rawtypes") BasicTypeReference type);
/**
* Declare a scalar query result.
@ -106,7 +106,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @return {@code this}, for method chaining
*/
NativeQuery<T> addScalar(String columnAlias, BasicDomainType<?> type);
NativeQuery<T> addScalar(String columnAlias, @SuppressWarnings("rawtypes") BasicDomainType type);
/**
* Declare a scalar query result using the specified result type.
@ -118,7 +118,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @since 6.0
*/
NativeQuery<T> addScalar(String columnAlias, Class<?> javaType);
NativeQuery<T> addScalar(String columnAlias, @SuppressWarnings("rawtypes") Class javaType);
/**
* Declare a scalar query result with an explicit conversion
@ -189,7 +189,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @since 6.0
*/
NativeQuery<T> addAttributeResult(String columnAlias, Class<?> entityJavaType, String attributePath);
NativeQuery<T> addAttributeResult(String columnAlias, @SuppressWarnings("rawtypes") Class entityJavaType, String attributePath);
/**
* Defines a result based on a specified attribute. Differs from adding a scalar in that
@ -213,7 +213,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @since 6.0
*/
NativeQuery<T> addAttributeResult(String columnAlias, SingularAttribute<?,?> attribute);
NativeQuery<T> addAttributeResult(String columnAlias, @SuppressWarnings("rawtypes") SingularAttribute attribute);
/**
* Add a new root return mapping, returning a {@link RootReturn} to allow
@ -238,7 +238,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @since 3.6
*/
RootReturn addRoot(String tableAlias, Class entityType);
RootReturn addRoot(String tableAlias, @SuppressWarnings("rawtypes") Class entityType);
/**
* Declare a "root" entity, without specifying an alias. The expectation here is that the table alias is the
@ -281,7 +281,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @return {@code this}, for method chaining
*/
NativeQuery<T> addEntity(Class<?> entityType);
NativeQuery<T> addEntity(@SuppressWarnings("rawtypes") Class entityType);
/**
* Declare a "root" entity.
@ -291,7 +291,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @return {@code this}, for method chaining
*/
NativeQuery<T> addEntity(String tableAlias, Class<?> entityType);
NativeQuery<T> addEntity(String tableAlias, @SuppressWarnings("rawtypes") Class entityType);
/**
* Declare a "root" entity, specifying a lock mode.
@ -302,7 +302,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
*
* @return {@code this}, for method chaining
*/
NativeQuery<T> addEntity(String tableAlias, Class<?> entityClass, LockMode lockMode);
NativeQuery<T> addEntity(String tableAlias, @SuppressWarnings("rawtypes") Class entityClass, LockMode lockMode);
/**
* Declare a join fetch result.
@ -507,7 +507,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
NativeQuery<T> addSynchronizedEntityName(String entityName) throws MappingException;
@Override
NativeQuery<T> addSynchronizedEntityClass(Class<?> entityClass) throws MappingException;
NativeQuery<T> addSynchronizedEntityClass(@SuppressWarnings("rawtypes") Class entityClass) throws MappingException;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -567,7 +567,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
@Override
NativeQuery<T> setResultListTransformer(ResultListTransformer transformer);
@Override
@Override @SuppressWarnings("deprecation")
NativeQuery<T> setResultTransformer(ResultTransformer transformer);
@ -664,7 +664,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
<P> NativeQuery<T> setParameterList(QueryParameter<P> parameter, Collection<P> values);
@Override
NativeQuery<T> setParameterList(String name, Collection<?> values);
NativeQuery<T> setParameterList(String name, @SuppressWarnings("rawtypes") Collection values);
// @Override
// default NativeQuery<T> setParameterList(String name, Collection values, Type type) {
@ -678,7 +678,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
// NativeQuery<T> setParameterList(String name, Object[] values, Type type);
@Override
NativeQuery<T> setParameterList(String name, Object[] values, AllowableParameterType<?> type);
NativeQuery<T> setParameterList(String name, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type);
@Override
NativeQuery<T> setParameterList(String name, Object[] values);
@ -702,7 +702,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
<P> NativeQuery<T> setParameter(QueryParameter<P> parameter, P val, BasicTypeReference<P> type);
@Override
NativeQuery<T> setParameterList(int position, Collection<?> values);
NativeQuery<T> setParameterList(int position, @SuppressWarnings("rawtypes") Collection values);
@Override
<P> NativeQuery<T> setParameterList(String name, Collection<? extends P> values, Class<P> type);
@ -720,7 +720,7 @@ public interface NativeQuery<T> extends Query<T>, SynchronizeableQuery {
// NativeQuery<T> setParameterList(int position, Object[] values, Type type);
@Override
NativeQuery<T> setParameterList(int position, Object[] values, AllowableParameterType<?> type);
NativeQuery<T> setParameterList(int position, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type);
@Override
NativeQuery<T> setParameterList(int position, Object[] values);
@ -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(@SuppressWarnings("rawtypes") Map bean);
}

View File

@ -77,7 +77,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
*
* @return this - for method chaining
*/
Query<R> applyGraph(RootGraph<?> graph, GraphSemantic semantic);
Query<R> applyGraph(@SuppressWarnings("rawtypes") RootGraph graph, GraphSemantic semantic);
/**
* Apply the given graph using {@linkplain GraphSemantic#FETCH fetch semantics}
@ -85,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(@SuppressWarnings("rawtypes") RootGraph graph) {
return applyGraph( graph, GraphSemantic.FETCH );
}
@ -96,7 +96,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
* {@link GraphSemantic#LOAD} as the semantic
*/
@SuppressWarnings("UnusedDeclaration")
default Query<R> applyLoadGraph(RootGraph<?> graph) {
default Query<R> applyLoadGraph(@SuppressWarnings("rawtypes") RootGraph graph) {
return applyGraph( graph, GraphSemantic.LOAD );
}
@ -541,7 +541,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
*
* @return {@code this}, for method chaining
*/
Query<R> setParameterList(String name, Collection<?> values);
Query<R> setParameterList(String name, @SuppressWarnings("rawtypes") Collection values);
/**
* Bind multiple values to a positional query parameter. The Hibernate type of the parameter is
@ -554,7 +554,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
*
* @return {@code this}, for method chaining
*/
Query<R> setParameterList(int position, Collection<?> values);
Query<R> setParameterList(int position, @SuppressWarnings("rawtypes") Collection values);
/**
* Bind multiple values to a named query parameter. The Hibernate type of the parameter is
@ -650,7 +650,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
*
* @return {@code this}, for method chaining
*/
Query<R> setParameterList(String name, Object[] values, AllowableParameterType<?> type);
Query<R> setParameterList(String name, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type);
/**
* Bind multiple values to a named query parameter. This is useful for binding
@ -662,7 +662,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
*
* @return {@code this}, for method chaining
*/
Query<R> setParameterList(int position, Object[] values, AllowableParameterType<?> type);
Query<R> setParameterList(int position, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type);
/**
* Bind multiple values to a named query parameter. The Hibernate type of the parameter is
@ -710,7 +710,7 @@ public interface Query<R> extends TypedQuery<R>, CommonQueryContract {
*
* @return {@code this}, for method chaining
*/
Query<R> setProperties(Map<?,?> bean);
Query<R> setProperties(@SuppressWarnings("rawtypes") Map bean);
/**
* @deprecated (since 5.2) Use {@link #setTupleTransformer} or {@link #setResultListTransformer}

View File

@ -11,16 +11,10 @@ import org.hibernate.sql.results.internal.RowTransformerTupleTransformerAdapter;
/**
* User hook for applying transformations of the query result tuples (the result "row").
*
* Ultimately, gets wrapped in a
* {@link RowTransformerTupleTransformerAdapter}
* Ultimately, gets wrapped in a {@link RowTransformerTupleTransformerAdapter}
* to adapt the TupleTransformer to the {@link org.hibernate.sql.results.spi.RowTransformer}
* contract, which is the thing actually used to process the results internally.
*
* Note that {@link JpaTupleTransformer} is a special sub-type applications may use
* to transform the row into a JPA {@link jakarta.persistence.Tuple}. JpaTupleTransformer is
* deprecated as it is much more appropriate (and simpler) to simply specify the Query
* return type as Tuple
*
* @see org.hibernate.transform.ResultTransformer
* @see org.hibernate.sql.results.spi.RowTransformer
*

View File

@ -383,6 +383,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
return hints;
}
@SuppressWarnings("deprecation")
protected void collectHints(Map<String, Object> hints) {
if ( getQueryOptions().getTimeout() != null ) {
hints.put( HINT_TIMEOUT, getQueryOptions().getTimeout() );
@ -445,7 +446,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
}
}
@Override
@Override @SuppressWarnings("deprecation")
public QueryImplementor<R> setHint(String hintName, Object value) {
getSession().checkOpen( true );
@ -532,7 +533,6 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
DEPRECATION_LOGGER.deprecatedSetting( HINT_FETCHGRAPH, JAKARTA_HINT_FETCH_GRAPH );
}
else {
assert HINT_LOADGRAPH.equals( hintName );
DEPRECATION_LOGGER.deprecatedSetting( HINT_FETCHGRAPH, JAKARTA_HINT_FETCH_GRAPH );
}
@ -712,8 +712,9 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
return true;
}
@SuppressWarnings( "UnusedReturnValue" )
@SuppressWarnings({"UnusedReturnValue", "deprecation"})
protected boolean applyHibernateLockModeHint(LockMode lockMode) {
//TODO: this method is a noop. Delete it?
final LockOptions lockOptions;
if ( lockMode == LockMode.NONE ) {
lockOptions = NONE;
@ -982,6 +983,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
locateBinding( parameter ).setBindValue( null, type );
}
else if ( value instanceof Collection ) {
//TODO: this looks wrong to me: how can value be both a P and a (Collection<P>)?
locateBinding( parameter ).setBindValues( (Collection<P>) value );
}
else {
@ -1116,13 +1118,13 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
}
@Override
public QueryImplementor<R> setParameterList(String name, Collection<?> values) {
public QueryImplementor<R> setParameterList(String name, @SuppressWarnings("rawtypes") Collection values) {
locateBinding( name ).setBindValues( values );
return this;
}
@Override
public QueryImplementor<R> setParameterList(int position, Collection<?> values) {
public QueryImplementor<R> setParameterList(int position, @SuppressWarnings("rawtypes") Collection values) {
locateBinding( position ).setBindValues( values );
return this;
}
@ -1151,15 +1153,15 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
return this;
}
@Override
public QueryImplementor<R> setParameterList(String name, Object[] values, AllowableParameterType<?> type) {
locateBinding( name ).setBindValues( Arrays.asList( values ), (AllowableParameterType<Object>) type );
@Override @SuppressWarnings({"rawtypes", "unchecked"})
public QueryImplementor<R> setParameterList(String name, Object[] values, AllowableParameterType type) {
locateBinding( name ).setBindValues( Arrays.asList( values ), type );
return this;
}
@Override
public QueryImplementor<R> setParameterList(int position, Object[] values, AllowableParameterType<?> type) {
locateBinding( position ).setBindValues( Arrays.asList( values ), (AllowableParameterType<Object>) type );
@Override @SuppressWarnings({"rawtypes", "unchecked"})
public QueryImplementor<R> setParameterList(int position, Object[] values, AllowableParameterType type) {
locateBinding( position ).setBindValues( Arrays.asList( values ), type );
return this;
}
@ -1288,7 +1290,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
return (T) binding.getBindValues();
}
else {
return (T) binding.getBindValue();
return binding.getBindValue();
}
}
@ -1303,7 +1305,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
final QueryParameterBinding<?> binding = getQueryParameterBindings().getBinding( parameter );
if ( binding == null || !binding.isBound() ) {
throw new IllegalStateException( "Parameter value not yet bound : " + parameter.toString() );
throw new IllegalStateException( "Parameter value not yet bound : " + parameter );
}
if ( binding.isMultiValued() ) {
@ -1342,10 +1344,10 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
private FlushMode sessionFlushMode;
private CacheMode sessionCacheMode;
protected void beforeQuery(boolean requiresTxn) {
protected void beforeQuery() {
getQueryParameterBindings().validate();
getSession().prepareForQueryExecution( requiresTxn );
getSession().prepareForQueryExecution(false);
prepareForExecution();
@ -1412,7 +1414,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
}
@Override
public QueryImplementor<R> setProperties(Map<?,?> map) {
public QueryImplementor<R> setProperties(@SuppressWarnings("rawtypes") Map map) {
for ( String paramName : getParameterMetadata().getNamedParameterNames() ) {
final Object object = map.get( paramName );
if ( object == null ) {
@ -1421,15 +1423,14 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
}
}
else {
Class<?> retType = object.getClass();
if ( Collection.class.isAssignableFrom( retType ) ) {
setParameterList( paramName, (Collection) object );
if ( object instanceof Collection<?> ) {
setParameterList( paramName, (Collection<?>) object );
}
else if ( retType.isArray() ) {
else if ( object instanceof Object[] ) {
setParameterList( paramName, (Object[]) object );
}
else {
setParameter( paramName, object, determineType( paramName, retType ) );
setParameter( paramName, object, determineType( paramName, object.getClass() ) );
}
}
}
@ -1454,7 +1455,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
@Override
public List<R> list() {
beforeQuery( false );
beforeQuery();
boolean success = false;
try {
final List<R> result = doList();
@ -1536,7 +1537,7 @@ public abstract class AbstractQuery<R> implements QueryImplementor<R> {
@Override
public int executeUpdate() throws HibernateException {
getSession().checkTransactionNeededForUpdateOperation( "Executing an update/delete query" );
beforeQuery( false );
beforeQuery();
boolean success = false;
try {
final int result = doExecuteUpdate();

View File

@ -46,7 +46,6 @@ import org.hibernate.jpa.internal.util.LockModeTypeHelper;
import org.hibernate.jpa.spi.NativeQueryTupleTransformer;
import org.hibernate.metamodel.model.domain.AllowableParameterType;
import org.hibernate.metamodel.model.domain.BasicDomainType;
import org.hibernate.query.Limit;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.ParameterMetadata;
import org.hibernate.query.Query;
@ -127,7 +126,6 @@ public class NativeQueryImpl<R>
private Callback callback;
private Object collectionKey;
private NativeQueryInterpreter nativeQueryInterpreter;
/**
* Constructs a NativeQueryImpl given a sql query defined in the mappings.
@ -366,7 +364,7 @@ public class NativeQueryImpl<R>
.getService( NativeQueryInterpreter.class )
.recognizeParameters( sqlString, parameterRecognizer );
return new ParameterInterpretationImpl( sqlString, parameterRecognizer );
return new ParameterInterpretationImpl( parameterRecognizer );
}
);
}
@ -503,12 +501,12 @@ public class NativeQueryImpl<R>
}
@Override
public Query<R> applyGraph(RootGraph graph, GraphSemantic semantic) {
public Query<R> applyGraph(@SuppressWarnings("rawtypes") RootGraph graph, GraphSemantic semantic) {
throw new HibernateException( "A native SQL query cannot use EntityGraphs" );
}
@Override
public NativeQueryImplementor<R> setTupleTransformer(TupleTransformer transformer) {
public NativeQueryImplementor<R> setTupleTransformer(@SuppressWarnings("rawtypes") TupleTransformer transformer) {
return (NativeQueryImplementor<R>) super.setTupleTransformer( transformer );
}
@ -565,9 +563,7 @@ public class NativeQueryImpl<R>
}
if ( effectiveFlushMode == FlushMode.AUTO ) {
if ( getSession().getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
return true;
}
return getSession().getFactory().getSessionFactoryOptions().isJpaBootstrap();
}
}
@ -594,7 +590,7 @@ public class NativeQueryImpl<R>
private NativeSelectQueryPlan<R> createQueryPlan(ResultSetMapping resultSetMapping) {
final String sqlString = expandParameterLists();
final NativeSelectQueryDefinition<R> queryDefinition = new NativeSelectQueryDefinition<R>() {
final NativeSelectQueryDefinition<R> queryDefinition = new NativeSelectQueryDefinition<>() {
@Override
public String getSqlString() {
return sqlString;
@ -788,10 +784,6 @@ public class NativeQueryImpl<R>
return !query.parameterBindings.hasAnyMultiValuedBindings();
}
private static boolean hasLimit(Limit limit) {
return limit.getFirstRow() != null || limit.getMaxRows() != null;
}
@Override
public ScrollableResultsImplementor<R> scroll(ScrollMode scrollMode) {
return resolveSelectQueryPlan().performScroll( scrollMode, this );
@ -834,7 +826,7 @@ public class NativeQueryImpl<R>
}
@Override
public NativeQueryImplementor setCollectionKey(Object key) {
public NativeQueryImplementor<R> setCollectionKey(Object key) {
this.collectionKey = key;
return this;
}
@ -850,7 +842,7 @@ public class NativeQueryImpl<R>
}
@Override
public NativeQuery<R> addScalar(String columnAlias, BasicTypeReference<?> type) {
public NativeQuery<R> addScalar(String columnAlias, @SuppressWarnings("rawtypes") BasicTypeReference type) {
return registerBuilder(
Builders.scalar(
columnAlias,
@ -860,12 +852,12 @@ public class NativeQueryImpl<R>
}
@Override
public NativeQueryImplementor<R> addScalar(String columnAlias, BasicDomainType<?> type) {
public NativeQueryImplementor<R> addScalar(String columnAlias, @SuppressWarnings("rawtypes") BasicDomainType type) {
return registerBuilder( Builders.scalar( columnAlias, (BasicType<?>) type ) );
}
@Override
public NativeQueryImplementor<R> addScalar(String columnAlias, Class<?> javaType) {
public NativeQueryImplementor<R> addScalar(String columnAlias, @SuppressWarnings("rawtypes") Class javaType) {
return registerBuilder( Builders.scalar( columnAlias, javaType, getSessionFactory() ) );
}
@ -916,7 +908,7 @@ public class NativeQueryImpl<R>
@Override
public NativeQueryImplementor<R> addAttributeResult(
String columnAlias,
Class<?> entityJavaType,
@SuppressWarnings("rawtypes") Class entityJavaType,
String attributePath) {
return addAttributeResult( columnAlias, entityJavaType.getName(), attributePath );
}
@ -933,7 +925,7 @@ public class NativeQueryImpl<R>
@Override
public NativeQueryImplementor<R> addAttributeResult(
String columnAlias,
SingularAttribute<?, ?> attribute) {
@SuppressWarnings("rawtypes") SingularAttribute attribute) {
registerBuilder( Builders.attributeResult( columnAlias, attribute ) );
return this;
}
@ -950,7 +942,7 @@ public class NativeQueryImpl<R>
}
@Override
public DynamicResultBuilderEntityStandard addRoot(String tableAlias, Class entityType) {
public DynamicResultBuilderEntityStandard addRoot(String tableAlias, @SuppressWarnings("rawtypes") Class entityType) {
return addRoot( tableAlias, entityType.getName() );
}
@ -972,17 +964,17 @@ public class NativeQueryImpl<R>
}
@Override
public NativeQueryImplementor<R> addEntity(Class<?> entityType) {
public NativeQueryImplementor<R> addEntity(@SuppressWarnings("rawtypes") Class entityType) {
return addEntity( entityType.getName() );
}
@Override
public NativeQueryImplementor<R> addEntity(String tableAlias, Class<?> entityClass) {
public NativeQueryImplementor<R> addEntity(String tableAlias, @SuppressWarnings("rawtypes") Class entityClass) {
return addEntity( tableAlias, entityClass.getName() );
}
@Override
public NativeQueryImplementor<R> addEntity(String tableAlias, Class<?> entityClass, LockMode lockMode) {
public NativeQueryImplementor<R> addEntity(String tableAlias, @SuppressWarnings("rawtypes") Class entityClass, LockMode lockMode) {
return addEntity( tableAlias, entityClass.getName(), lockMode );
}
@ -1057,7 +1049,7 @@ public class NativeQueryImpl<R>
}
@Override
public NativeQueryImplementor<R> addSynchronizedEntityClass(Class<?> entityClass) throws MappingException {
public NativeQueryImplementor<R> addSynchronizedEntityClass(@SuppressWarnings("rawtypes") Class entityClass) throws MappingException {
addQuerySpaces( getSession().getFactory().getMetamodel().entityPersister( entityClass.getName() ).getQuerySpaces() );
return this;
}
@ -1161,18 +1153,16 @@ public class NativeQueryImpl<R>
addSynchronizedQuerySpace( (String) value );
}
else if ( value instanceof String[] ) {
final String[] strings = (String[]) value;
for ( int i = 0; i < strings.length; i++ ) {
addSynchronizedQuerySpace( strings[i] );
for (String string : (String[]) value) {
addSynchronizedQuerySpace(string);
}
}
else if ( value instanceof Class ) {
addSynchronizedEntityClass( (Class<?>) value );
}
else if ( value instanceof Class[] ) {
final Class<?>[] classes = (Class<?>[]) value;
for ( int i = 0; i < classes.length; i++ ) {
addSynchronizedEntityClass( classes[i] );
for (Class<?> aClass : (Class<?>[]) value) {
addSynchronizedEntityClass(aClass);
}
}
else if ( value instanceof List ) {
@ -1200,7 +1190,7 @@ public class NativeQueryImpl<R>
else if ( value instanceof LockModeType ) {
applyLockModeTypeHint( (LockModeType) value );
}
else if ( String.class.isInstance( value ) ) {
else if ( value instanceof String ) {
applyHibernateLockModeHint( LockModeTypeHelper.interpretLockMode( value ) );
}
else {
@ -1315,19 +1305,25 @@ public class NativeQueryImpl<R>
}
@Override
public <P> NativeQueryImplementor<R> setParameterList(int position, Collection<? extends P> values, AllowableParameterType<P> type) {
public <P> NativeQueryImplementor<R> setParameterList(
int position, Collection<? extends P> values,
AllowableParameterType<P> type) {
super.setParameterList( position, values, type );
return this;
}
@Override
public NativeQueryImplementor<R> setParameterList(String name, Object[] values, AllowableParameterType<?> type) {
public NativeQueryImplementor<R> setParameterList(
String name, Object[] values,
@SuppressWarnings("rawtypes") AllowableParameterType type) {
super.setParameterList( name, values, type );
return this;
}
@Override
public NativeQueryImplementor<R> setParameterList(int position, Object[] values, AllowableParameterType<?> type) {
public NativeQueryImplementor<R> setParameterList(
int position, Object[] values,
@SuppressWarnings("rawtypes") AllowableParameterType type) {
super.setParameterList( position, values, type );
return this;
}
@ -1392,7 +1388,7 @@ public class NativeQueryImpl<R>
}
@Override
public NativeQueryImplementor<R> setParameterList(String name, Collection<?> values) {
public NativeQueryImplementor<R> setParameterList(String name, @SuppressWarnings("rawtypes") Collection values) {
super.setParameterList( name, values );
return this;
}
@ -1451,14 +1447,14 @@ public class NativeQueryImpl<R>
return this;
}
@Override
@Override @SuppressWarnings("deprecation")
public NativeQueryImplementor<R> setResultTransformer(ResultTransformer transformer) {
super.setResultTransformer( transformer );
return this;
}
@Override
public NativeQueryImplementor<R> setProperties(Map<?,?> map) {
public NativeQueryImplementor<R> setProperties(@SuppressWarnings("rawtypes") Map map) {
super.setProperties( map );
return this;
}
@ -1518,7 +1514,7 @@ public class NativeQueryImpl<R>
}
@Override
public NativeQueryImplementor<R> setParameterList(int position, Collection<?> values) {
public NativeQueryImplementor<R> setParameterList(int position, @SuppressWarnings("rawtypes") Collection values) {
super.setParameterList( position, values );
return this;
}
@ -1552,7 +1548,7 @@ public class NativeQueryImpl<R>
}
@Override
protected void applyEntityGraphQueryHint(String hintName, RootGraphImplementor entityGraph) {
protected void applyEntityGraphQueryHint(String hintName, @SuppressWarnings("rawtypes") RootGraphImplementor entityGraph) {
throw new HibernateException( "A native SQL query cannot use EntityGraphs" );
}
@ -1562,7 +1558,7 @@ public class NativeQueryImpl<R>
private final Map<Integer, QueryParameterImplementor<?>> positionalParameters;
private final Map<String, QueryParameterImplementor<?>> namedParameters;
public ParameterInterpretationImpl(String sqlString, ParameterRecognizerImpl parameterRecognizer) {
public ParameterInterpretationImpl(ParameterRecognizerImpl parameterRecognizer) {
this.sqlString = parameterRecognizer.getAdjustedSqlString();
this.parameterList = parameterRecognizer.getParameterList();
this.positionalParameters = parameterRecognizer.getPositionalQueryParameters();

View File

@ -43,7 +43,9 @@ import org.hibernate.type.BasicTypeReference;
*/
@Incubating
public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQuery<R>, NameableQuery {
NativeQueryImplementor setCollectionKey(Object key);
//TODO: this method is no longer used. Can it be deleted?
NativeQueryImplementor<R> setCollectionKey(Object key);
@Override
default LockOptions getLockOptions() {
@ -66,10 +68,10 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
NativeQueryImplementor<R> addScalar(String columnAlias);
@Override
NativeQueryImplementor<R> addScalar(String columnAlias, BasicDomainType<?> type);
NativeQueryImplementor<R> addScalar(String columnAlias, @SuppressWarnings("rawtypes") BasicDomainType type);
@Override
NativeQueryImplementor<R> addScalar(String columnAlias, Class<?> javaType);
NativeQueryImplementor<R> addScalar(String columnAlias, @SuppressWarnings("rawtypes") Class javaType);
@Override
<C> NativeQueryImplementor<R> addScalar(String columnAlias, Class<C> relationalJavaType, AttributeConverter<?,C> converter);
@ -88,13 +90,13 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
Class<? extends AttributeConverter<O, J>> converter);
@Override
NativeQueryImplementor<R> addAttributeResult(String columnAlias, Class<?> entityJavaType, String attributePath);
NativeQueryImplementor<R> addAttributeResult(String columnAlias, @SuppressWarnings("rawtypes") Class entityJavaType, String attributePath);
@Override
NativeQueryImplementor<R> addAttributeResult(String columnAlias, String entityName, String attributePath);
@Override
NativeQueryImplementor<R> addAttributeResult(String columnAlias, SingularAttribute<?, ?> attribute);
NativeQueryImplementor<R> addAttributeResult(String columnAlias, @SuppressWarnings("rawtypes") SingularAttribute attribute);
@Override
DynamicResultBuilderEntityStandard addRoot(String tableAlias, String entityName);
@ -109,13 +111,13 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
NativeQueryImplementor<R> addEntity(String tableAlias, String entityName, LockMode lockMode);
@Override
NativeQueryImplementor<R> addEntity(Class<?> entityType);
NativeQueryImplementor<R> addEntity(@SuppressWarnings("rawtypes") Class entityType);
@Override
NativeQueryImplementor<R> addEntity(String tableAlias, Class<?> entityType);
NativeQueryImplementor<R> addEntity(String tableAlias, @SuppressWarnings("rawtypes") Class entityType);
@Override
NativeQueryImplementor<R> addEntity(String tableAlias, Class<?> entityClass, LockMode lockMode);
NativeQueryImplementor<R> addEntity(String tableAlias, @SuppressWarnings("rawtypes") Class entityClass, LockMode lockMode);
@Override
NativeQueryImplementor<R> addJoin(String tableAlias, String path);
@ -136,7 +138,7 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
NativeQueryImplementor<R> addSynchronizedEntityName(String entityName) throws MappingException;
@Override
NativeQueryImplementor<R> addSynchronizedEntityClass(Class<?> entityClass) throws MappingException;
NativeQueryImplementor<R> addSynchronizedEntityClass(@SuppressWarnings("rawtypes") Class entityClass) throws MappingException;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -253,7 +255,7 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
Collection<P> values);
@Override
NativeQueryImplementor<R> setParameterList(String name, Collection<?> values);
NativeQueryImplementor<R> setParameterList(String name, @SuppressWarnings("rawtypes") Collection values);
// @Override
// default NativeQueryImplementor<R> setParameterList(String name, Collection values, Type type) {
@ -269,7 +271,7 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
// }
@Override
NativeQueryImplementor<R> setParameterList(String name, Object[] values, AllowableParameterType<?> type);
NativeQueryImplementor<R> setParameterList(String name, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type);
@Override
NativeQueryImplementor<R> setParameterList(String name, Object[] values);
@ -278,7 +280,7 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
NativeQueryImplementor<R> setProperties(Object bean);
@Override
NativeQueryImplementor<R> setProperties(Map<?,?> bean);
NativeQueryImplementor<R> setProperties(@SuppressWarnings("rawtypes") Map bean);
@Override
NativeQueryImplementor<R> setParameter(
@ -314,7 +316,7 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
NativeQueryImplementor<R> setParameter(String name, Instant value, TemporalType temporalType);
@Override
NativeQueryImplementor<R> setTupleTransformer(TupleTransformer transformer);
NativeQueryImplementor<R> setTupleTransformer(@SuppressWarnings("rawtypes") TupleTransformer transformer);
@Override
NativeQueryImplementor<R> setResultListTransformer(ResultListTransformer transformer);
@ -353,7 +355,7 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
NativeQueryImplementor<R> setParameter(Parameter<OffsetDateTime> param, OffsetDateTime value, TemporalType temporalType);
@Override
NativeQueryImplementor<R> setParameterList(int position, Collection<?> values);
NativeQueryImplementor<R> setParameterList(int position, @SuppressWarnings("rawtypes") Collection values);
@Override
<P> NativeQueryImplementor<R> setParameterList(String name, Collection<? extends P> values, Class<P> type);
@ -371,7 +373,7 @@ public interface NativeQueryImplementor<R> extends QueryImplementor<R>, NativeQu
// NativeQueryImplementor<R> setParameterList(int position, Object[] values, Type type);
@Override
NativeQueryImplementor<R> setParameterList(int position, Object[] values, AllowableParameterType<?> type);
NativeQueryImplementor<R> setParameterList(int position, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type);
@Override
NativeQueryImplementor<R> setParameterList(int position, Object[] values);

View File

@ -541,13 +541,13 @@ public class QuerySqmImpl<R>
}
@Override
public HqlQueryImplementor<R> applyGraph(RootGraph graph, GraphSemantic semantic) {
public HqlQueryImplementor<R> applyGraph(@SuppressWarnings("rawtypes") RootGraph graph, GraphSemantic semantic) {
queryOptions.applyGraph( (RootGraphImplementor<?>) graph, semantic );
return this;
}
@Override
protected void applyEntityGraphQueryHint(String hintName, RootGraphImplementor entityGraph) {
protected void applyEntityGraphQueryHint(String hintName, @SuppressWarnings("rawtypes") RootGraphImplementor entityGraph) {
final GraphSemantic graphSemantic = GraphSemantic.fromJpaHintName( hintName );
applyGraph( entityGraph, graphSemantic );