Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import jakarta.persistence.TemporalType;

import org.hibernate.MappingException;
import org.hibernate.query.BindableType;
import org.hibernate.query.SynchronizeableQuery;
import org.hibernate.query.CommonQueryContract;
import org.hibernate.query.procedure.ProcedureParameter;
import org.hibernate.type.BasicTypeReference;

/**
* Defines support for executing database stored procedures and functions.
Expand Down Expand Up @@ -74,7 +74,7 @@ public interface ProcedureCall
boolean isFunctionCall();

/**
* Mark this ProcedureCall as representing a call to a database function,
* Mark this {@code ProcedureCall} as representing a call to a database function,
* rather than a database procedure.
*
* @param sqlType The {@link java.sql.Types} code for the function return
Expand All @@ -84,7 +84,7 @@ public interface ProcedureCall
ProcedureCall markAsFunctionCall(int sqlType);

/**
* Mark this ProcedureCall as representing a call to a database function,
* Mark this {@code ProcedureCall} as representing a call to a database function,
* rather than a database procedure.
*
* @param resultType The result type for the function return
Expand All @@ -95,15 +95,15 @@ public interface ProcedureCall
ProcedureCall markAsFunctionCall(Class<?> resultType);

/**
* Mark this ProcedureCall as representing a call to a database function,
* Mark this {@code ProcedureCall} as representing a call to a database function,
* rather than a database procedure.
*
* @param typeReference The result type for the function return
*
* @return {@code this}, for method chaining
* @since 6.2
*/
ProcedureCall markAsFunctionCall(BasicTypeReference<?> typeReference);
ProcedureCall markAsFunctionCall(BindableType<?> typeReference);

/**
* Basic form for registering a positional parameter.
Expand All @@ -127,13 +127,13 @@ public interface ProcedureCall
*
* @return The parameter registration memento
*/
<T> ProcedureParameter<T> registerParameter(int position, BasicTypeReference<T> type, ParameterMode mode);
<T> ProcedureParameter<T> registerParameter(int position, BindableType<T> type, ParameterMode mode);

/**
* Like {@link #registerStoredProcedureParameter(int, Class, ParameterMode)} but a basic type reference is given
* Like {@link #registerStoredProcedureParameter(int, Class, ParameterMode)} but a type reference is given
* instead of a class for the parameter type.
*/
ProcedureCall registerStoredProcedureParameter(int position, BasicTypeReference<?> type, ParameterMode mode);
ProcedureCall registerStoredProcedureParameter(int position, BindableType<?> type, ParameterMode mode);

/**
* Retrieve a previously registered parameter memento by the position under which it was registered.
Expand Down Expand Up @@ -176,14 +176,14 @@ <T> ProcedureParameter<T> registerParameter(String parameterName, Class<T> type,
* @throws NamedParametersNotSupportedException When the underlying database is known to not support
* named procedure parameters.
*/
<T> ProcedureParameter<T> registerParameter(String parameterName, BasicTypeReference<T> type, ParameterMode mode)
<T> ProcedureParameter<T> registerParameter(String parameterName, BindableType<T> type, ParameterMode mode)
throws NamedParametersNotSupportedException;

/**
* Like {@link #registerStoredProcedureParameter(String, Class, ParameterMode)} but a basic type reference is given
* Like {@link #registerStoredProcedureParameter(String, Class, ParameterMode)} but a type reference is given
* instead of a class for the parameter type.
*/
ProcedureCall registerStoredProcedureParameter(String parameterName, BasicTypeReference<?> type, ParameterMode mode);
ProcedureCall registerStoredProcedureParameter(String parameterName, BindableType<?> type, ParameterMode mode);

/**
* Retrieve a previously registered parameter memento by the name under which it was registered.
Expand Down Expand Up @@ -223,9 +223,7 @@ default void close() {
getOutputs().release();
}

/*
Covariant overrides
*/
/* Covariant overrides */

@Override
ProcedureCall addSynchronizedQuerySpace(String querySpace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.NoMoreOutputsException;
import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeReference;
import org.hibernate.type.spi.TypeConfiguration;

import jakarta.persistence.CacheRetrieveMode;
Expand Down Expand Up @@ -385,13 +384,19 @@
}

