@Test public void testHibernateProcedureCallRefCursor() { doInJPA(entityManager -> { Session session = entityManager.unwrap(Session.class); ProcedureCall call = session .createStoredProcedureCall("post_comments"); call.registerParameter(1, void.class, ParameterMode.REF_CURSOR); call.registerParameter(2, Long.class, ParameterMode.IN).bindValue(1L); Output output = call.getOutputs().getCurrent(); if (output.isResultSet()) { List<Object[]> postComments = ((ResultSetOutput) output).getResultList(); assertEquals(2, postComments.size()); } }); }
@Override @SuppressWarnings("UnnecessaryLocalVariable") public ProcedureCall getNamedProcedureCall(String name) { errorIfClosed(); final ProcedureCallMemento memento = factory.getNamedQueryRepository().getNamedProcedureCallMemento( name ); if ( memento == null ) { throw new IllegalArgumentException( "Could not find named stored procedure call with that registration name : " + name ); } final ProcedureCall procedureCall = memento.makeProcedureCall( this ); // procedureCall.setComment( "Named stored procedure call [" + name + "]" ); return procedureCall; }
@Override @SuppressWarnings("UnnecessaryLocalVariable") public ProcedureCall createStoredProcedureCall(String procedureName) { errorIfClosed(); final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; }
@Override @SuppressWarnings("UnnecessaryLocalVariable") public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { errorIfClosed(); final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName, resultClasses ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; }
@Override @SuppressWarnings("UnnecessaryLocalVariable") public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) { errorIfClosed(); final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName, resultSetMappings ); // call.setComment( "Dynamic stored procedure call" ); return procedureCall; }
@Test public void testHibernateProcedureCallOutParameter() { doInJPA(entityManager -> { Session session = entityManager.unwrap(Session.class); ProcedureCall call = session.createStoredProcedureCall("getStatistics"); call.registerParameter("postId", Long.class, ParameterMode.IN).bindValue(1L); call.registerParameter("commentCount", Long.class, ParameterMode.OUT); Long commentCount = (Long) call.getOutputs().getOutputParameterValue("commentCount"); assertEquals(Long.valueOf(2), commentCount); }); }
@Test public void testHibernateProcedureCallReturnValueParameter() { doInJPA(entityManager -> { Session session = entityManager.unwrap(Session.class); ProcedureCall call = session.createStoredProcedureCall("post_comments"); call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L); Output output = call.getOutputs().getCurrent(); if (output.isResultSet()) { List<Object[]> postComments = ((ResultSetOutput) output).getResultList(); assertEquals(2, postComments.size()); } }); }
@Test public void testHibernateProcedureCallRefCursor() { doInJPA(entityManager -> { Session session = entityManager.unwrap(Session.class); ProcedureCall call = session.createStoredProcedureCall("post_comments"); call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L); call.registerParameter(2, Class.class, ParameterMode.REF_CURSOR); Output output = call.getOutputs().getCurrent(); if (output.isResultSet()) { List<Object[]> postComments = ((ResultSetOutput) output).getResultList(); assertEquals(2, postComments.size()); } }); }
@Override public ProcedureCall getNamedProcedureCall(String name) { return session.getNamedProcedureCall( name ); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName) { return session.createStoredProcedureCall( procedureName ); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { return session.createStoredProcedureCall( procedureName, resultClasses ); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) { return session.createStoredProcedureCall( procedureName, resultSetMappings ); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName) { errorIfClosed(); checkTransactionSynchStatus(); return super.createStoredProcedureCall( procedureName ); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) { errorIfClosed(); checkTransactionSynchStatus(); return super.createStoredProcedureCall( procedureName, resultSetMappings ); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) { errorIfClosed(); checkTransactionSynchStatus(); return super.createStoredProcedureCall( procedureName, resultClasses ); }
@Override @SuppressWarnings("unchecked") public ProcedureCall registerParameter0(int position, Class type, ParameterMode mode) { registerParameter( position, type, mode ); return this; }
@Override @SuppressWarnings("unchecked") public ProcedureCall registerParameter0(String name, Class type, ParameterMode mode) { registerParameter( name, type, mode ); return this; }
@Override public ProcedureCall makeProcedureCall(Session session) { return new ProcedureCallImpl( (SessionImplementor) session, this ); }
@Override public ProcedureCall makeProcedureCall(SessionImplementor session) { return new ProcedureCallImpl( session, this ); }
@Override public ProcedureCall getNamedProcedureCall(String name) { return target.getNamedProcedureCall(name); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName) { return target.createStoredProcedureCall(procedureName); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName, @SuppressWarnings("rawtypes") Class... resultClasses) { return target.createStoredProcedureCall(procedureName, resultClasses); }
@Override public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) { return target.createStoredProcedureCall(procedureName, resultSetMappings); }
/** * Gets a ProcedureCall based on a named template * * @param name The name given to the template * * @return The ProcedureCall * * @see javax.persistence.NamedStoredProcedureQuery */ public ProcedureCall getNamedProcedureCall(String name);
/** * Creates a call to a stored procedure. * * @param procedureName The name of the procedure. * * @return The representation of the procedure call. */ public ProcedureCall createStoredProcedureCall(String procedureName);
/** * Creates a call to a stored procedure with specific result set entity mappings. Each class named * is considered a "root return". * * @param procedureName The name of the procedure. * @param resultClasses The entity(s) to map the result on to. * * @return The representation of the procedure call. */ public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses);
/** * Creates a call to a stored procedure with specific result set entity mappings. * * @param procedureName The name of the procedure. * @param resultSetMappings The explicit result set mapping(s) to use for mapping the results * * @return The representation of the procedure call. */ public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings);