Skip to content

Commit 6beb5ac

Browse files
committed
HHH-8415 - Throw exception types expected by JPA spec wrt StoredProcedureQuery
1 parent aea6b76 commit 6beb5ac

File tree

14 files changed

+418
-130
lines changed

14 files changed

+418
-130
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.procedure;
25+
26+
import org.hibernate.HibernateException;
27+
28+
/**
29+
* @author Steve Ebersole
30+
*/
31+
public class NoSuchParameterException extends HibernateException {
32+
public NoSuchParameterException(String message) {
33+
super( message );
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.procedure;
25+
26+
import org.hibernate.HibernateException;
27+
28+
/**
29+
* @author Steve Ebersole
30+
*/
31+
public class ParameterStrategyException extends HibernateException {
32+
public ParameterStrategyException(String message) {
33+
super( message );
34+
}
35+
}

hibernate-core/src/main/java/org/hibernate/procedure/ProcedureCall.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public interface ProcedureCall extends BasicQueryContract, SynchronizeableQuery
8282
* @param position The parameter position
8383
*
8484
* @return The parameter registration memento
85+
*
86+
* @throws ParameterStrategyException If the ProcedureCall is defined using named parameters
87+
* @throws NoSuchParameterException If no parameter with that position exists
8588
*/
8689
public ParameterRegistration getParameterRegistration(int position);
8790

@@ -122,6 +125,9 @@ public ProcedureCall registerParameter0(String parameterName, Class type, Parame
122125
* @param name The parameter name
123126
*
124127
* @return The parameter registration memento
128+
*
129+
* @throws ParameterStrategyException If the ProcedureCall is defined using positional parameters
130+
* @throws NoSuchParameterException If no parameter with that name exists
125131
*/
126132
public ParameterRegistration getParameterRegistration(String name);
127133

hibernate-core/src/main/java/org/hibernate/procedure/ProcedureOutputs.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public interface ProcedureOutputs extends Outputs {
5353
*
5454
* @return The output value.
5555
*
56+
* @throws ParameterStrategyException If the ProcedureCall is defined using positional parameters
57+
* @throws NoSuchParameterException If no parameter with that name exists
58+
*
5659
* @see ProcedureCall#registerParameter(String, Class, javax.persistence.ParameterMode)
5760
*/
5861
public Object getOutputParameterValue(String name);
@@ -64,6 +67,9 @@ public interface ProcedureOutputs extends Outputs {
6467
*
6568
* @return The output value.
6669
*
70+
* @throws ParameterStrategyException If the ProcedureCall is defined using named parameters
71+
* @throws NoSuchParameterException If no parameter with that position exists
72+
*
6773
* @see ProcedureCall#registerParameter(int, Class, javax.persistence.ParameterMode)
6874
*/
6975
public Object getOutputParameterValue(int position);

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
import org.hibernate.internal.util.collections.CollectionHelper;
5151
import org.hibernate.persister.entity.EntityPersister;
5252
import org.hibernate.procedure.NamedParametersNotSupportedException;
53+
import org.hibernate.procedure.NoSuchParameterException;
5354
import org.hibernate.procedure.ParameterRegistration;
55+
import org.hibernate.procedure.ParameterStrategyException;
5456
import org.hibernate.procedure.ProcedureCall;
5557
import org.hibernate.procedure.ProcedureCallMemento;
5658
import org.hibernate.procedure.ProcedureOutputs;
@@ -321,21 +323,22 @@ private void prepareForNamedParameters() {
321323
@Override
322324
public ParameterRegistrationImplementor getParameterRegistration(int position) {
323325
if ( parameterStrategy != ParameterStrategy.POSITIONAL ) {
324-
throw new IllegalArgumentException( "Positions were not used to register parameters with this stored procedure call" );
325-
}
326-
try {
327-
return registeredParameters.get( position );
326+
throw new ParameterStrategyException(
327+
"Attempt to access positional parameter [" + position + "] but ProcedureCall using named parameters"
328+
);
328329
}
329-
catch ( Exception e ) {
330-
throw new QueryException( "Could not locate parameter registered using that position [" + position + "]" );
330+
for ( ParameterRegistrationImplementor parameter : registeredParameters ) {
331+
if ( position == parameter.getPosition() ) {
332+
return parameter;
333+
}
331334
}
335+
throw new NoSuchParameterException( "Could not locate parameter registered using that position [" + position + "]" );
332336
}
333337

334338
@Override
335339
@SuppressWarnings("unchecked")
336340
public <T> ParameterRegistration<T> registerParameter(String name, Class<T> type, ParameterMode mode) {
337-
final NamedParameterRegistration parameterRegistration
338-
= new NamedParameterRegistration( this, name, mode, type );
341+
final NamedParameterRegistration parameterRegistration = new NamedParameterRegistration( this, name, mode, type );
339342
registerParameter( parameterRegistration );
340343
return parameterRegistration;
341344
}
@@ -350,14 +353,14 @@ public ProcedureCall registerParameter0(String name, Class type, ParameterMode m
350353
@Override
351354
public ParameterRegistrationImplementor getParameterRegistration(String name) {
352355
if ( parameterStrategy != ParameterStrategy.NAMED ) {
353-
throw new IllegalArgumentException( "Names were not used to register parameters with this stored procedure call" );
356+
throw new ParameterStrategyException( "Names were not used to register parameters with this stored procedure call" );
354357
}
355358
for ( ParameterRegistrationImplementor parameter : registeredParameters ) {
356359
if ( name.equals( parameter.getName() ) ) {
357360
return parameter;
358361
}
359362
}
360-
throw new IllegalArgumentException( "Could not locate parameter registered under that name [" + name + "]" );
363+
throw new NoSuchParameterException( "Could not locate parameter registered under that name [" + name + "]" );
361364
}
362365

363366
@Override

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Object getOutputParameterValue(int position) {
6868
}
6969

7070
@Override
71-
protected CurrentReturnState buildCurrentReturnDescriptor(boolean isResultSet, int updateCount) {
71+
protected CurrentReturnState buildCurrentReturnState(boolean isResultSet, int updateCount) {
7272
return new ProcedureCurrentReturnState( isResultSet, updateCount, refCursorParamIndex );
7373
}
7474

@@ -81,8 +81,8 @@ private ProcedureCurrentReturnState(boolean isResultSet, int updateCount, int re
8181
}
8282

8383
@Override
84-
public boolean indicatesMoreReturns() {
85-
return super.indicatesMoreReturns()
84+
public boolean indicatesMoreOutputs() {
85+
return super.indicatesMoreOutputs()
8686
|| ProcedureOutputsImpl.this.refCursorParamIndex < ProcedureOutputsImpl.this.refCursorParameters.length;
8787
}
8888

@@ -106,7 +106,7 @@ protected Output buildExtendedReturn() {
106106
.getService( RefCursorSupport.class )
107107
.getResultSet( ProcedureOutputsImpl.this.callableStatement, refCursorParam.getPosition() );
108108
}
109-
return new ResultSetOutputImpl( extractResults( resultSet ) );
109+
return buildResultSetOutput( extractResults( resultSet ) );
110110
}
111111
}
112112

hibernate-core/src/main/java/org/hibernate/result/Outputs.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,18 @@ public interface Outputs {
3838
*
3939
* @return The current Output object. Can be {@code null}
4040
*/
41-
public Output getCurrentOutput();
41+
public Output getCurrent();
4242

4343
/**
44-
* Are there any more Output objects associated with {@code this}?
44+
* Go to the next Output object (if any), returning an indication of whether there was another (aka, will
45+
* the next call to {@link #getCurrent()} return {@code null}?
4546
*
46-
* @return {@code true} means there are more Output objects available via {@link #getNextOutput()}; {@code false}
47-
* indicates that calling {@link #getNextOutput()} will certainly result in an exception.
47+
* @return {@code true} if the next call to {@link #getCurrent()} will return a non-{@code null} value.
4848
*/
49-
public boolean hasMoreOutput();
49+
public boolean goToNext();
5050

5151
/**
52-
* Retrieve the next return
53-
*
54-
* @return The next return.
55-
*
56-
* @throws NoMoreReturnsException Thrown if there are no more returns associated with this Result, as would
57-
* have been indicated by a {@code false} return from {@link #hasMoreOutput()}.
52+
* Eagerly release any resources held by this Outputs.
5853
*/
59-
public Output getNextOutput() throws NoMoreReturnsException;
54+
public void release();
6055
}

0 commit comments

Comments
 (0)