@Override
public ProcedureCallImpl<R> markAsFunctionCall(BasicTypeReference<?> typeReference) {
final BasicType<?> basicType =
getTypeConfiguration().getBasicTypeRegistry().resolve( typeReference );
if ( basicType == null ) {
throw new IllegalArgumentException( "Could not resolve a BasicType for the java type: " + typeReference.getName() );
public ProcedureCall markAsFunctionCall(BindableType<?> typeReference) {

Check notice

Code scanning / CodeQL

Confusing overloading of methods Note

Method ProcedureCallImpl.markAsFunctionCall(..) could be confused with overloaded method
markAsFunctionCall
, since dispatch depends on static types.
if ( !(typeReference instanceof OutputableType<?> outputableType) ) {
throw new IllegalArgumentException( "Given type is not an OutputableType: " + typeReference );
}
markAsFunctionCall( basicType );
if ( resultSetMapping.getNumberOfResultBuilders() == 0 ) {
final SqmExpressible<?> expressible =
typeReference.resolveExpressible( getSessionFactory().getRuntimeMetamodels() );
// Function returns might not be represented as callable parameters,
// but we still want to convert the result to the requested java type if possible
resultSetMapping.addResultBuilder( new ScalarDomainResultBuilder<>( expressible.getExpressibleJavaType() ) );
}
//noinspection unchecked
functionReturn = new FunctionReturnImpl<>( this, (OutputableType<R>) outputableType );
return this;
}

Expand Down Expand Up @@ -452,7 +457,7 @@
@Override
public ProcedureCallImplementor<R> registerStoredProcedureParameter(
int position,
BasicTypeReference<?> type,
BindableType<?> type,
ParameterMode mode) {
getSession().checkOpen( true );

Expand All @@ -472,7 +477,7 @@
@Override
public ProcedureCallImplementor<R> registerStoredProcedureParameter(
String parameterName,
BasicTypeReference<?> type,
BindableType<?> type,
ParameterMode mode) {
getSession().checkOpen( true );
try {
Expand Down Expand Up @@ -501,12 +506,12 @@
@Override
public <T> ProcedureParameter<T> registerParameter(
int position,
BasicTypeReference<T> typeReference,
BindableType<T> typeReference,
ParameterMode mode) {
final BasicType<T> basicType =
getTypeConfiguration().getBasicTypeRegistry().resolve( typeReference );
final SqmExpressible<T> expressible =
typeReference.resolveExpressible( getSessionFactory().getRuntimeMetamodels() );
final ProcedureParameterImpl<T> procedureParameter =
new ProcedureParameterImpl<>( position, mode, basicType.getJavaType(), basicType );
new ProcedureParameterImpl<>( position, mode, typeReference.getBindableJavaType(), expressible );
registerParameter( procedureParameter );
return procedureParameter;
}
Expand Down Expand Up @@ -545,12 +550,12 @@
@Override
public <T> ProcedureParameterImplementor<T> registerParameter(
String name,
BasicTypeReference<T> typeReference,
BindableType<T> typeReference,
ParameterMode mode) {
final BasicType<T> basicType =
getTypeConfiguration().getBasicTypeRegistry().resolve( typeReference );
final SqmExpressible<T> expressible =
typeReference.resolveExpressible( getSessionFactory().getRuntimeMetamodels() );
final ProcedureParameterImpl<T> parameter =
new ProcedureParameterImpl<>( name, mode, basicType.getJavaType(), basicType );
new ProcedureParameterImpl<>( name, mode, typeReference.getBindableJavaType(), expressible );
registerParameter( parameter );
return parameter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import java.util.List;

import org.hibernate.procedure.ProcedureCall;
import org.hibernate.query.BindableType;
import org.hibernate.query.named.NameableQuery;
import org.hibernate.query.spi.ProcedureParameterMetadataImplementor;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.type.BasicTypeReference;

import jakarta.persistence.CacheRetrieveMode;
import jakarta.persistence.CacheStoreMode;
Expand Down Expand Up @@ -41,10 +41,16 @@ default List<R> getResultList() {
R getSingleResult();

@Override
ProcedureCallImplementor<R> registerStoredProcedureParameter(int position, BasicTypeReference<?> type, ParameterMode mode);
ProcedureCallImplementor<R> registerStoredProcedureParameter(int position, Class<?> type, ParameterMode mode);

@Override
ProcedureCallImplementor<R> registerStoredProcedureParameter(String parameterName, Class<?> type, ParameterMode mode);

@Override
ProcedureCallImplementor<R> registerStoredProcedureParameter(int position, BindableType<?> type, ParameterMode mode);

@Override
ProcedureCallImplementor<R> registerStoredProcedureParameter(String parameterName, BasicTypeReference<?> type, ParameterMode mode);
ProcedureCallImplementor<R> registerStoredProcedureParameter(String parameterName, BindableType<?> type, ParameterMode mode);

@Override
ProcedureCallImplementor<R> setHint(String hintName, Object value);
Expand Down Expand Up @@ -88,12 +94,6 @@ default List<R> getResultList() {
@Override
ProcedureCallImplementor<R> setTimeout(Integer timeout);

@Override
ProcedureCallImplementor<R> registerStoredProcedureParameter(int position, Class<?> type, ParameterMode mode);

@Override
ProcedureCallImplementor<R> registerStoredProcedureParameter(String parameterName, Class<?> type, ParameterMode mode);

@Override
NamedCallableQueryMemento toMemento(String name);
}
Loading