Skip to content

Commit f330a19

Browse files
committed
HHH-19449 mopping up and jdoc after apocalypse
1 parent af45504 commit f330a19

File tree

9 files changed

+139
-141
lines changed

9 files changed

+139
-141
lines changed

hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public <T> ProcedureParameter<T> registerParameter(
502502
ParameterMode mode) {
503503
final SqmBindableType<T> expressible = resolveExpressible( typeReference );
504504
final ProcedureParameterImpl<T> procedureParameter =
505-
new ProcedureParameterImpl<>( position, mode, ((BindableType<T>) typeReference).getJavaType(), expressible );
505+
new ProcedureParameterImpl<>( position, mode, typeReference.getJavaType(), expressible );
506506
registerParameter( procedureParameter );
507507
return procedureParameter;
508508
}
@@ -552,7 +552,7 @@ public <T> ProcedureParameterImplementor<T> registerParameter(
552552
ParameterMode mode) {
553553
final SqmBindableType<T> expressible = resolveExpressible( typeReference );
554554
final ProcedureParameterImpl<T> parameter =
555-
new ProcedureParameterImpl<>( name, mode, ((BindableType<T>) typeReference).getJavaType(), expressible );
555+
new ProcedureParameterImpl<>( name, mode, typeReference.getJavaType(), expressible );
556556
registerParameter( parameter );
557557
return parameter;
558558
}

hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterImpl.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,14 @@ public JdbcCallParameterRegistration toJdbcParameterRegistration(
103103
ProcedureCallImplementor<?> procedureCall) {
104104
final QueryParameterBinding<T> binding = procedureCall.getParameterBindings().getBinding( this );
105105
final boolean isNamed = procedureCall.getParameterStrategy() == ParameterStrategy.NAMED && this.name != null;
106-
107-
final BindableType<T> bindableType = getBindableType( binding );
108-
109106
final SharedSessionContractImplementor session = procedureCall.getSession();
110107

111-
final OutputableType<T> typeToUse = (OutputableType<T>) BindingTypeHelper.INSTANCE.resolveTemporalPrecision(
112-
binding == null ? null : binding.getExplicitTemporalPrecision(),
113-
bindableType,
114-
session.getFactory().getQueryEngine().getCriteriaBuilder()
115-
);
108+
final OutputableType<T> typeToUse = (OutputableType<T>)
109+
BindingTypeHelper.resolveTemporalPrecision(
110+
binding == null ? null : binding.getExplicitTemporalPrecision(),
111+
getBindableType( binding ),
112+
session.getFactory().getQueryEngine().getCriteriaBuilder()
113+
);
116114

117115
final String jdbcParamName;
118116
final JdbcParameterBinder parameterBinder;

hibernate-core/src/main/java/org/hibernate/query/CommonQueryContract.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,26 @@
3333
* Queries may have <em>parameters</em>, either ordinal or named, and the various
3434
* {@code setParameter()} operations of this interface allow an argument to be
3535
* bound to a parameter. It's not usually necessary to explicitly specify the type
36-
* of an argument, but in rare cases where this is needed, {@link TypedParameterValue}
37-
* may be used.
36+
* of an argument, but in rare cases where this is needed:
37+
* <ul>
38+
* <li>an instance of an appropriate metamodel {@link Type} may be passed to
39+
* {@link #setParameter(int, Object, Type)}, or
40+
* <li>the argument may be wrapped in a {@link TypedParameterValue}. (For JPA users,
41+
* this second option avoids the need to cast the {@link jakarta.persistence.Query}
42+
* to a Hibernate-specific type.)
43+
* </ul>
44+
* <p>
45+
* For example:
46+
* <pre>
47+
* session.createSelectionQuery("from Person where address = :address", Person.class)
48+
* .setParameter("address", address, Person_.address.getType())
49+
* .getResultList()
50+
* </pre>
51+
* <pre>
52+
* entityManager.createQuery( "from Person where address = :address", Person.class)
53+
* .setParameter("address", TypedParameterValue.of(Person_.address.getType(), address))
54+
* .getResultList()
55+
* </pre>
3856
* <p>
3957
* The operation {@link #setQueryFlushMode(QueryFlushMode)} allows a temporary flush
4058
* mode to be specified, which is in effect only during the execution of this query.

hibernate-core/src/main/java/org/hibernate/query/TypedParameterValue.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package org.hibernate.query;
66

7+
import jakarta.persistence.metamodel.Type;
78
import org.hibernate.type.BindableType;
89
import org.hibernate.type.BasicTypeReference;
910

@@ -25,6 +26,10 @@
2526
* query.setParameter("stringNamedParam",
2627
* TypedParameterValue.ofNull(StandardBasicTypes.STRING))
2728
* </pre>
29+
* <pre>
30+
* query.setParameter("address",
31+
* TypedParameterValue.of(Address_.class_, address))
32+
* </pre>
2833
* <p>
2934
* Here, a "null string" argument was bound to the named parameter
3035
* {@code :stringNamedParam}.
@@ -51,17 +56,17 @@ public record TypedParameterValue<J>(BindableType<J> type, J value) {
5156
*
5257
* @since 7.0
5358
*/
54-
public static <J> TypedParameterValue<J> of(BindableType<J> type, J value) {
55-
return new TypedParameterValue<>( type, value );
59+
public static <J> TypedParameterValue<J> of(Type<J> type, J value) {
60+
return new TypedParameterValue<>( (BindableType<J>) type, value );
5661
}
5762

5863
/**
5964
* Obtain an instance with the given type and a null value.
6065
*
6166
* @since 7.0
6267
*/
63-
public static <J> TypedParameterValue<J> ofNull(BindableType<J> type) {
64-
return new TypedParameterValue<>( type, null );
68+
public static <J> TypedParameterValue<J> ofNull(Type<J> type) {
69+
return new TypedParameterValue<>( (BindableType<J>) type, null );
6570
}
6671

6772
/**

hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void setBindValues(
249249
private void setExplicitTemporalPrecision(TemporalType precision) {
250250
explicitTemporalPrecision = precision;
251251
if ( bindType == null || JavaTypeHelper.isTemporal( determineJavaType( bindType ) ) ) {
252-
bindType = BindingTypeHelper.INSTANCE.resolveTemporalPrecision( precision, bindType, getCriteriaBuilder() );
252+
bindType = BindingTypeHelper.resolveTemporalPrecision( precision, bindType, getCriteriaBuilder() );
253253
}
254254
}
255255

hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private QueryParameterBindingValidator() {
2727
}
2828

2929
public void validate(BindableType<?> paramType, Object bind, BindingContext bindingContext) {
30-
validate( paramType, bind, null, bindingContext);
30+
validate( paramType, bind, null, bindingContext );
3131
}
3232

3333
public void validate(

hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBindings.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
import org.hibernate.metamodel.mapping.JdbcMapping;
1515
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
1616
import org.hibernate.sql.exec.internal.JdbcParameterBindingImpl;
17-
import org.hibernate.type.internal.BindingTypeHelper;
1817
import org.hibernate.type.spi.TypeConfiguration;
1918

19+
import static org.hibernate.type.internal.BindingTypeHelper.resolveBindType;
20+
2021
/**
2122
* Access to all the externalized JDBC parameter bindings
2223
*
@@ -93,10 +94,7 @@ private void createAndAddBinding(
9394
JdbcMapping type) {
9495
addBinding(
9596
params.get( selectionIndex ),
96-
new JdbcParameterBindingImpl(
97-
BindingTypeHelper.INSTANCE.resolveBindType( jdbcValue, type, typeConfiguration ),
98-
jdbcValue
99-
)
97+
new JdbcParameterBindingImpl( resolveBindType( jdbcValue, type, typeConfiguration ), jdbcValue )
10098
);
10199
}
102100
}

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TemporalJavaType.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,19 @@
2020
public interface TemporalJavaType<T> extends BasicJavaType<T> {
2121

2222
static int resolveJdbcTypeCode(TemporalType requestedTemporalPrecision) {
23-
switch ( requestedTemporalPrecision ) {
24-
case DATE:
25-
return Types.DATE;
26-
case TIME:
27-
return Types.TIME;
28-
case TIMESTAMP:
29-
return Types.TIMESTAMP;
30-
}
31-
throw new UnsupportedOperationException( "Unsupported precision: " + requestedTemporalPrecision );
23+
return switch ( requestedTemporalPrecision ) {
24+
case DATE -> Types.DATE;
25+
case TIME -> Types.TIME;
26+
case TIMESTAMP -> Types.TIMESTAMP;
27+
};
3228
}
3329

3430
static Class<?> resolveJavaTypeClass(TemporalType requestedTemporalPrecision) {
35-
switch ( requestedTemporalPrecision ) {
36-
case DATE:
37-
return java.sql.Date.class;
38-
case TIME:
39-
return java.sql.Time.class;
40-
case TIMESTAMP:
41-
return java.sql.Timestamp.class;
42-
}
43-
throw new UnsupportedOperationException( "Unsupported precision: " + requestedTemporalPrecision );
31+
return switch ( requestedTemporalPrecision ) {
32+
case DATE -> java.sql.Date.class;
33+
case TIME -> java.sql.Time.class;
34+
case TIMESTAMP -> java.sql.Timestamp.class;
35+
};
4436
}
4537

4638
/**

0 commit comments

Comments
 (0)