use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class MySQLStoredProcedureTest method testStoredProcedureReturnValue.
@Test
public void testStoredProcedureReturnValue() {
doInJPA(this::entityManagerFactory, entityManager -> {
// tag::sql-jpa-call-sp-no-out-mysql-example[]
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_phones");
query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
query.setParameter(1, 1L);
List<Object[]> personComments = query.getResultList();
// end::sql-jpa-call-sp-no-out-mysql-example[]
assertEquals(2, personComments.size());
});
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class OracleStoredProcedureTest method testStoredProcedureRefCursor.
@Test
public void testStoredProcedureRefCursor() {
doInJPA(this::entityManagerFactory, entityManager -> {
// tag::sql-jpa-call-sp-ref-cursor-oracle-example[]
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_person_phones");
query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
query.registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR);
query.setParameter(1, 1L);
query.execute();
List<Object[]> postComments = query.getResultList();
// end::sql-jpa-call-sp-ref-cursor-oracle-example[]
assertNotNull(postComments);
});
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class HANAStoredProcedureTest method testOutAndSysRefCursorAsOutParameter.
@Test
@TestForIssue(jiraKey = "HHH-12138")
public void testOutAndSysRefCursorAsOutParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
StoredProcedureQuery function = entityManager.createNamedStoredProcedureQuery("outAndRefCursor");
function.execute();
Integer value = (Integer) function.getSingleResult();
assertEquals(Integer.valueOf(1), value);
assertEquals(Integer.valueOf(1), function.getOutputParameterValue(1));
assertFalse(function.hasMoreResults());
});
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class PostgreSQLStoredProcedureTest method testStoredProcedureOutParameter.
@Test
public void testStoredProcedureOutParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_count_phones");
query.registerStoredProcedureParameter("personId", Long.class, ParameterMode.IN);
query.registerStoredProcedureParameter("phoneCount", Long.class, ParameterMode.OUT);
query.setParameter("personId", 1L);
query.execute();
Long phoneCount = (Long) query.getOutputParameterValue("phoneCount");
assertEquals(Long.valueOf(2), phoneCount);
});
}
use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.
the class PostgreSQLStoredProcedureTest method testSysRefCursorAsOutParameter.
@Test
@TestForIssue(jiraKey = "HHH-11863")
public void testSysRefCursorAsOutParameter() {
doInJPA(this::entityManagerFactory, entityManager -> {
Long value = null;
Session session = entityManager.unwrap(Session.class);
try (ResultSet resultSet = session.doReturningWork(connection -> {
CallableStatement function = null;
try {
function = connection.prepareCall("{ ? = call singleRefCursor() }");
function.registerOutParameter(1, Types.REF_CURSOR);
function.execute();
return (ResultSet) function.getObject(1);
} finally {
if (function != null) {
function.close();
}
}
})) {
while (resultSet.next()) {
value = resultSet.getLong(1);
}
} catch (Exception e) {
fail(e.getMessage());
}
assertEquals(Long.valueOf(1), value);
StoredProcedureQuery function = entityManager.createStoredProcedureQuery("singleRefCursor");
function.registerStoredProcedureParameter(1, void.class, ParameterMode.REF_CURSOR);
function.execute();
assertFalse(function.hasMoreResults());
value = null;
try (ResultSet resultSet = (ResultSet) function.getOutputParameterValue(1)) {
while (resultSet.next()) {
value = resultSet.getLong(1);
}
} catch (SQLException e) {
fail(e.getMessage());
}
assertEquals(Long.valueOf(1), value);
});
}
Aggregations