HHH-8413 - Rename ProcedureResults -> ProcedureOutputs
This commit is contained in:
parent
49a2ee04b9
commit
59d2bff81b
|
@ -141,7 +141,7 @@ public interface ProcedureCall extends BasicQueryContract, SynchronizeableQuery
|
||||||
*
|
*
|
||||||
* @return The ProcedureResult representation
|
* @return The ProcedureResult representation
|
||||||
*/
|
*/
|
||||||
public ProcedureResult getResult();
|
public ProcedureOutputs getResult();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the disconnected representation of this call. Used in HEM to allow redefining a named query
|
* Extract the disconnected representation of this call. Used in HEM to allow redefining a named query
|
||||||
|
|
|
@ -23,20 +23,20 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.procedure;
|
package org.hibernate.procedure;
|
||||||
|
|
||||||
import org.hibernate.result.Result;
|
import org.hibernate.result.Outputs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specialization of the {@link Result} contract providing access to the stored procedure's registered
|
* Specialization of the {@link org.hibernate.result.Outputs} contract providing access to the stored procedure's registered
|
||||||
* output parameters.
|
* output parameters.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface ProcedureResult extends Result {
|
public interface ProcedureOutputs extends Outputs {
|
||||||
/**
|
/**
|
||||||
* Retrieve the value of an OUTPUT parameter by the parameter's registration memento.
|
* Retrieve the value of an OUTPUT parameter by the parameter's registration memento.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Should NOT be called for parameters registered as REF_CURSOR. REF_CURSOR parameters should be
|
* Should NOT be called for parameters registered as REF_CURSOR. REF_CURSOR parameters should be
|
||||||
* accessed via the returns (see {@link #getNextReturn}
|
* accessed via the returns (see {@link #getNextOutput}
|
||||||
*
|
*
|
||||||
* @param parameterRegistration The parameter's registration memento.
|
* @param parameterRegistration The parameter's registration memento.
|
||||||
*
|
*
|
|
@ -53,7 +53,7 @@ import org.hibernate.procedure.NamedParametersNotSupportedException;
|
||||||
import org.hibernate.procedure.ParameterRegistration;
|
import org.hibernate.procedure.ParameterRegistration;
|
||||||
import org.hibernate.procedure.ProcedureCall;
|
import org.hibernate.procedure.ProcedureCall;
|
||||||
import org.hibernate.procedure.ProcedureCallMemento;
|
import org.hibernate.procedure.ProcedureCallMemento;
|
||||||
import org.hibernate.procedure.ProcedureResult;
|
import org.hibernate.procedure.ProcedureOutputs;
|
||||||
import org.hibernate.result.spi.ResultContext;
|
import org.hibernate.result.spi.ResultContext;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements
|
||||||
|
|
||||||
private Set<String> synchronizedQuerySpaces;
|
private Set<String> synchronizedQuerySpaces;
|
||||||
|
|
||||||
private ProcedureResultImpl outputs;
|
private ProcedureOutputsImpl outputs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The no-returns form.
|
* The no-returns form.
|
||||||
|
@ -367,7 +367,7 @@ public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProcedureResult getResult() {
|
public ProcedureOutputs getResult() {
|
||||||
if ( outputs == null ) {
|
if ( outputs == null ) {
|
||||||
outputs = buildOutputs();
|
outputs = buildOutputs();
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements
|
||||||
return outputs;
|
return outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProcedureResultImpl buildOutputs() {
|
private ProcedureOutputsImpl buildOutputs() {
|
||||||
// todo : going to need a very specialized Loader for this.
|
// todo : going to need a very specialized Loader for this.
|
||||||
// or, might be a good time to look at splitting Loader up into:
|
// or, might be a good time to look at splitting Loader up into:
|
||||||
// 1) building statement objects
|
// 1) building statement objects
|
||||||
|
@ -419,7 +419,7 @@ public class ProcedureCallImpl extends AbstractBasicQueryContractImpl implements
|
||||||
i += parameter.getSqlTypes().length;
|
i += parameter.getSqlTypes().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ProcedureResultImpl( this, statement );
|
return new ProcedureOutputsImpl( this, statement );
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
catch (SQLException e) {
|
||||||
throw getSession().getFactory().getSQLExceptionHelper().convert(
|
throw getSession().getFactory().getSQLExceptionHelper().convert(
|
||||||
|
|
|
@ -28,23 +28,23 @@ import java.sql.ResultSet;
|
||||||
|
|
||||||
import org.hibernate.engine.jdbc.cursor.spi.RefCursorSupport;
|
import org.hibernate.engine.jdbc.cursor.spi.RefCursorSupport;
|
||||||
import org.hibernate.procedure.ParameterRegistration;
|
import org.hibernate.procedure.ParameterRegistration;
|
||||||
import org.hibernate.procedure.ProcedureResult;
|
import org.hibernate.procedure.ProcedureOutputs;
|
||||||
import org.hibernate.result.Return;
|
import org.hibernate.result.Output;
|
||||||
import org.hibernate.result.internal.ResultImpl;
|
import org.hibernate.result.internal.OutputsImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of ProcedureResult. Defines centralized access to all of the results of a procedure call.
|
* Implementation of ProcedureResult. Defines centralized access to all of the results of a procedure call.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ProcedureResultImpl extends ResultImpl implements ProcedureResult {
|
public class ProcedureOutputsImpl extends OutputsImpl implements ProcedureOutputs {
|
||||||
private final ProcedureCallImpl procedureCall;
|
private final ProcedureCallImpl procedureCall;
|
||||||
private final CallableStatement callableStatement;
|
private final CallableStatement callableStatement;
|
||||||
|
|
||||||
private final ParameterRegistrationImplementor[] refCursorParameters;
|
private final ParameterRegistrationImplementor[] refCursorParameters;
|
||||||
private int refCursorParamIndex;
|
private int refCursorParamIndex;
|
||||||
|
|
||||||
ProcedureResultImpl(ProcedureCallImpl procedureCall, CallableStatement callableStatement) {
|
ProcedureOutputsImpl(ProcedureCallImpl procedureCall, CallableStatement callableStatement) {
|
||||||
super( procedureCall, callableStatement );
|
super( procedureCall, callableStatement );
|
||||||
this.procedureCall = procedureCall;
|
this.procedureCall = procedureCall;
|
||||||
this.callableStatement = callableStatement;
|
this.callableStatement = callableStatement;
|
||||||
|
@ -83,7 +83,7 @@ public class ProcedureResultImpl extends ResultImpl implements ProcedureResult {
|
||||||
@Override
|
@Override
|
||||||
public boolean indicatesMoreReturns() {
|
public boolean indicatesMoreReturns() {
|
||||||
return super.indicatesMoreReturns()
|
return super.indicatesMoreReturns()
|
||||||
|| ProcedureResultImpl.this.refCursorParamIndex < ProcedureResultImpl.this.refCursorParameters.length;
|
|| ProcedureOutputsImpl.this.refCursorParamIndex < ProcedureOutputsImpl.this.refCursorParameters.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,21 +92,21 @@ public class ProcedureResultImpl extends ResultImpl implements ProcedureResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Return buildExtendedReturn() {
|
protected Output buildExtendedReturn() {
|
||||||
ProcedureResultImpl.this.refCursorParamIndex++;
|
ProcedureOutputsImpl.this.refCursorParamIndex++;
|
||||||
final ParameterRegistrationImplementor refCursorParam = ProcedureResultImpl.this.refCursorParameters[refCursorParamIndex];
|
final ParameterRegistrationImplementor refCursorParam = ProcedureOutputsImpl.this.refCursorParameters[refCursorParamIndex];
|
||||||
ResultSet resultSet;
|
ResultSet resultSet;
|
||||||
if ( refCursorParam.getName() != null ) {
|
if ( refCursorParam.getName() != null ) {
|
||||||
resultSet = ProcedureResultImpl.this.procedureCall.getSession().getFactory().getServiceRegistry()
|
resultSet = ProcedureOutputsImpl.this.procedureCall.getSession().getFactory().getServiceRegistry()
|
||||||
.getService( RefCursorSupport.class )
|
.getService( RefCursorSupport.class )
|
||||||
.getResultSet( ProcedureResultImpl.this.callableStatement, refCursorParam.getName() );
|
.getResultSet( ProcedureOutputsImpl.this.callableStatement, refCursorParam.getName() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
resultSet = ProcedureResultImpl.this.procedureCall.getSession().getFactory().getServiceRegistry()
|
resultSet = ProcedureOutputsImpl.this.procedureCall.getSession().getFactory().getServiceRegistry()
|
||||||
.getService( RefCursorSupport.class )
|
.getService( RefCursorSupport.class )
|
||||||
.getResultSet( ProcedureResultImpl.this.callableStatement, refCursorParam.getPosition() );
|
.getResultSet( ProcedureOutputsImpl.this.callableStatement, refCursorParam.getPosition() );
|
||||||
}
|
}
|
||||||
return new ResultSetReturnImpl( extractResults( resultSet ) );
|
return new ResultSetOutputImpl( extractResults( resultSet ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,18 +24,18 @@
|
||||||
package org.hibernate.result;
|
package org.hibernate.result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common contract for individual return objects which can be either results ({@link ResultSetReturn}) or update
|
* Common contract for individual return objects which can be either results ({@link ResultSetOutput}) or update
|
||||||
* counts ({@link UpdateCountReturn}).
|
* counts ({@link UpdateCountOutput}).
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface Return {
|
public interface Output {
|
||||||
/**
|
/**
|
||||||
* Determine if this return is a result (castable to {@link ResultSetReturn}). The alternative is that it is
|
* Determine if this return is a result (castable to {@link ResultSetOutput}). The alternative is that it is
|
||||||
* an update count (castable to {@link UpdateCountReturn}).
|
* an update count (castable to {@link UpdateCountOutput}).
|
||||||
*
|
*
|
||||||
* @return {@code true} indicates that {@code this} can be safely cast to {@link ResultSetReturn}), other wise
|
* @return {@code true} indicates that {@code this} can be safely cast to {@link ResultSetOutput}), other wise
|
||||||
* it can be cast to {@link UpdateCountReturn}.
|
* it can be cast to {@link UpdateCountOutput}.
|
||||||
*/
|
*/
|
||||||
public boolean isResultSet();
|
public boolean isResultSet();
|
||||||
}
|
}
|
|
@ -24,29 +24,29 @@
|
||||||
package org.hibernate.result;
|
package org.hibernate.result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the result of executing a JDBC statement accounting for mixing of result sets and update counts hiding the
|
* Represents the outputs of executing a JDBC statement accounting for mixing of result sets and update counts
|
||||||
* complexity (IMO) of how this is exposed in the JDBC API.
|
* hiding the complexity (IMO) of how this is exposed in the JDBC API.
|
||||||
*
|
* <p/>
|
||||||
* A result is made up of group of {@link Return} objects, each representing a single result set or update count.
|
* The outputs are exposed as a group of {@link Output} objects, each representing a single result set or update count.
|
||||||
* Conceptually, Result presents those Returns as an iterator.
|
* Conceptually, Result presents those Returns as an iterator.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface Result {
|
public interface Outputs {
|
||||||
/**
|
/**
|
||||||
* Retrieve the current return.
|
* Retrieve the current Output object.
|
||||||
*
|
*
|
||||||
* @return The current return.
|
* @return The current Output object. Can be {@code null}
|
||||||
*/
|
*/
|
||||||
public Return getCurrentReturn();
|
public Output getCurrentOutput();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Are there any more returns associated with this result?
|
* Are there any more Output objects associated with {@code this}?
|
||||||
*
|
*
|
||||||
* @return {@code true} means there are more returns available via {@link #getNextReturn()}; {@code false}
|
* @return {@code true} means there are more Output objects available via {@link #getNextOutput()}; {@code false}
|
||||||
* indicates that calling {@link #getNextReturn()} will certainly result in an exception.
|
* indicates that calling {@link #getNextOutput()} will certainly result in an exception.
|
||||||
*/
|
*/
|
||||||
public boolean hasMoreReturns();
|
public boolean hasMoreOutput();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the next return
|
* Retrieve the next return
|
||||||
|
@ -54,7 +54,7 @@ public interface Result {
|
||||||
* @return The next return.
|
* @return The next return.
|
||||||
*
|
*
|
||||||
* @throws NoMoreReturnsException Thrown if there are no more returns associated with this Result, as would
|
* @throws NoMoreReturnsException Thrown if there are no more returns associated with this Result, as would
|
||||||
* have been indicated by a {@code false} return from {@link #hasMoreReturns()}.
|
* have been indicated by a {@code false} return from {@link #hasMoreOutput()}.
|
||||||
*/
|
*/
|
||||||
public Return getNextReturn() throws NoMoreReturnsException;
|
public Output getNextOutput() throws NoMoreReturnsException;
|
||||||
}
|
}
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface ResultSetReturn extends Return {
|
public interface ResultSetOutput extends Output {
|
||||||
/**
|
/**
|
||||||
* Consume the underlying {@link java.sql.ResultSet} and return the resulting List.
|
* Consume the underlying {@link java.sql.ResultSet} and return the resulting List.
|
||||||
*
|
*
|
|
@ -28,7 +28,7 @@ package org.hibernate.result;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface UpdateCountReturn extends Return {
|
public interface UpdateCountOutput extends Output {
|
||||||
/**
|
/**
|
||||||
* Retrieve the associated update count
|
* Retrieve the associated update count
|
||||||
*
|
*
|
|
@ -42,17 +42,17 @@ import org.hibernate.loader.custom.CustomQuery;
|
||||||
import org.hibernate.loader.custom.sql.SQLQueryReturnProcessor;
|
import org.hibernate.loader.custom.sql.SQLQueryReturnProcessor;
|
||||||
import org.hibernate.loader.spi.AfterLoadAction;
|
import org.hibernate.loader.spi.AfterLoadAction;
|
||||||
import org.hibernate.result.NoMoreReturnsException;
|
import org.hibernate.result.NoMoreReturnsException;
|
||||||
import org.hibernate.result.Result;
|
import org.hibernate.result.Outputs;
|
||||||
import org.hibernate.result.ResultSetReturn;
|
import org.hibernate.result.ResultSetOutput;
|
||||||
import org.hibernate.result.Return;
|
import org.hibernate.result.Output;
|
||||||
import org.hibernate.result.UpdateCountReturn;
|
import org.hibernate.result.UpdateCountOutput;
|
||||||
import org.hibernate.result.spi.ResultContext;
|
import org.hibernate.result.spi.ResultContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ResultImpl implements Result {
|
public class OutputsImpl implements Outputs {
|
||||||
private static final Logger log = CoreLogging.logger( ResultImpl.class );
|
private static final Logger log = CoreLogging.logger( OutputsImpl.class );
|
||||||
|
|
||||||
private final ResultContext context;
|
private final ResultContext context;
|
||||||
private final PreparedStatement jdbcStatement;
|
private final PreparedStatement jdbcStatement;
|
||||||
|
@ -60,7 +60,7 @@ public class ResultImpl implements Result {
|
||||||
|
|
||||||
private CurrentReturnState currentReturnState;
|
private CurrentReturnState currentReturnState;
|
||||||
|
|
||||||
public ResultImpl(ResultContext context, PreparedStatement jdbcStatement) {
|
public OutputsImpl(ResultContext context, PreparedStatement jdbcStatement) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.jdbcStatement = jdbcStatement;
|
this.jdbcStatement = jdbcStatement;
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class ResultImpl implements Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Return getCurrentReturn() {
|
public Output getCurrentOutput() {
|
||||||
if ( currentReturnState == null ) {
|
if ( currentReturnState == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class ResultImpl implements Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasMoreReturns() {
|
public boolean hasMoreOutput() {
|
||||||
// prepare the next return state
|
// prepare the next return state
|
||||||
try {
|
try {
|
||||||
final boolean isResultSet = jdbcStatement.getMoreResults();
|
final boolean isResultSet = jdbcStatement.getMoreResults();
|
||||||
|
@ -117,12 +117,12 @@ public class ResultImpl implements Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Return getNextReturn() {
|
public Output getNextOutput() {
|
||||||
if ( !hasMoreReturns() ) {
|
if ( !hasMoreOutput() ) {
|
||||||
throw new NoMoreReturnsException( "Results have been exhausted" );
|
throw new NoMoreReturnsException( "Results have been exhausted" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return getCurrentReturn();
|
return getCurrentOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List extractCurrentResults() {
|
private List extractCurrentResults() {
|
||||||
|
@ -158,7 +158,7 @@ public class ResultImpl implements Result {
|
||||||
private final boolean isResultSet;
|
private final boolean isResultSet;
|
||||||
private final int updateCount;
|
private final int updateCount;
|
||||||
|
|
||||||
private Return rtn;
|
private Output rtn;
|
||||||
|
|
||||||
protected CurrentReturnState(boolean isResultSet, int updateCount) {
|
protected CurrentReturnState(boolean isResultSet, int updateCount) {
|
||||||
this.isResultSet = isResultSet;
|
this.isResultSet = isResultSet;
|
||||||
|
@ -177,14 +177,14 @@ public class ResultImpl implements Result {
|
||||||
return updateCount;
|
return updateCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Return getReturn() {
|
public Output getReturn() {
|
||||||
if ( rtn == null ) {
|
if ( rtn == null ) {
|
||||||
rtn = buildReturn();
|
rtn = buildReturn();
|
||||||
}
|
}
|
||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Return buildReturn() {
|
protected Output buildReturn() {
|
||||||
if ( log.isDebugEnabled() ) {
|
if ( log.isDebugEnabled() ) {
|
||||||
log.debugf(
|
log.debugf(
|
||||||
"Building Return [isResultSet=%s, updateCount=%s, extendedReturn=%s",
|
"Building Return [isResultSet=%s, updateCount=%s, extendedReturn=%s",
|
||||||
|
@ -204,10 +204,10 @@ public class ResultImpl implements Result {
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( isResultSet() ) {
|
if ( isResultSet() ) {
|
||||||
return new ResultSetReturnImpl( extractCurrentResults() );
|
return new ResultSetOutputImpl( extractCurrentResults() );
|
||||||
}
|
}
|
||||||
else if ( getUpdateCount() >= 0 ) {
|
else if ( getUpdateCount() >= 0 ) {
|
||||||
return new UpdateCountReturnImpl( updateCount );
|
return new UpdateCountOutputImpl( updateCount );
|
||||||
}
|
}
|
||||||
else if ( hasExtendedReturns() ) {
|
else if ( hasExtendedReturns() ) {
|
||||||
return buildExtendedReturn();
|
return buildExtendedReturn();
|
||||||
|
@ -222,15 +222,15 @@ public class ResultImpl implements Result {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Return buildExtendedReturn() {
|
protected Output buildExtendedReturn() {
|
||||||
throw new IllegalStateException( "State does not define extended returns" );
|
throw new IllegalStateException( "State does not define extended returns" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class ResultSetReturnImpl implements ResultSetReturn {
|
protected static class ResultSetOutputImpl implements ResultSetOutput {
|
||||||
private final List results;
|
private final List results;
|
||||||
|
|
||||||
public ResultSetReturnImpl(List results) {
|
public ResultSetOutputImpl(List results) {
|
||||||
this.results = results;
|
this.results = results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,10 +257,10 @@ public class ResultImpl implements Result {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class UpdateCountReturnImpl implements UpdateCountReturn {
|
protected static class UpdateCountOutputImpl implements UpdateCountOutput {
|
||||||
private final int updateCount;
|
private final int updateCount;
|
||||||
|
|
||||||
public UpdateCountReturnImpl(int updateCount) {
|
public UpdateCountOutputImpl(int updateCount) {
|
||||||
this.updateCount = updateCount;
|
this.updateCount = updateCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,16 +33,15 @@ import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.mapping.AuxiliaryDatabaseObject;
|
import org.hibernate.mapping.AuxiliaryDatabaseObject;
|
||||||
import org.hibernate.procedure.ProcedureCall;
|
import org.hibernate.procedure.ProcedureCall;
|
||||||
import org.hibernate.procedure.ProcedureResult;
|
import org.hibernate.procedure.ProcedureOutputs;
|
||||||
import org.hibernate.result.ResultSetReturn;
|
import org.hibernate.result.ResultSetOutput;
|
||||||
import org.hibernate.result.Return;
|
import org.hibernate.result.Output;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.hibernate.testing.junit4.ExtraAssertions;
|
|
||||||
|
|
||||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -171,10 +170,10 @@ public class StoredProcedureTest extends BaseCoreFunctionalTestCase {
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
|
|
||||||
ProcedureCall query = session.createStoredProcedureCall( "user");
|
ProcedureCall query = session.createStoredProcedureCall( "user");
|
||||||
ProcedureResult procedureResult = query.getResult();
|
ProcedureOutputs procedureResult = query.getResult();
|
||||||
Return currentReturn = procedureResult.getCurrentReturn();
|
Output currentOutput = procedureResult.getCurrentOutput();
|
||||||
assertNotNull( currentReturn );
|
assertNotNull( currentOutput );
|
||||||
ResultSetReturn resultSetReturn = assertTyping( ResultSetReturn.class, currentReturn );
|
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||||
String name = (String) resultSetReturn.getSingleResult();
|
String name = (String) resultSetReturn.getSingleResult();
|
||||||
assertEquals( "SA", name );
|
assertEquals( "SA", name );
|
||||||
|
|
||||||
|
@ -188,10 +187,10 @@ public class StoredProcedureTest extends BaseCoreFunctionalTestCase {
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
|
|
||||||
ProcedureCall query = session.createStoredProcedureCall( "findOneUser" );
|
ProcedureCall query = session.createStoredProcedureCall( "findOneUser" );
|
||||||
ProcedureResult procedureResult = query.getResult();
|
ProcedureOutputs procedureResult = query.getResult();
|
||||||
Return currentReturn = procedureResult.getCurrentReturn();
|
Output currentOutput = procedureResult.getCurrentOutput();
|
||||||
assertNotNull( currentReturn );
|
assertNotNull( currentOutput );
|
||||||
ResultSetReturn resultSetReturn = assertTyping( ResultSetReturn.class, currentReturn );
|
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||||
Object result = resultSetReturn.getSingleResult();
|
Object result = resultSetReturn.getSingleResult();
|
||||||
assertTyping( Object[].class, result );
|
assertTyping( Object[].class, result );
|
||||||
String name = (String) ( (Object[]) result )[1];
|
String name = (String) ( (Object[]) result )[1];
|
||||||
|
@ -207,10 +206,10 @@ public class StoredProcedureTest extends BaseCoreFunctionalTestCase {
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
|
|
||||||
ProcedureCall query = session.createStoredProcedureCall( "findUsers" );
|
ProcedureCall query = session.createStoredProcedureCall( "findUsers" );
|
||||||
ProcedureResult procedureResult = query.getResult();
|
ProcedureOutputs procedureResult = query.getResult();
|
||||||
Return currentReturn = procedureResult.getCurrentReturn();
|
Output currentOutput = procedureResult.getCurrentOutput();
|
||||||
assertNotNull( currentReturn );
|
assertNotNull( currentOutput );
|
||||||
ResultSetReturn resultSetReturn = assertTyping( ResultSetReturn.class, currentReturn );
|
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||||
List results = resultSetReturn.getResultList();
|
List results = resultSetReturn.getResultList();
|
||||||
assertEquals( 3, results.size() );
|
assertEquals( 3, results.size() );
|
||||||
|
|
||||||
|
@ -244,10 +243,10 @@ public class StoredProcedureTest extends BaseCoreFunctionalTestCase {
|
||||||
ProcedureCall query = session.createStoredProcedureCall( "findUserRange" );
|
ProcedureCall query = session.createStoredProcedureCall( "findUserRange" );
|
||||||
query.registerParameter( "start", Integer.class, ParameterMode.IN ).bindValue( 1 );
|
query.registerParameter( "start", Integer.class, ParameterMode.IN ).bindValue( 1 );
|
||||||
query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 );
|
query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 );
|
||||||
ProcedureResult procedureResult = query.getResult();
|
ProcedureOutputs procedureResult = query.getResult();
|
||||||
Return currentReturn = procedureResult.getCurrentReturn();
|
Output currentOutput = procedureResult.getCurrentOutput();
|
||||||
assertNotNull( currentReturn );
|
assertNotNull( currentOutput );
|
||||||
ResultSetReturn resultSetReturn = assertTyping( ResultSetReturn.class, currentReturn );
|
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||||
List results = resultSetReturn.getResultList();
|
List results = resultSetReturn.getResultList();
|
||||||
assertEquals( 1, results.size() );
|
assertEquals( 1, results.size() );
|
||||||
Object result = results.get( 0 );
|
Object result = results.get( 0 );
|
||||||
|
@ -269,10 +268,10 @@ public class StoredProcedureTest extends BaseCoreFunctionalTestCase {
|
||||||
ProcedureCall query = session.createStoredProcedureCall( "findUserRange" );
|
ProcedureCall query = session.createStoredProcedureCall( "findUserRange" );
|
||||||
query.registerParameter( 1, Integer.class, ParameterMode.IN ).bindValue( 1 );
|
query.registerParameter( 1, Integer.class, ParameterMode.IN ).bindValue( 1 );
|
||||||
query.registerParameter( 2, Integer.class, ParameterMode.IN ).bindValue( 2 );
|
query.registerParameter( 2, Integer.class, ParameterMode.IN ).bindValue( 2 );
|
||||||
ProcedureResult procedureResult = query.getResult();
|
ProcedureOutputs procedureResult = query.getResult();
|
||||||
Return currentReturn = procedureResult.getCurrentReturn();
|
Output currentOutput = procedureResult.getCurrentOutput();
|
||||||
assertNotNull( currentReturn );
|
assertNotNull( currentOutput );
|
||||||
ResultSetReturn resultSetReturn = assertTyping( ResultSetReturn.class, currentReturn );
|
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||||
List results = resultSetReturn.getResultList();
|
List results = resultSetReturn.getResultList();
|
||||||
assertEquals( 1, results.size() );
|
assertEquals( 1, results.size() );
|
||||||
Object result = results.get( 0 );
|
Object result = results.get( 0 );
|
||||||
|
|
|
@ -41,14 +41,13 @@ import java.util.List;
|
||||||
import org.hibernate.CacheMode;
|
import org.hibernate.CacheMode;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.procedure.ParameterRegistration;
|
|
||||||
import org.hibernate.procedure.ProcedureCall;
|
import org.hibernate.procedure.ProcedureCall;
|
||||||
import org.hibernate.procedure.ProcedureCallMemento;
|
import org.hibernate.procedure.ProcedureCallMemento;
|
||||||
import org.hibernate.procedure.ProcedureResult;
|
import org.hibernate.procedure.ProcedureOutputs;
|
||||||
import org.hibernate.result.NoMoreReturnsException;
|
import org.hibernate.result.NoMoreReturnsException;
|
||||||
import org.hibernate.result.ResultSetReturn;
|
import org.hibernate.result.ResultSetOutput;
|
||||||
import org.hibernate.result.Return;
|
import org.hibernate.result.Output;
|
||||||
import org.hibernate.result.UpdateCountReturn;
|
import org.hibernate.result.UpdateCountOutput;
|
||||||
import org.hibernate.jpa.spi.BaseQueryImpl;
|
import org.hibernate.jpa.spi.BaseQueryImpl;
|
||||||
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
|
||||||
*/
|
*/
|
||||||
public class StoredProcedureQueryImpl extends BaseQueryImpl implements StoredProcedureQuery {
|
public class StoredProcedureQueryImpl extends BaseQueryImpl implements StoredProcedureQuery {
|
||||||
private final ProcedureCall procedureCall;
|
private final ProcedureCall procedureCall;
|
||||||
private ProcedureResult procedureResult;
|
private ProcedureOutputs procedureResult;
|
||||||
|
|
||||||
public StoredProcedureQueryImpl(ProcedureCall procedureCall, HibernateEntityManagerImplementor entityManager) {
|
public StoredProcedureQueryImpl(ProcedureCall procedureCall, HibernateEntityManagerImplementor entityManager) {
|
||||||
super( entityManager );
|
super( entityManager );
|
||||||
|
@ -200,7 +199,7 @@ public class StoredProcedureQueryImpl extends BaseQueryImpl implements StoredPro
|
||||||
|
|
||||||
// outputs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// outputs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
private ProcedureResult outputs() {
|
private ProcedureOutputs outputs() {
|
||||||
if ( procedureResult == null ) {
|
if ( procedureResult == null ) {
|
||||||
procedureResult = procedureCall.getResult();
|
procedureResult = procedureCall.getResult();
|
||||||
}
|
}
|
||||||
|
@ -220,8 +219,8 @@ public class StoredProcedureQueryImpl extends BaseQueryImpl implements StoredPro
|
||||||
@Override
|
@Override
|
||||||
public boolean execute() {
|
public boolean execute() {
|
||||||
try {
|
try {
|
||||||
final Return rtn = outputs().getCurrentReturn();
|
final Output rtn = outputs().getCurrentOutput();
|
||||||
return rtn != null && ResultSetReturn.class.isInstance( rtn );
|
return rtn != null && ResultSetOutput.class.isInstance( rtn );
|
||||||
}
|
}
|
||||||
catch (NoMoreReturnsException e) {
|
catch (NoMoreReturnsException e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -238,18 +237,18 @@ public class StoredProcedureQueryImpl extends BaseQueryImpl implements StoredPro
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasMoreResults() {
|
public boolean hasMoreResults() {
|
||||||
return outputs().hasMoreReturns() && ResultSetReturn.class.isInstance( outputs().getCurrentReturn() );
|
return outputs().hasMoreOutput() && ResultSetOutput.class.isInstance( outputs().getCurrentOutput() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUpdateCount() {
|
public int getUpdateCount() {
|
||||||
try {
|
try {
|
||||||
final Return rtn = outputs().getCurrentReturn();
|
final Output rtn = outputs().getCurrentOutput();
|
||||||
if ( rtn == null ) {
|
if ( rtn == null ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if ( UpdateCountReturn.class.isInstance( rtn ) ) {
|
else if ( UpdateCountOutput.class.isInstance( rtn ) ) {
|
||||||
return ( (UpdateCountReturn) rtn ).getUpdateCount();
|
return ( (UpdateCountOutput) rtn ).getUpdateCount();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -263,12 +262,12 @@ public class StoredProcedureQueryImpl extends BaseQueryImpl implements StoredPro
|
||||||
@Override
|
@Override
|
||||||
public List getResultList() {
|
public List getResultList() {
|
||||||
try {
|
try {
|
||||||
final Return rtn = outputs().getCurrentReturn();
|
final Output rtn = outputs().getCurrentOutput();
|
||||||
if ( ! ResultSetReturn.class.isInstance( rtn ) ) {
|
if ( ! ResultSetOutput.class.isInstance( rtn ) ) {
|
||||||
throw new IllegalStateException( "Current CallableStatement return was not a ResultSet, but getResultList was called" );
|
throw new IllegalStateException( "Current CallableStatement return was not a ResultSet, but getResultList was called" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( (ResultSetReturn) rtn ).getResultList();
|
return ( (ResultSetOutput) rtn ).getResultList();
|
||||||
}
|
}
|
||||||
catch (NoMoreReturnsException e) {
|
catch (NoMoreReturnsException e) {
|
||||||
// todo : the spec is completely silent on these type of edge-case scenarios.
|
// todo : the spec is completely silent on these type of edge-case scenarios.
|
||||||
|
@ -307,7 +306,7 @@ public class StoredProcedureQueryImpl extends BaseQueryImpl implements StoredPro
|
||||||
if ( ProcedureCall.class.isAssignableFrom( cls ) ) {
|
if ( ProcedureCall.class.isAssignableFrom( cls ) ) {
|
||||||
return (T) procedureCall;
|
return (T) procedureCall;
|
||||||
}
|
}
|
||||||
else if ( ProcedureResult.class.isAssignableFrom( cls ) ) {
|
else if ( ProcedureOutputs.class.isAssignableFrom( cls ) ) {
|
||||||
return (T) outputs();
|
return (T) outputs();
|
||||||
}
|
}
|
||||||
else if ( BaseQueryImpl.class.isAssignableFrom( cls ) ) {
|
else if ( BaseQueryImpl.class.isAssignableFrom( cls ) ) {
|
||||||
|
|
Loading…
Reference in New Issue