org.hibernate.procedure.ProcedureCall Java Examples

The following examples show how to use org.hibernate.procedure.ProcedureCall. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PostgreSQLStoredProcedureTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
@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());
        }
    });
}
 
Example #2
Source File: OracleStoredProcedureTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
@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);

        ProcedureOutputs outputs = call.getOutputs();
        try {
            Output output = outputs.getCurrent();

            if (output.isResultSet()) {
                List<Object[]> postComments = ((ResultSetOutput) output).getResultList();
                assertEquals(2, postComments.size());
            }
        } finally {
            outputs.release();
        }
    });
}
 
Example #3
Source File: PostgreSQLStoredProcedureTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcedureCallParameterDefaultClose() {
    doInJPA(entityManager -> {
        Session session = entityManager.unwrap(Session.class);

        ProcedureCall call = session.createStoredProcedureCall("count_comments");
        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);
    });
}
 
Example #4
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
	@SuppressWarnings("UnnecessaryLocalVariable")
	public ProcedureCall getNamedProcedureCall(String name) {
		checkOpen();

		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;
	}
 
Example #5
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
	@SuppressWarnings("UnnecessaryLocalVariable")
	public ProcedureCall createStoredProcedureCall(String procedureName) {
		checkOpen();
		final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName );
//		call.setComment( "Dynamic stored procedure call" );
		return procedureCall;
	}
 
Example #6
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
	@SuppressWarnings("UnnecessaryLocalVariable")
	public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) {
		checkOpen();
		final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName, resultClasses );
//		call.setComment( "Dynamic stored procedure call" );
		return procedureCall;
	}
 
Example #7
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
	@SuppressWarnings("UnnecessaryLocalVariable")
	public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) {
		checkOpen();
		final ProcedureCall procedureCall = new ProcedureCallImpl( this, procedureName, resultSetMappings );
//		call.setComment( "Dynamic stored procedure call" );
		return procedureCall;
	}
 
Example #8
Source File: MySQLStoredProcedureTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@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());
        }
    });
}
 
Example #9
Source File: MySQLStoredProcedureTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Test
public void testHibernateProcedureCallOutParameter() {
    doInJPA(entityManager -> {
        Session session = entityManager.unwrap(Session.class);
        ProcedureCall call = session.createStoredProcedureCall("count_comments");
        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);
    });
}
 
Example #10
Source File: ProcedureCallMementoImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ProcedureCall makeProcedureCall(SharedSessionContractImplementor session) {
	return new ProcedureCallImpl( session, this );
}
 
Example #11
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) {
	return target.createStoredProcedureCall(procedureName, resultSetMappings);
}
 
Example #12
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public ProcedureCall createStoredProcedureCall(String procedureName, @SuppressWarnings("rawtypes") Class... resultClasses) {
	return target.createStoredProcedureCall(procedureName, resultClasses);
}
 
Example #13
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public ProcedureCall createStoredProcedureCall(String procedureName) {
	return target.createStoredProcedureCall(procedureName);
}
 
Example #14
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public ProcedureCall getNamedProcedureCall(String name) {
	return target.getNamedProcedureCall(name);
}
 
Example #15
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ProcedureCall getNamedProcedureCall(String name) {
	return delegate.getNamedProcedureCall( name );
}
 
Example #16
Source File: ProcedureCallImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public ProcedureCall registerParameter0(String name, Class type, ParameterMode mode) {
	registerParameter( name, type, mode );
	return this;
}
 
Example #17
Source File: ProcedureCallImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public ProcedureCall registerParameter0(int position, Class type, ParameterMode mode) {
	registerParameter( position, type, mode );
	return this;
}
 
Example #18
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void addNamedStoredProcedureQuery(String name, ProcedureCall procedureCall) {
	getNamedQueryRepository().registerNamedProcedureCallMemento(
			name,
			procedureCall.extractMemento( procedureCall.getHints() )
	);
}
 
Example #19
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
	public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) {
		checkOpen();
//		checkTransactionSynchStatus();
		return super.createStoredProcedureCall( procedureName, resultClasses );
	}
 
Example #20
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
	public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) {
		checkOpen();
//		checkTransactionSynchStatus();
		return super.createStoredProcedureCall( procedureName, resultSetMappings );
	}
 
Example #21
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
	public ProcedureCall createStoredProcedureCall(String procedureName) {
		checkOpen();
//		checkTransactionSynchStatus();
		return super.createStoredProcedureCall( procedureName );
	}
 
Example #22
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) {
	return delegate.createStoredProcedureCall( procedureName, resultSetMappings );
}
 
Example #23
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) {
	return delegate.createStoredProcedureCall( procedureName, resultClasses );
}
 
Example #24
Source File: SessionDelegatorBaseImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ProcedureCall createStoredProcedureCall(String procedureName) {
	return delegate.createStoredProcedureCall( procedureName );
}
 
Example #25
Source File: SharedSessionContract.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets a ProcedureCall based on a named template
 *
 * @param name The name given to the template
 *
 * @return The ProcedureCall
 *
 * @see javax.persistence.NamedStoredProcedureQuery
 */
ProcedureCall getNamedProcedureCall(String name);
 
Example #26
Source File: SharedSessionContract.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a call to a stored procedure.
 *
 * @param procedureName The name of the procedure.
 *
 * @return The representation of the procedure call.
 */
ProcedureCall createStoredProcedureCall(String procedureName);
 
Example #27
Source File: SharedSessionContract.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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.
 */
ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses);
 
Example #28
Source File: SharedSessionContract.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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.
 */
ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings);