Move and adapt tests from sql/storedproc
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
bd2f8271bd
commit
5df67d8b43
|
@ -15,15 +15,12 @@ import javax.persistence.Table;
|
|||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.query.QueryParameter;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.sql.storedproc.StoredProcedureResultSetMappingTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.sql.storedproc;
|
||||
package org.hibernate.orm.test.sql.storedproc;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityResult;
|
||||
import javax.persistence.FieldResult;
|
||||
|
@ -17,6 +16,7 @@ import javax.persistence.QueryHint;
|
|||
import javax.persistence.SqlResultSetMapping;
|
||||
import javax.persistence.StoredProcedureParameter;
|
||||
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
@ -26,8 +26,8 @@ import org.hibernate.dialect.H2Dialect;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class H2ProcTesting {
|
||||
public static void applyProcDefinitions(Configuration configuration) {
|
||||
configuration.addAuxiliaryDatabaseObject(
|
||||
public static void applyProcDefinitions(MetadataBuilder metadataBuilder) {
|
||||
metadataBuilder.applyAuxiliaryDatabaseObject(
|
||||
new AuxiliaryDatabaseObject() {
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
|
@ -71,7 +71,7 @@ public class H2ProcTesting {
|
|||
}
|
||||
);
|
||||
|
||||
configuration.addAuxiliaryDatabaseObject(
|
||||
metadataBuilder.applyAuxiliaryDatabaseObject(
|
||||
new AuxiliaryDatabaseObject() {
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
|
@ -115,7 +115,7 @@ public class H2ProcTesting {
|
|||
}
|
||||
);
|
||||
|
||||
configuration.addAuxiliaryDatabaseObject(
|
||||
metadataBuilder.applyAuxiliaryDatabaseObject(
|
||||
new AuxiliaryDatabaseObject() {
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.sql.storedproc;
|
||||
package org.hibernate.orm.test.sql.storedproc;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
@ -15,11 +15,8 @@ import javax.persistence.Table;
|
|||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||
|
@ -28,21 +25,20 @@ import org.hibernate.procedure.ProcedureCall;
|
|||
import org.hibernate.procedure.ProcedureOutputs;
|
||||
import org.hibernate.result.ResultSetOutput;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialect( value = PostgreSQLDialect.class, strictMatching = false )
|
||||
@FailureExpected( jiraKey = "HHH-8445", message = "Waiting on EG clarification" )
|
||||
public class PostgresRefCursorSupportTest extends BaseUnitTestCase {
|
||||
@RequiresDialect( value = PostgreSQLDialect.class )
|
||||
//@FailureExpected( jiraKey = "HHH-8445", reason = "Waiting on EG clarification" )
|
||||
@NotImplementedYet(reason = "org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs not yet implemented")
|
||||
public class PostgresRefCursorSupportTest extends BaseSessionFactoryFunctionalTest {
|
||||
|
||||
public static class ProcedureDefinitions implements AuxiliaryDatabaseObject, AuxiliaryDatabaseObject.Expandable {
|
||||
/**
|
||||
|
@ -105,36 +101,28 @@ public class PostgresRefCursorSupportTest extends BaseUnitTestCase {
|
|||
private Date availabilityEndDate;
|
||||
}
|
||||
|
||||
private SessionFactory sf;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
Configuration cfg = new Configuration()
|
||||
.addAnnotatedClass( Item.class )
|
||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.addAuxiliaryDatabaseObject( ProcedureDefinitions.INSTANCE );
|
||||
|
||||
sf = cfg.buildSessionFactory();
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Item.class
|
||||
};
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() {
|
||||
if ( sf != null ) {
|
||||
sf.close();
|
||||
}
|
||||
@Override
|
||||
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
super.applyMetadataBuilder( metadataBuilder );
|
||||
metadataBuilder.applyAuxiliaryDatabaseObject( ProcedureDefinitions.INSTANCE );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitClassReturn() {
|
||||
Session session = sf.openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
ProcedureCall call = session.createStoredProcedureCall( "all_items", Item.class );
|
||||
call.registerParameter( 1, void.class, ParameterMode.REF_CURSOR );
|
||||
ProcedureOutputs outputs = call.getOutputs();
|
||||
ResultSetOutput results = assertTyping( ResultSetOutput.class, outputs.getCurrent() );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
inTransaction(
|
||||
session -> {
|
||||
ProcedureCall call = session.createStoredProcedureCall( "all_items", Item.class );
|
||||
call.registerParameter( 1, void.class, ParameterMode.REF_CURSOR );
|
||||
ProcedureOutputs outputs = call.getOutputs();
|
||||
ResultSetOutput results = assertTyping( ResultSetOutput.class, outputs.getCurrent() );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -4,37 +4,42 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.sql.storedproc;
|
||||
package org.hibernate.orm.test.sql.storedproc;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.procedure.ProcedureOutputs;
|
||||
import org.hibernate.result.Output;
|
||||
import org.hibernate.result.ResultSetOutput;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialect( H2Dialect.class )
|
||||
public class ResultMappingTest extends BaseCoreFunctionalTestCase {
|
||||
@NotImplementedYet(reason = "org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs not yet implemented")
|
||||
public class ResultMappingTest extends BaseSessionFactoryFunctionalTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { H2ProcTesting.MyEntity.class };
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
H2ProcTesting.MyEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
H2ProcTesting.applyProcDefinitions( configuration );
|
||||
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
super.applyMetadataBuilder( metadataBuilder );
|
||||
H2ProcTesting.applyProcDefinitions( metadataBuilder );
|
||||
}
|
||||
|
||||
@Test
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.sql.storedproc;
|
||||
package org.hibernate.orm.test.sql.storedproc;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.persistence.ColumnResult;
|
||||
|
@ -16,29 +16,29 @@ import javax.persistence.Table;
|
|||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.procedure.ProcedureOutputs;
|
||||
import org.hibernate.result.ResultSetOutput;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialect( H2Dialect.class )
|
||||
public class StoredProcedureResultSetMappingTest extends BaseUnitTestCase {
|
||||
@NotImplementedYet(reason = "org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs not yet implemented")
|
||||
public class StoredProcedureResultSetMappingTest extends BaseSessionFactoryFunctionalTest {
|
||||
@Entity( name = "Employee" )
|
||||
@Table( name = "EMP" )
|
||||
// ignore the questionable-ness of constructing a partial entity
|
||||
|
@ -121,24 +121,29 @@ public class StoredProcedureResultSetMappingTest extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Employee.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
super.applyMetadataBuilder( metadataBuilder );
|
||||
metadataBuilder.applyAuxiliaryDatabaseObject( new ProcedureDefinition() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialResults() {
|
||||
Configuration cfg = new Configuration()
|
||||
.addAnnotatedClass( Employee.class )
|
||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.addAuxiliaryDatabaseObject( new ProcedureDefinition() );
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
Session session = sf.openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
ProcedureCall call = session.createStoredProcedureCall( "allEmployeeNames", "id-fname-lname" );
|
||||
ProcedureOutputs outputs = call.getOutputs();
|
||||
ResultSetOutput output = assertTyping( ResultSetOutput.class, outputs.getCurrent() );
|
||||
assertEquals( 3, output.getResultList().size() );
|
||||
assertTyping( Employee.class, output.getResultList().get( 0 ) );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
inTransaction(
|
||||
session -> {
|
||||
ProcedureCall call = session.createStoredProcedureCall( "allEmployeeNames", "id-fname-lname" );
|
||||
ProcedureOutputs outputs = call.getOutputs();
|
||||
ResultSetOutput output = assertTyping( ResultSetOutput.class, outputs.getCurrent() );
|
||||
assertEquals( 3, output.getResultList().size() );
|
||||
assertTyping( Employee.class, output.getResultList().get( 0 ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.orm.test.sql.storedproc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.procedure.ProcedureOutputs;
|
||||
import org.hibernate.result.Output;
|
||||
import org.hibernate.result.ResultSetOutput;
|
||||
|
||||
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
@NotImplementedYet(reason = "org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs not yet implemented")
|
||||
public class StoredProcedureTest extends BaseSessionFactoryFunctionalTest {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
H2ProcTesting.MyEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||
super.applyMetadataBuilder( metadataBuilder );
|
||||
H2ProcTesting.applyProcDefinitions( metadataBuilder );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void baseTest() {
|
||||
inTransaction( session -> {
|
||||
ProcedureCall procedureCall = session.createStoredProcedureCall( "user" );
|
||||
ProcedureOutputs procedureOutputs = procedureCall.getOutputs();
|
||||
Output currentOutput = procedureOutputs.getCurrent();
|
||||
assertNotNull( currentOutput );
|
||||
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||
String name = (String) resultSetReturn.getSingleResult();
|
||||
assertEquals( "SA", name );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSingleResultTuple() {
|
||||
inTransaction( session -> {
|
||||
ProcedureCall query = session.createStoredProcedureCall( "findOneUser" );
|
||||
ProcedureOutputs procedureResult = query.getOutputs();
|
||||
Output currentOutput = procedureResult.getCurrent();
|
||||
assertNotNull( currentOutput );
|
||||
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||
Object result = resultSetReturn.getSingleResult();
|
||||
assertTyping( Object[].class, result );
|
||||
String name = (String) ( (Object[]) result )[1];
|
||||
assertEquals( "Steve", name );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResultListTuple() {
|
||||
inTransaction( session -> {
|
||||
ProcedureCall query = session.createStoredProcedureCall( "findUsers" );
|
||||
ProcedureOutputs procedureResult = query.getOutputs();
|
||||
Output currentOutput = procedureResult.getCurrent();
|
||||
assertNotNull( currentOutput );
|
||||
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||
List results = resultSetReturn.getResultList();
|
||||
assertEquals( 3, results.size() );
|
||||
|
||||
for ( Object result : results ) {
|
||||
assertTyping( Object[].class, result );
|
||||
Integer id = (Integer) ( (Object[]) result )[0];
|
||||
String name = (String) ( (Object[]) result )[1];
|
||||
if ( id.equals( 1 ) ) {
|
||||
assertEquals( "Steve", name );
|
||||
}
|
||||
else if ( id.equals( 2 ) ) {
|
||||
assertEquals( "John", name );
|
||||
}
|
||||
else if ( id.equals( 3 ) ) {
|
||||
assertEquals( "Jane", name );
|
||||
}
|
||||
else {
|
||||
fail( "Unexpected id value found [" + id + "]" );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.sql.storedproc;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.ParameterMode;
|
||||
|
||||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.procedure.ProcedureOutputs;
|
||||
import org.hibernate.result.Output;
|
||||
import org.hibernate.result.ResultSetOutput;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialect( H2Dialect.class )
|
||||
public class StoredProcedureTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { H2ProcTesting.MyEntity.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
H2ProcTesting.applyProcDefinitions( configuration );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void baseTest() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
ProcedureCall procedureCall = session.createStoredProcedureCall( "user");
|
||||
ProcedureOutputs procedureOutputs = procedureCall.getOutputs();
|
||||
Output currentOutput = procedureOutputs.getCurrent();
|
||||
assertNotNull( currentOutput );
|
||||
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||
String name = (String) resultSetReturn.getSingleResult();
|
||||
assertEquals( "SA", name );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSingleResultTuple() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
ProcedureCall query = session.createStoredProcedureCall( "findOneUser" );
|
||||
ProcedureOutputs procedureResult = query.getOutputs();
|
||||
Output currentOutput = procedureResult.getCurrent();
|
||||
assertNotNull( currentOutput );
|
||||
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||
Object result = resultSetReturn.getSingleResult();
|
||||
assertTyping( Object[].class, result );
|
||||
String name = (String) ( (Object[]) result )[1];
|
||||
assertEquals( "Steve", name );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResultListTuple() {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
ProcedureCall query = session.createStoredProcedureCall( "findUsers" );
|
||||
ProcedureOutputs procedureResult = query.getOutputs();
|
||||
Output currentOutput = procedureResult.getCurrent();
|
||||
assertNotNull( currentOutput );
|
||||
ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput );
|
||||
List results = resultSetReturn.getResultList();
|
||||
assertEquals( 3, results.size() );
|
||||
|
||||
for ( Object result : results ) {
|
||||
assertTyping( Object[].class, result );
|
||||
Integer id = (Integer) ( (Object[]) result )[0];
|
||||
String name = (String) ( (Object[]) result )[1];
|
||||
if ( id.equals( 1 ) ) {
|
||||
assertEquals( "Steve", name );
|
||||
}
|
||||
else if ( id.equals( 2 ) ) {
|
||||
assertEquals( "John", name );
|
||||
}
|
||||
else if ( id.equals( 3 ) ) {
|
||||
assertEquals( "Jane", name );
|
||||
}
|
||||
else {
|
||||
fail( "Unexpected id value found [" + id + "]" );
|
||||
}
|
||||
}
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.sql.storedproc;
|
||||
package org.hibernate.orm.test.sql.storedproc;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.ParameterMode;
|
||||
|
|
Loading…
Reference in New Issue