HHH-18280 Add test for issue
This commit is contained in:
parent
7c84a5b597
commit
79480ab490
|
@ -176,7 +176,7 @@ public class StructAggregateEmbeddableInheritanceTest implements AdditionalMappi
|
|||
}
|
||||
final ProcedureCall structFunction = session.createStoredProcedureCall( "structProcedure" );
|
||||
final ProcedureParameter<ParentEmbeddable> resultParameter = structFunction.registerParameter(
|
||||
"structType",
|
||||
"result",
|
||||
ParentEmbeddable.class,
|
||||
parameterMode
|
||||
);
|
||||
|
|
|
@ -588,7 +588,7 @@ public class NestedStructEmbeddableTest implements AdditionalMappingContributor
|
|||
}
|
||||
ProcedureCall structFunction = entityManager.createStoredProcedureCall( "structProcedure" );
|
||||
ProcedureParameter<TheStruct> resultParameter = structFunction.registerParameter(
|
||||
"structType",
|
||||
"result",
|
||||
TheStruct.class,
|
||||
parameterMode
|
||||
);
|
||||
|
|
|
@ -527,7 +527,7 @@ public class StructEmbeddableArrayTest implements AdditionalMappingContributor {
|
|||
}
|
||||
ProcedureCall structFunction = entityManager.createStoredProcedureCall( "structProcedure" );
|
||||
ProcedureParameter<EmbeddableAggregate[]> resultParameter = structFunction.registerParameter(
|
||||
"structType",
|
||||
"result",
|
||||
EmbeddableAggregate[].class,
|
||||
parameterMode
|
||||
);
|
||||
|
|
|
@ -546,7 +546,7 @@ public class StructEmbeddableTest implements AdditionalMappingContributor {
|
|||
}
|
||||
ProcedureCall structFunction = entityManager.createStoredProcedureCall( "structProcedure" );
|
||||
ProcedureParameter<EmbeddableAggregate> resultParameter = structFunction.registerParameter(
|
||||
"structType",
|
||||
"result",
|
||||
EmbeddableAggregate.class,
|
||||
parameterMode
|
||||
);
|
||||
|
|
|
@ -509,7 +509,7 @@ public class StructWithArrayEmbeddableTest implements AdditionalMappingContribut
|
|||
}
|
||||
ProcedureCall structFunction = entityManager.createStoredProcedureCall( "structProcedure" );
|
||||
ProcedureParameter<EmbeddableWithArrayAggregate> resultParameter = structFunction.registerParameter(
|
||||
"structType",
|
||||
"result",
|
||||
EmbeddableWithArrayAggregate.class,
|
||||
parameterMode
|
||||
);
|
||||
|
|
|
@ -71,6 +71,9 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
public class OracleStoredProcedureTest {
|
||||
|
||||
private Person person1;
|
||||
private static final String CITY = "London";
|
||||
private static final String STREET = "Lollard Street";
|
||||
private static final String ZIP = "SE116UG";
|
||||
|
||||
@Test
|
||||
public void testUnRegisteredParameter(EntityManagerFactoryScope scope) {
|
||||
|
@ -91,18 +94,47 @@ public class OracleStoredProcedureTest {
|
|||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnRegisteredParameterByName2(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( (em) -> {
|
||||
final StoredProcedureQuery function = em.createStoredProcedureQuery( "find_char", Integer.class );
|
||||
function.setHint( QueryHints.CALLABLE_FUNCTION, "true" );
|
||||
// search-string
|
||||
function.registerStoredProcedureParameter( "search_char", String.class, ParameterMode.IN );
|
||||
// source-string
|
||||
function.registerStoredProcedureParameter( "string", String.class, ParameterMode.IN );
|
||||
|
||||
function.setParameter( "search_char", "." );
|
||||
function.setParameter( "string", "org.hibernate.query" );
|
||||
|
||||
final Object singleResult = function.getSingleResult();
|
||||
Assertions.assertThat( singleResult ).isInstanceOf( Integer.class );
|
||||
Assertions.assertThat( singleResult ).isEqualTo( 4 );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnRegisteredParameterByNameInvertedParameterRegistrationOrder(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( (em) -> {
|
||||
final StoredProcedureQuery function = em.createStoredProcedureQuery( "find_char", Integer.class );
|
||||
function.setHint( QueryHints.CALLABLE_FUNCTION, "true" );
|
||||
// search-string
|
||||
function.registerStoredProcedureParameter( "string", String.class, ParameterMode.IN );
|
||||
// source-string
|
||||
function.registerStoredProcedureParameter( "search_char", String.class, ParameterMode.IN );
|
||||
|
||||
function.setParameter( "string", "org.hibernate.query");
|
||||
function.setParameter( "search_char", "." );
|
||||
|
||||
final Object singleResult = function.getSingleResult();
|
||||
Assertions.assertThat( singleResult ).isInstanceOf( Integer.class );
|
||||
Assertions.assertThat( singleResult ).isEqualTo( 4 );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-15542")
|
||||
public void testStoredProcedureInAndOutAndRefCursorParameters(EntityManagerFactoryScope scope) {
|
||||
String city = "London";
|
||||
String street = "Lollard Street";
|
||||
String zip = "SE116UG";
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
Address address = new Address( 1l, street, city, zip );
|
||||
entityManager.persist( address );
|
||||
}
|
||||
);
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "GET_ADDRESS_BY_NAME" );
|
||||
|
@ -111,15 +143,71 @@ public class OracleStoredProcedureTest {
|
|||
query.registerStoredProcedureParameter( "rec_out", ResultSet.class, ParameterMode.REF_CURSOR );
|
||||
query.registerStoredProcedureParameter( "err_out", String.class, ParameterMode.OUT );
|
||||
|
||||
query.setParameter( "street_in", street )
|
||||
.setParameter( "city_in", city );
|
||||
query.setParameter( "street_in", STREET )
|
||||
.setParameter( "city_in", CITY );
|
||||
query.execute();
|
||||
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
|
||||
try {
|
||||
assertTrue( rs.next() );
|
||||
assertThat( rs.getString( "street" ), is( street ) );
|
||||
assertThat( rs.getString( "city" ), is( city ) );
|
||||
assertThat( rs.getString( "zip" ), is( zip ) );
|
||||
assertThat( rs.getString( "street" ), is( STREET ) );
|
||||
assertThat( rs.getString( "city" ), is( CITY ) );
|
||||
assertThat( rs.getString( "zip" ), is( ZIP ) );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-18280")
|
||||
public void testStoredProcedureInAndOutAndRefCursorParametersInvertedParamRegistationOrder(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "GET_ADDRESS_BY_NAME" );
|
||||
query.registerStoredProcedureParameter( "city_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "street_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "rec_out", ResultSet.class, ParameterMode.REF_CURSOR );
|
||||
query.registerStoredProcedureParameter( "err_out", String.class, ParameterMode.OUT );
|
||||
|
||||
query.setParameter( "street_in", STREET )
|
||||
.setParameter( "city_in", CITY );
|
||||
query.execute();
|
||||
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
|
||||
try {
|
||||
assertTrue( rs.next() );
|
||||
assertThat( rs.getString( "street" ), is( STREET ) );
|
||||
assertThat( rs.getString( "city" ), is( CITY ) );
|
||||
assertThat( rs.getString( "zip" ), is( ZIP ) );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-18280")
|
||||
public void testStoredProcedureInAndOutAndRefCursorParametersInvertedParamRegistationOrder2(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "GET_ADDRESS_BY_NAME" );
|
||||
query.registerStoredProcedureParameter( "city_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "street_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "rec_out", ResultSet.class, ParameterMode.REF_CURSOR );
|
||||
query.registerStoredProcedureParameter( "err_out", String.class, ParameterMode.OUT );
|
||||
|
||||
query.setParameter( "city_in", CITY )
|
||||
.setParameter( "street_in", STREET );
|
||||
query.execute();
|
||||
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
|
||||
try {
|
||||
assertTrue( rs.next() );
|
||||
assertThat( rs.getString( "street" ), is( STREET ) );
|
||||
assertThat( rs.getString( "city" ), is( CITY ) );
|
||||
assertThat( rs.getString( "zip" ), is( ZIP ) );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
|
@ -510,6 +598,9 @@ public class OracleStoredProcedureTest {
|
|||
phone2.setValid( false );
|
||||
|
||||
person1.addPhone( phone2 );
|
||||
|
||||
Address address = new Address( 1l, STREET, CITY, ZIP );
|
||||
entityManager.persist( address );
|
||||
} );
|
||||
}
|
||||
|
||||
|
@ -538,6 +629,7 @@ public class OracleStoredProcedureTest {
|
|||
people.forEach( em::remove );
|
||||
|
||||
em.createQuery( "delete IdHolder" ).executeUpdate();
|
||||
em.createQuery( "delete Address" ).executeUpdate();
|
||||
});
|
||||
} );
|
||||
}
|
||||
|
@ -566,7 +658,7 @@ public class OracleStoredProcedureTest {
|
|||
String name;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Address")
|
||||
@Table(name="ADDRESS_TABLE")
|
||||
public static class Address{
|
||||
@Id
|
||||
|
|
|
@ -10,34 +10,36 @@ import java.sql.CallableStatement;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.persistence.ParameterMode;
|
||||
import jakarta.persistence.StoredProcedureQuery;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.boot.model.relational.Database;
|
||||
import org.hibernate.boot.model.relational.NamedAuxiliaryDatabaseObject;
|
||||
import org.hibernate.boot.model.relational.Namespace;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.dialect.PostgresPlusDialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.procedure.ProcedureCall;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ParameterMode;
|
||||
import jakarta.persistence.StoredProcedureQuery;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -46,122 +48,23 @@ import static org.junit.Assert.fail;
|
|||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
@Jpa(
|
||||
annotatedClasses = {
|
||||
Person.class,
|
||||
Phone.class
|
||||
};
|
||||
}
|
||||
Phone.class,
|
||||
PostgreSQLStoredProcedureTest.Address.class
|
||||
}
|
||||
)
|
||||
@RequiresDialect(value = PostgreSQLDialect.class)
|
||||
public class PostgreSQLStoredProcedureTest {
|
||||
|
||||
@Override
|
||||
protected void applyMetadataImplementor(MetadataImplementor metadataImplementor) {
|
||||
final Database database = metadataImplementor.getDatabase();
|
||||
final Namespace namespace = database.getDefaultNamespace();
|
||||
database.addAuxiliaryDatabaseObject(
|
||||
new NamedAuxiliaryDatabaseObject(
|
||||
"sp_count_phones",
|
||||
namespace,
|
||||
"CREATE OR REPLACE PROCEDURE sp_count_phones( " +
|
||||
" IN personId bigint, " +
|
||||
" INOUT phoneCount bigint) " +
|
||||
" AS " +
|
||||
"$BODY$ " +
|
||||
" BEGIN " +
|
||||
" SELECT COUNT(*) INTO phoneCount " +
|
||||
" FROM phone " +
|
||||
" WHERE person_id = personId; " +
|
||||
" END; " +
|
||||
"$BODY$ " +
|
||||
"LANGUAGE plpgsql;",
|
||||
"DROP PROCEDURE sp_count_phones(bigint, bigint)",
|
||||
Set.of( PostgreSQLDialect.class.getName(), PostgresPlusDialect.class.getName() )
|
||||
)
|
||||
);
|
||||
database.addAuxiliaryDatabaseObject(
|
||||
new NamedAuxiliaryDatabaseObject(
|
||||
"sp_phones",
|
||||
namespace,
|
||||
"CREATE OR REPLACE PROCEDURE sp_phones(IN personId BIGINT, INOUT phones REFCURSOR) " +
|
||||
" AS " +
|
||||
"$BODY$ " +
|
||||
" BEGIN " +
|
||||
" OPEN phones FOR " +
|
||||
" SELECT * " +
|
||||
" FROM phone " +
|
||||
" WHERE person_id = personId; " +
|
||||
" END; " +
|
||||
"$BODY$ " +
|
||||
"LANGUAGE plpgsql",
|
||||
"DROP PROCEDURE sp_phones(bigint, refcursor)",
|
||||
Set.of( PostgreSQLDialect.class.getName(), PostgresPlusDialect.class.getName() )
|
||||
)
|
||||
);
|
||||
database.addAuxiliaryDatabaseObject(
|
||||
new NamedAuxiliaryDatabaseObject(
|
||||
"singleRefCursor",
|
||||
namespace,
|
||||
"CREATE OR REPLACE PROCEDURE singleRefCursor(INOUT p_recordset REFCURSOR) " +
|
||||
" AS " +
|
||||
"$BODY$ " +
|
||||
" BEGIN " +
|
||||
" OPEN p_recordset FOR SELECT 1; " +
|
||||
" END; " +
|
||||
"$BODY$ " +
|
||||
"LANGUAGE plpgsql;",
|
||||
"DROP PROCEDURE singleRefCursor(refcursor)",
|
||||
Set.of( PostgreSQLDialect.class.getName(), PostgresPlusDialect.class.getName() )
|
||||
)
|
||||
);
|
||||
database.addAuxiliaryDatabaseObject(
|
||||
new NamedAuxiliaryDatabaseObject(
|
||||
"sp_is_null",
|
||||
namespace,
|
||||
"CREATE OR REPLACE PROCEDURE sp_is_null( " +
|
||||
" IN param varchar(255), " +
|
||||
" INOUT result boolean) " +
|
||||
" AS " +
|
||||
"$BODY$ " +
|
||||
" BEGIN " +
|
||||
" select param is null into result; " +
|
||||
" END; " +
|
||||
"$BODY$ " +
|
||||
"LANGUAGE plpgsql;",
|
||||
"DROP PROCEDURE sp_is_null(varchar, boolean)",
|
||||
Set.of( PostgreSQLDialect.class.getName(), PostgresPlusDialect.class.getName() )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Person person1 = new Person( 1L, "John Doe" );
|
||||
person1.setNickName( "JD" );
|
||||
person1.setAddress( "Earth" );
|
||||
person1.setCreatedOn( Timestamp.from( LocalDateTime.of( 2000, 1, 1, 0, 0, 0 )
|
||||
.toInstant( ZoneOffset.UTC ) ) );
|
||||
|
||||
entityManager.persist( person1 );
|
||||
|
||||
Phone phone1 = new Phone( "123-456-7890" );
|
||||
phone1.setId( 1L );
|
||||
|
||||
person1.addPhone( phone1 );
|
||||
|
||||
Phone phone2 = new Phone( "098_765-4321" );
|
||||
phone2.setId( 2L );
|
||||
|
||||
person1.addPhone( phone2 );
|
||||
} );
|
||||
}
|
||||
private static final String CITY = "London";
|
||||
private static final String STREET = "Lollard Street";
|
||||
private static final String ZIP = "SE116UG";
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureOutParameter() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testStoredProcedureOutParameter(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_count_phones" );
|
||||
query.registerStoredProcedureParameter( "personId", Long.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "phoneCount", Long.class, ParameterMode.INOUT );
|
||||
|
@ -177,8 +80,8 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
|
||||
@Test
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 14, comment = "Stored procedure OUT parameters are only supported since version 14")
|
||||
public void testStoredProcedureRefCursor() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testStoredProcedureRefCursor(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_phones" );
|
||||
query.registerStoredProcedureParameter( 1, Long.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( 2, void.class, ParameterMode.REF_CURSOR );
|
||||
|
@ -191,8 +94,8 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureWithJDBC() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testStoredProcedureWithJDBC(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Session session = entityManager.unwrap( Session.class );
|
||||
Long phoneCount = session.doReturningWork( connection -> {
|
||||
CallableStatement procedure = null;
|
||||
|
@ -215,8 +118,8 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProcedureWithJDBCByName() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testProcedureWithJDBCByName(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
try {
|
||||
Session session = entityManager.unwrap( Session.class );
|
||||
Long phoneCount = session.doReturningWork( connection -> {
|
||||
|
@ -245,9 +148,8 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
@Test
|
||||
@JiraKey("HHH-11863")
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 14, comment = "Stored procedure OUT parameters are only supported since version 14")
|
||||
public void testSysRefCursorAsOutParameter() {
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testSysRefCursorAsOutParameter(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Long value = null;
|
||||
|
||||
Session session = entityManager.unwrap( Session.class );
|
||||
|
@ -299,9 +201,8 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
|
||||
@Test
|
||||
@JiraKey("HHH-12905")
|
||||
public void testStoredProcedureNullParameterHibernate() {
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testStoredProcedureNullParameterHibernate(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
ProcedureCall procedureCall = entityManager.unwrap( Session.class )
|
||||
.createStoredProcedureCall( "sp_is_null" );
|
||||
procedureCall.registerParameter( 1, StandardBasicTypes.STRING, ParameterMode.IN );
|
||||
|
@ -314,7 +215,7 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
assertTrue( result );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
ProcedureCall procedureCall = entityManager.unwrap( Session.class )
|
||||
.createStoredProcedureCall( "sp_is_null" );
|
||||
procedureCall.registerParameter( 1, StandardBasicTypes.STRING, ParameterMode.IN );
|
||||
|
@ -330,9 +231,8 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
|
||||
@Test
|
||||
@JiraKey("HHH-12905")
|
||||
public void testStoredProcedureNullParameterHibernateWithoutEnablePassingNulls() {
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testStoredProcedureNullParameterHibernateWithoutEnablePassingNulls(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
ProcedureCall procedureCall = entityManager.unwrap( Session.class )
|
||||
.createStoredProcedureCall( "sp_is_null" );
|
||||
procedureCall.registerParameter( "param", StandardBasicTypes.STRING, ParameterMode.IN );
|
||||
|
@ -345,9 +245,8 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureNullParameterHibernateWithoutSettingTheParameter() {
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testStoredProcedureNullParameterHibernateWithoutSettingTheParameter(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
try {
|
||||
ProcedureCall procedureCall = entityManager.unwrap( Session.class )
|
||||
.createStoredProcedureCall( "sp_is_null" );
|
||||
|
@ -366,4 +265,250 @@ public class PostgreSQLStoredProcedureTest extends BaseEntityManagerFunctionalTe
|
|||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureInAndOutAndRefCursorParameters(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_get_address_by_street_city" );
|
||||
query.registerStoredProcedureParameter( "street_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "city_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "rec_out", ResultSet.class, ParameterMode.REF_CURSOR );
|
||||
|
||||
query.setParameter( "street_in", STREET )
|
||||
.setParameter( "city_in", CITY );
|
||||
query.execute();
|
||||
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
|
||||
try {
|
||||
Assertions.assertTrue( rs.next() );
|
||||
assertThat( rs.getString( "street" ), is( STREET ) );
|
||||
assertThat( rs.getString( "city" ), is( CITY ) );
|
||||
assertThat( rs.getString( "zip" ), is( ZIP ) );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureInAndOutAndRefCursorParametersDifferentRegistrationOrder(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_get_address_by_street_city" );
|
||||
query.registerStoredProcedureParameter( "city_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "street_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "rec_out", ResultSet.class, ParameterMode.REF_CURSOR );
|
||||
|
||||
query.setParameter( "street_in", STREET )
|
||||
.setParameter( "city_in", CITY );
|
||||
query.execute();
|
||||
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
|
||||
try {
|
||||
Assertions.assertTrue( rs.next() );
|
||||
assertThat( rs.getString( "street" ), is( STREET ) );
|
||||
assertThat( rs.getString( "city" ), is( CITY ) );
|
||||
assertThat( rs.getString( "zip" ), is( ZIP ) );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureInAndOutAndRefCursorParametersDifferentRegistrationOrder2(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_get_address_by_street_city" );
|
||||
query.registerStoredProcedureParameter( "rec_out", ResultSet.class, ParameterMode.REF_CURSOR );
|
||||
query.registerStoredProcedureParameter( "city_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "street_in", String.class, ParameterMode.IN );
|
||||
|
||||
query.setParameter( "street_in", STREET )
|
||||
.setParameter( "city_in", CITY );
|
||||
query.execute();
|
||||
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
|
||||
try {
|
||||
Assertions.assertTrue( rs.next() );
|
||||
assertThat( rs.getString( "street" ), is( STREET ) );
|
||||
assertThat( rs.getString( "city" ), is( CITY ) );
|
||||
assertThat( rs.getString( "zip" ), is( ZIP ) );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void prepareSchema(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( (entityManager) -> entityManager.unwrap( Session.class ).doWork( (connection) -> {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(
|
||||
"CREATE OR REPLACE PROCEDURE sp_count_phones( " +
|
||||
" IN personId bigint, " +
|
||||
" INOUT phoneCount bigint) " +
|
||||
" AS " +
|
||||
"$BODY$ " +
|
||||
" BEGIN " +
|
||||
" SELECT COUNT(*) INTO phoneCount " +
|
||||
" FROM phone " +
|
||||
" WHERE person_id = personId; " +
|
||||
" END; " +
|
||||
"$BODY$ " +
|
||||
"LANGUAGE plpgsql;"
|
||||
);
|
||||
statement.executeUpdate(
|
||||
"CREATE OR REPLACE PROCEDURE sp_phones(IN personId BIGINT, INOUT phones REFCURSOR) " +
|
||||
" AS " +
|
||||
"$BODY$ " +
|
||||
" BEGIN " +
|
||||
" OPEN phones FOR " +
|
||||
" SELECT * " +
|
||||
" FROM phone " +
|
||||
" WHERE person_id = personId; " +
|
||||
" END; " +
|
||||
"$BODY$ " +
|
||||
"LANGUAGE plpgsql"
|
||||
);
|
||||
statement.executeUpdate(
|
||||
"CREATE OR REPLACE PROCEDURE singleRefCursor(INOUT p_recordset REFCURSOR) " +
|
||||
" AS " +
|
||||
"$BODY$ " +
|
||||
" BEGIN " +
|
||||
" OPEN p_recordset FOR SELECT 1; " +
|
||||
" END; " +
|
||||
"$BODY$ " +
|
||||
"LANGUAGE plpgsql;"
|
||||
);
|
||||
statement.executeUpdate(
|
||||
"CREATE OR REPLACE PROCEDURE sp_is_null( " +
|
||||
" IN param varchar(255), " +
|
||||
" INOUT result boolean) " +
|
||||
" AS " +
|
||||
"$BODY$ " +
|
||||
" BEGIN " +
|
||||
" select param is null into result; " +
|
||||
" END; " +
|
||||
"$BODY$ " +
|
||||
"LANGUAGE plpgsql;"
|
||||
);
|
||||
statement.executeUpdate(
|
||||
"CREATE OR REPLACE PROCEDURE sp_get_address_by_street_city (" +
|
||||
" IN street_in varchar(255) ," +
|
||||
" IN city_in varchar(255)" +
|
||||
" ,INOUT rec_out REFCURSOR" +
|
||||
" )" +
|
||||
" AS" +
|
||||
" $BODY$ " +
|
||||
" BEGIN" +
|
||||
" OPEN rec_out FOR" +
|
||||
" SELECT * " +
|
||||
" FROM ADDRESS_TABLE A " +
|
||||
" WHERE " +
|
||||
" A.STREET = street_in" +
|
||||
" AND A.CITY = city_in;" +
|
||||
" END; " +
|
||||
" $BODY$ " +
|
||||
" LANGUAGE plpgsql"
|
||||
);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
System.err.println( "Error exporting procedure and function definitions to Oracle database : " + e.getMessage() );
|
||||
e.printStackTrace( System.err );
|
||||
}
|
||||
} ) );
|
||||
|
||||
scope.inTransaction( (entityManager) -> {
|
||||
Person person1 = new Person( 1L, "John Doe" );
|
||||
person1.setNickName( "JD" );
|
||||
person1.setAddress( "Earth" );
|
||||
person1.setCreatedOn( Timestamp.from( LocalDateTime.of( 2000, 1, 1, 0, 0, 0 )
|
||||
.toInstant( ZoneOffset.UTC ) ) );
|
||||
|
||||
entityManager.persist( person1 );
|
||||
|
||||
Phone phone1 = new Phone( "123-456-7890" );
|
||||
phone1.setId( 1L );
|
||||
|
||||
person1.addPhone( phone1 );
|
||||
|
||||
Phone phone2 = new Phone( "098_765-4321" );
|
||||
phone2.setId( 2L );
|
||||
|
||||
person1.addPhone( phone2 );
|
||||
|
||||
Address address = new Address( 1l, STREET, CITY, ZIP );
|
||||
entityManager.persist( address );
|
||||
} );
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanUpSchema(EntityManagerFactoryScope scope) {
|
||||
scope.inEntityManager( (em) -> {
|
||||
final Session session = em.unwrap( Session.class );
|
||||
session.doWork( connection -> {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate( "DROP PROCEDURE sp_count_phones(bigint, bigint)" );
|
||||
statement.executeUpdate( "DROP PROCEDURE sp_phones(bigint, refcursor)" );
|
||||
statement.executeUpdate( "DROP PROCEDURE singleRefCursor(refcursor)" );
|
||||
statement.executeUpdate( "DROP PROCEDURE sp_is_null(varchar, boolean)" );
|
||||
statement.executeUpdate( "DROP PROCEDURE sp_get_address_by_street_city(varchar,varchar,refcursor)" );
|
||||
}
|
||||
catch (SQLException ignore) {
|
||||
}
|
||||
} );
|
||||
|
||||
scope.inTransaction( em, (em2) -> {
|
||||
final List<Person> people = em.createQuery( "from Person", Person.class ).getResultList();
|
||||
people.forEach( em::remove );
|
||||
|
||||
em.createQuery( "delete Address" ).executeUpdate();
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "Address")
|
||||
@Table(name = "ADDRESS_TABLE")
|
||||
public static class Address {
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
private long id;
|
||||
@Column(name = "STREET")
|
||||
private String street;
|
||||
@Column(name = "CITY")
|
||||
private String city;
|
||||
@Column(name = "ZIP")
|
||||
private String zip;
|
||||
|
||||
public Address() {
|
||||
}
|
||||
|
||||
public Address(long id, String street, String city, String zip) {
|
||||
this.id = id;
|
||||
this.street = street;
|
||||
this.city = city;
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public String getZip() {
|
||||
return zip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.util.regex.Pattern;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
|
@ -24,9 +25,15 @@ import org.junit.jupiter.api.AfterEach;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ParameterMode;
|
||||
import jakarta.persistence.StoredProcedureQuery;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInAutoCommit;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
@ -40,16 +47,23 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
annotatedClasses = {
|
||||
Person.class,
|
||||
Phone.class,
|
||||
SQLServerStoredProcedureTest.Address.class
|
||||
}
|
||||
)
|
||||
public class SQLServerStoredProcedureTest {
|
||||
|
||||
private static final String CITY = "London";
|
||||
private static final String STREET = "Lollard Street";
|
||||
private static final String ZIP = "SE116UG";
|
||||
|
||||
@BeforeEach
|
||||
public void init(EntityManagerFactoryScope scope) {
|
||||
doInAutoCommit(
|
||||
"DROP PROCEDURE sp_count_phones",
|
||||
"DROP FUNCTION fn_count_phones",
|
||||
"DROP PROCEDURE sp_phones",
|
||||
"DROP PROCEDURE sp_zip_by_city_and_street",
|
||||
"DROP PROCEDURE sp_insert_address",
|
||||
"CREATE PROCEDURE sp_count_phones " +
|
||||
" @personId INT, " +
|
||||
" @phoneCount INT OUTPUT " +
|
||||
|
@ -79,7 +93,35 @@ public class SQLServerStoredProcedureTest {
|
|||
" SELECT * " +
|
||||
" FROM Phone " +
|
||||
" WHERE person_id = @personId; " +
|
||||
" OPEN @phones;"
|
||||
" OPEN @phones;" +
|
||||
"END",
|
||||
"CREATE PROCEDURE sp_insert_address " +
|
||||
" @id BIGINT," +
|
||||
" @street VARCHAR(255) = '" + STREET + "'," +
|
||||
" @zip VARCHAR(255)," +
|
||||
" @city VARCHAR(255) = '" + CITY + "'" +
|
||||
"AS " +
|
||||
"BEGIN " +
|
||||
" INSERT INTO " +
|
||||
" ADDRESS_TABLE (ID, STREET, CITY, ZIP) " +
|
||||
" VALUES ( " +
|
||||
" @id," +
|
||||
" @street," +
|
||||
" @city," +
|
||||
" @zip);" +
|
||||
"END",
|
||||
"CREATE PROCEDURE sp_zip_by_city_and_street " +
|
||||
" @street_in VARCHAR(255)," +
|
||||
" @city_in VARCHAR(255) = '" + CITY + "'," +
|
||||
" @zip_out VARCHAR(255) OUTPUT " +
|
||||
"AS " +
|
||||
"BEGIN " +
|
||||
" SELECT @zip_out = A.ZIP" +
|
||||
" FROM ADDRESS_TABLE A " +
|
||||
" WHERE " +
|
||||
" A.STREET = @street_in" +
|
||||
" AND A.CITY = @city_in;" +
|
||||
"END"
|
||||
);
|
||||
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
@ -100,11 +142,14 @@ public class SQLServerStoredProcedureTest {
|
|||
phone2.setId( 2L );
|
||||
|
||||
person1.addPhone( phone2 );
|
||||
|
||||
Address address = new Address( 1l, STREET, CITY, ZIP );
|
||||
entityManager.persist( address );
|
||||
} );
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(EntityManagerFactoryScope scope){
|
||||
public void tearDown(EntityManagerFactoryScope scope) {
|
||||
scope.releaseEntityManagerFactory();
|
||||
}
|
||||
|
||||
|
@ -123,6 +168,24 @@ public class SQLServerStoredProcedureTest {
|
|||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureDefaultValue(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_insert_address" );
|
||||
query.registerStoredProcedureParameter( "street", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "id", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "zip", String.class, ParameterMode.IN );
|
||||
|
||||
query.setParameter( "id", 2 )
|
||||
.setParameter( "street", STREET )
|
||||
.setParameter( "zip", "SE116UG" );
|
||||
query.execute();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureRefCursor(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
@ -166,4 +229,117 @@ public class SQLServerStoredProcedureTest {
|
|||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-18280")
|
||||
public void testStoredProcedureInAndOutParametersInvertedParamRegistationOrder2(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_zip_by_city_and_street" );
|
||||
query.registerStoredProcedureParameter( "city_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "street_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "zip_out", String.class, ParameterMode.OUT );
|
||||
|
||||
query.setParameter( "street_in", STREET )
|
||||
.setParameter( "city_in", CITY );
|
||||
query.execute();
|
||||
assertThat( (String) query.getOutputParameterValue( "zip_out" ) ).isEqualTo( ZIP );
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-18280")
|
||||
public void testStoredProcedureInAndOutParametersInvertedParamRegistationOrder2_(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
Session session = entityManager.unwrap( Session.class );
|
||||
session.doWork( connection -> {
|
||||
try (CallableStatement statement = connection.prepareCall(
|
||||
"{call sp_zip_by_city_and_street ( @zip_out = ?, @city_in = ?, @street_in = ? )}" )) {
|
||||
statement.registerOutParameter( 1, Types.VARCHAR );
|
||||
statement.setString( 2, CITY );
|
||||
statement.setString( 3, STREET );
|
||||
statement.execute();
|
||||
assertThat( (String) statement.getString( 1 ) ).isEqualTo( ZIP );
|
||||
|
||||
}
|
||||
} );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-18280")
|
||||
public void testStoredProcedureInAndOutParametersInvertedParamRegistationOrder3(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_zip_by_city_and_street" );
|
||||
query.registerStoredProcedureParameter( "zip_out", String.class, ParameterMode.OUT );
|
||||
query.registerStoredProcedureParameter( "street_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "city_in", String.class, ParameterMode.IN );
|
||||
|
||||
query.setParameter( "city_in", CITY )
|
||||
.setParameter( "street_in", STREET );
|
||||
query.execute();
|
||||
assertThat( (String) query.getOutputParameterValue( "zip_out" ) ).isEqualTo( ZIP );
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnRegisteredParameterByName(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( (entityManager) -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_zip_by_city_and_street" );
|
||||
query.registerStoredProcedureParameter( "street_in", String.class, ParameterMode.IN );
|
||||
query.registerStoredProcedureParameter( "zip_out", String.class, ParameterMode.OUT );
|
||||
query.setParameter( "street_in", STREET );
|
||||
query.execute();
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "Address")
|
||||
@Table(name = "ADDRESS_TABLE")
|
||||
public static class Address {
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
private long id;
|
||||
@Column(name = "STREET")
|
||||
private String street;
|
||||
@Column(name = "CITY")
|
||||
private String city;
|
||||
@Column(name = "ZIP")
|
||||
private String zip;
|
||||
|
||||
public Address() {
|
||||
}
|
||||
|
||||
public Address(long id, String street, String city, String zip) {
|
||||
this.id = id;
|
||||
this.street = street;
|
||||
this.city = city;
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public String getZip() {
|
||||
return zip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,21 @@ public class SybaseStoredProcedureTest {
|
|||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureOutParameterDifferentParametersRegistrationOrder(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_count_phones" );
|
||||
query.registerStoredProcedureParameter( "phoneCount", Long.class, ParameterMode.OUT );
|
||||
query.registerStoredProcedureParameter( "personId", Long.class, ParameterMode.IN );
|
||||
|
||||
query.setParameter( "personId", 1L );
|
||||
|
||||
query.execute();
|
||||
Long phoneCount = (Long) query.getOutputParameterValue( "phoneCount" );
|
||||
assertEquals( Long.valueOf( 2 ), phoneCount );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresDialectFeature(feature = DialectFeatureChecks.IsJtds.class, reverse = true, comment = "jTDS can't handle calling functions")
|
||||
public void testFunctionReturnValue(EntityManagerFactoryScope scope) {
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class CustomStoredProcTestSupport extends CustomSQLTestSupport {
|
|||
Session s = openSession();
|
||||
// Query namedQuery = s.getNamedQuery( "simpleScalar" );
|
||||
ProcedureCall namedQuery = s.createNamedStoredProcedureQuery( "simpleScalar" );
|
||||
namedQuery.setParameter( "number", 43 );
|
||||
namedQuery.setParameter( "p_number", 43 );
|
||||
List list = namedQuery.getResultList();
|
||||
Object o[] = ( Object[] ) list.get( 0 );
|
||||
assertEquals( o[0], "getAll" );
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<sql-query name="simpleScalar" callable="true">
|
||||
<return-scalar column="name" type="string"/>
|
||||
<return-scalar column="`value`" type="long"/>
|
||||
{ call simpleScalar(:number) }
|
||||
{ call simpleScalar(:p_number) }
|
||||
</sql-query>
|
||||
<sql-query name="paramhandling" callable="true">
|
||||
<return-scalar column="`value`" type="long" />
|
||||
|
|
|
@ -186,7 +186,7 @@
|
|||
<sql-query name="simpleScalar" callable="true">
|
||||
<return-scalar column="name" type="string"/>
|
||||
<return-scalar column="`value`" type="long"/>
|
||||
{ call simpleScalar(:number) }
|
||||
{ call simpleScalar(:p_number) }
|
||||
</sql-query>
|
||||
|
||||
<sql-query name="paramhandling" callable="true">
|
||||
|
@ -259,7 +259,7 @@
|
|||
|
||||
<database-object>
|
||||
<create>
|
||||
CREATE PROCEDURE simpleScalar (j SMALLINT)
|
||||
CREATE PROCEDURE simpleScalar (p_number SMALLINT)
|
||||
PARAMETER STYLE JAVA
|
||||
LANGUAGE JAVA
|
||||
READS SQL DATA
|
||||
|
|
|
@ -184,7 +184,7 @@
|
|||
<sql-query name="simpleScalar" callable="true">
|
||||
<return-scalar column="name" type="string"/>
|
||||
<return-scalar column="`value`" type="long"/>
|
||||
{ call simpleScalar(:number) }
|
||||
{ call simpleScalar(:p_number) }
|
||||
</sql-query>
|
||||
|
||||
<sql-query name="paramhandling" callable="true">
|
||||
|
@ -248,8 +248,8 @@
|
|||
|
||||
<database-object>
|
||||
<create>
|
||||
CREATE PROCEDURE simpleScalar (number int)
|
||||
SELECT number AS value, 'getAll' AS name
|
||||
CREATE PROCEDURE simpleScalar (p_number int)
|
||||
SELECT p_number AS value, 'getAll' AS name
|
||||
</create>
|
||||
<drop>
|
||||
DROP PROCEDURE simpleScalar
|
||||
|
|
|
@ -202,11 +202,11 @@
|
|||
|
||||
<database-object>
|
||||
<create>
|
||||
CREATE OR REPLACE FUNCTION simpleScalar (j number)
|
||||
CREATE OR REPLACE FUNCTION simpleScalar (p_number number)
|
||||
RETURN SYS_REFCURSOR AS st_cursor SYS_REFCURSOR;
|
||||
BEGIN
|
||||
OPEN st_cursor FOR
|
||||
SELECT j as value, 'getAll' as name from dual;
|
||||
SELECT p_number as value, 'getAll' as name from dual;
|
||||
RETURN st_cursor;
|
||||
END;
|
||||
</create>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<sql-query name="simpleScalar" callable="true">
|
||||
<return-scalar column="name" type="string"/>
|
||||
<return-scalar column="`value`" type="long"/>
|
||||
{ ? = call simpleScalar(:number) }
|
||||
{ ? = call simpleScalar(:p_number) }
|
||||
</sql-query>
|
||||
|
||||
<sql-query name="paramhandling" callable="true">
|
||||
|
|
|
@ -185,7 +185,7 @@
|
|||
<sql-query name="simpleScalar" callable="true">
|
||||
<return-scalar column="name" type="string"/>
|
||||
<return-scalar column="`value`" type="long"/>
|
||||
{ call simpleScalar(:number) }
|
||||
{ call simpleScalar(:p_number) }
|
||||
</sql-query>
|
||||
|
||||
<sql-query name="paramhandling" callable="true">
|
||||
|
@ -270,8 +270,8 @@
|
|||
|
||||
<database-object>
|
||||
<create>
|
||||
CREATE PROCEDURE simpleScalar @number int AS
|
||||
SELECT @number as value, 'getAll' as name
|
||||
CREATE PROCEDURE simpleScalar @p_number int AS
|
||||
SELECT @p_number as value, 'getAll' as name
|
||||
</create>
|
||||
<drop>
|
||||
DROP PROCEDURE simpleScalar
|
||||
|
|
|
@ -185,7 +185,7 @@
|
|||
<sql-query name="simpleScalar" callable="true">
|
||||
<return-scalar column="name" type="string"/>
|
||||
<return-scalar column="`value`" type="long"/>
|
||||
{ call simpleScalar(:number) }
|
||||
{ call simpleScalar(:p_number) }
|
||||
</sql-query>
|
||||
|
||||
<sql-query name="paramhandling" callable="true">
|
||||
|
@ -270,8 +270,8 @@
|
|||
|
||||
<database-object>
|
||||
<create>
|
||||
CREATE PROCEDURE simpleScalar @number int AS
|
||||
SELECT @number as value, 'getAll' as name
|
||||
CREATE PROCEDURE simpleScalar @p_number int AS
|
||||
SELECT @p_number as value, 'getAll' as name
|
||||
</create>
|
||||
<drop>
|
||||
DROP PROCEDURE simpleScalar
|
||||
|
|
Loading…
Reference in New Issue