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.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.dialect.Dialect;
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.procedure.ProcedureCall;
|
import org.hibernate.procedure.ProcedureCall;
|
||||||
import org.hibernate.query.QueryParameter;
|
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.hibernate.test.sql.storedproc.StoredProcedureResultSetMappingTest;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* 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.Entity;
|
||||||
import javax.persistence.EntityResult;
|
import javax.persistence.EntityResult;
|
||||||
import javax.persistence.FieldResult;
|
import javax.persistence.FieldResult;
|
||||||
|
@ -17,6 +16,7 @@ import javax.persistence.QueryHint;
|
||||||
import javax.persistence.SqlResultSetMapping;
|
import javax.persistence.SqlResultSetMapping;
|
||||||
import javax.persistence.StoredProcedureParameter;
|
import javax.persistence.StoredProcedureParameter;
|
||||||
|
|
||||||
|
import org.hibernate.boot.MetadataBuilder;
|
||||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
@ -26,8 +26,8 @@ import org.hibernate.dialect.H2Dialect;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class H2ProcTesting {
|
public class H2ProcTesting {
|
||||||
public static void applyProcDefinitions(Configuration configuration) {
|
public static void applyProcDefinitions(MetadataBuilder metadataBuilder) {
|
||||||
configuration.addAuxiliaryDatabaseObject(
|
metadataBuilder.applyAuxiliaryDatabaseObject(
|
||||||
new AuxiliaryDatabaseObject() {
|
new AuxiliaryDatabaseObject() {
|
||||||
@Override
|
@Override
|
||||||
public String getExportIdentifier() {
|
public String getExportIdentifier() {
|
||||||
|
@ -71,7 +71,7 @@ public class H2ProcTesting {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
configuration.addAuxiliaryDatabaseObject(
|
metadataBuilder.applyAuxiliaryDatabaseObject(
|
||||||
new AuxiliaryDatabaseObject() {
|
new AuxiliaryDatabaseObject() {
|
||||||
@Override
|
@Override
|
||||||
public String getExportIdentifier() {
|
public String getExportIdentifier() {
|
||||||
|
@ -115,7 +115,7 @@ public class H2ProcTesting {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
configuration.addAuxiliaryDatabaseObject(
|
metadataBuilder.applyAuxiliaryDatabaseObject(
|
||||||
new AuxiliaryDatabaseObject() {
|
new AuxiliaryDatabaseObject() {
|
||||||
@Override
|
@Override
|
||||||
public String getExportIdentifier() {
|
public String getExportIdentifier() {
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -15,11 +15,8 @@ import javax.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.boot.MetadataBuilder;
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
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.Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||||
|
@ -28,21 +25,20 @@ import org.hibernate.procedure.ProcedureCall;
|
||||||
import org.hibernate.procedure.ProcedureOutputs;
|
import org.hibernate.procedure.ProcedureOutputs;
|
||||||
import org.hibernate.result.ResultSetOutput;
|
import org.hibernate.result.ResultSetOutput;
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@RequiresDialect( value = PostgreSQLDialect.class, strictMatching = false )
|
@RequiresDialect( value = PostgreSQLDialect.class )
|
||||||
@FailureExpected( jiraKey = "HHH-8445", message = "Waiting on EG clarification" )
|
//@FailureExpected( jiraKey = "HHH-8445", reason = "Waiting on EG clarification" )
|
||||||
public class PostgresRefCursorSupportTest extends BaseUnitTestCase {
|
@NotImplementedYet(reason = "org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs not yet implemented")
|
||||||
|
public class PostgresRefCursorSupportTest extends BaseSessionFactoryFunctionalTest {
|
||||||
|
|
||||||
public static class ProcedureDefinitions implements AuxiliaryDatabaseObject, AuxiliaryDatabaseObject.Expandable {
|
public static class ProcedureDefinitions implements AuxiliaryDatabaseObject, AuxiliaryDatabaseObject.Expandable {
|
||||||
/**
|
/**
|
||||||
|
@ -105,36 +101,28 @@ public class PostgresRefCursorSupportTest extends BaseUnitTestCase {
|
||||||
private Date availabilityEndDate;
|
private Date availabilityEndDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SessionFactory sf;
|
@Override
|
||||||
|
protected Class[] getAnnotatedClasses() {
|
||||||
@Before
|
return new Class[] {
|
||||||
public void beforeTest() {
|
Item.class
|
||||||
Configuration cfg = new Configuration()
|
};
|
||||||
.addAnnotatedClass( Item.class )
|
|
||||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
|
||||||
cfg.addAuxiliaryDatabaseObject( ProcedureDefinitions.INSTANCE );
|
|
||||||
|
|
||||||
sf = cfg.buildSessionFactory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@Override
|
||||||
public void afterTest() {
|
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||||
if ( sf != null ) {
|
super.applyMetadataBuilder( metadataBuilder );
|
||||||
sf.close();
|
metadataBuilder.applyAuxiliaryDatabaseObject( ProcedureDefinitions.INSTANCE );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitClassReturn() {
|
public void testExplicitClassReturn() {
|
||||||
Session session = sf.openSession();
|
inTransaction(
|
||||||
session.beginTransaction();
|
session -> {
|
||||||
|
ProcedureCall call = session.createStoredProcedureCall( "all_items", Item.class );
|
||||||
ProcedureCall call = session.createStoredProcedureCall( "all_items", Item.class );
|
call.registerParameter( 1, void.class, ParameterMode.REF_CURSOR );
|
||||||
call.registerParameter( 1, void.class, ParameterMode.REF_CURSOR );
|
ProcedureOutputs outputs = call.getOutputs();
|
||||||
ProcedureOutputs outputs = call.getOutputs();
|
ResultSetOutput results = assertTyping( ResultSetOutput.class, outputs.getCurrent() );
|
||||||
ResultSetOutput results = assertTyping( ResultSetOutput.class, outputs.getCurrent() );
|
}
|
||||||
|
);
|
||||||
session.getTransaction().commit();
|
|
||||||
session.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,37 +4,42 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* 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.dialect.H2Dialect;
|
||||||
import org.hibernate.procedure.ProcedureCall;
|
import org.hibernate.procedure.ProcedureCall;
|
||||||
import org.hibernate.procedure.ProcedureOutputs;
|
import org.hibernate.procedure.ProcedureOutputs;
|
||||||
import org.hibernate.result.Output;
|
import org.hibernate.result.Output;
|
||||||
import org.hibernate.result.ResultSetOutput;
|
import org.hibernate.result.ResultSetOutput;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||||
import org.junit.Test;
|
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;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@RequiresDialect( H2Dialect.class )
|
@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
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { H2ProcTesting.MyEntity.class };
|
return new Class[] {
|
||||||
|
H2ProcTesting.MyEntity.class
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(Configuration configuration) {
|
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||||
super.configure( configuration );
|
super.applyMetadataBuilder( metadataBuilder );
|
||||||
H2ProcTesting.applyProcDefinitions( configuration );
|
H2ProcTesting.applyProcDefinitions( metadataBuilder );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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 java.util.Date;
|
||||||
import javax.persistence.ColumnResult;
|
import javax.persistence.ColumnResult;
|
||||||
|
@ -16,29 +16,29 @@ import javax.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.boot.MetadataBuilder;
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
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.Dialect;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.procedure.ProcedureCall;
|
import org.hibernate.procedure.ProcedureCall;
|
||||||
import org.hibernate.procedure.ProcedureOutputs;
|
import org.hibernate.procedure.ProcedureOutputs;
|
||||||
import org.hibernate.result.ResultSetOutput;
|
import org.hibernate.result.ResultSetOutput;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||||
|
|
||||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@RequiresDialect( H2Dialect.class )
|
@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" )
|
@Entity( name = "Employee" )
|
||||||
@Table( name = "EMP" )
|
@Table( name = "EMP" )
|
||||||
// ignore the questionable-ness of constructing a partial entity
|
// 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
|
@Test
|
||||||
public void testPartialResults() {
|
public void testPartialResults() {
|
||||||
Configuration cfg = new Configuration()
|
inTransaction(
|
||||||
.addAnnotatedClass( Employee.class )
|
session -> {
|
||||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
ProcedureCall call = session.createStoredProcedureCall( "allEmployeeNames", "id-fname-lname" );
|
||||||
cfg.addAuxiliaryDatabaseObject( new ProcedureDefinition() );
|
ProcedureOutputs outputs = call.getOutputs();
|
||||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
ResultSetOutput output = assertTyping( ResultSetOutput.class, outputs.getCurrent() );
|
||||||
Session session = sf.openSession();
|
assertEquals( 3, output.getResultList().size() );
|
||||||
session.beginTransaction();
|
assertTyping( Employee.class, output.getResultList().get( 0 ) );
|
||||||
|
}
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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
|
* 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
|
* 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 java.util.List;
|
||||||
import javax.persistence.ParameterMode;
|
import javax.persistence.ParameterMode;
|
||||||
|
|
Loading…
Reference in New Issue