Stored Procedure added.

Added TestCase without using NamedStoredProcedure
This commit is contained in:
Giuseppe Bueti 2016-02-27 10:52:54 +01:00 committed by giuseppe.bueti
parent 3b5c46bbbf
commit 202a99786a
3 changed files with 21 additions and 3 deletions

View File

@ -0,0 +1,7 @@
create or replace PROCEDURE FIND_CAR_BY_YEAR ( p_year IN NUMBER, data OUT SYS_REFCURSOR ) AS
BEGIN
OPEN data FOR
SELECT ID, MODEL, YEAR
FROM CAR
WHERE YEAR = p_year;
END FIND_CAR_BY_YEAR;

View File

@ -1,4 +1,5 @@
INSERT INTO CAR (ID, MODEL, YEAR) VALUES ('123456', 'Camaro', '2012');
INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('12112', 'Fiat Panda', '2000')
INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('111000', 'Fiat Punto', '2007')
INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('3382', 'Citroen C3', '2009')
INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('12112', 'Fiat Panda', '2000');
INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('111000', 'Fiat Punto', '2007');
INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('3382', 'Citroen C3', '2009');
commit;

View File

@ -53,6 +53,16 @@ public class StoredProcedureTest {
storedProcedure.getResultList().forEach(c -> Assert.assertEquals("Camaro", ((Car) c).getModel()));
}
@Test
public void findCarsByYearNoNamedStored() {
StoredProcedureQuery findByYearProcedure =
entityManager.createStoredProcedureQuery("FIND_CAR_BY_YEAR", Car.class)
.registerStoredProcedureParameter("p_year", Integer.class, ParameterMode.IN)
.registerStoredProcedureParameter("data", Void.class, ParameterMode.REF_CURSOR).setParameter("p_year", 2015);
findByYearProcedure.getResultList().forEach(c -> Assert.assertEquals(new Integer(2015), ((Car) c).getYear()));
}
@AfterClass
public static void destroy() {