Java Code Examples for javax.persistence.StoredProcedureQuery#execute()
The following examples show how to use
javax.persistence.StoredProcedureQuery#execute() .
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: TestNamedStoredProcedureQuery.java From HibernateTips with MIT License | 7 votes |
@Test public void calculate() { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); StoredProcedureQuery query = em.createNamedStoredProcedureQuery("calculate"); query.setParameter("x", 1.23d); query.setParameter("y", 4d); query.execute(); Double sum = (Double) query.getOutputParameterValue("sum"); log.info("Calculation result: 1.23 + 4 = " + sum); em.getTransaction().commit(); em.close(); }
Example 2
Source File: TestStoredProcedureQuery.java From HibernateTips with MIT License | 7 votes |
@Test public void calculate() { log.info("... calculate ..."); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); // define the stored procedure StoredProcedureQuery query = em.createStoredProcedureQuery("calculate"); query.registerStoredProcedureParameter("x", Double.class, ParameterMode.IN); query.registerStoredProcedureParameter("y", Double.class, ParameterMode.IN); query.registerStoredProcedureParameter("sum", Double.class, ParameterMode.OUT); // set input parameter query.setParameter("x", 1.23d); query.setParameter("y", 4d); // call the stored procedure and get the result query.execute(); Double sum = (Double) query.getOutputParameterValue("sum"); log.info("Calculation result: 1.23 + 4 = " + sum); em.getTransaction().commit(); em.close(); }
Example 3
Source File: SharedEntityManagerCreatorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void deferredStoredProcedureQueryWithIndexedParameters() { EntityManagerFactory emf = mock(EntityManagerFactory.class); EntityManager targetEm = mock(EntityManager.class); StoredProcedureQuery query = mock(StoredProcedureQuery.class); given(emf.createEntityManager()).willReturn(targetEm); given(targetEm.createStoredProcedureQuery("x")).willReturn(query); willReturn("y").given(query).getOutputParameterValue(0); willReturn("z").given(query).getOutputParameterValue(2); given(targetEm.isOpen()).willReturn(true); EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf); StoredProcedureQuery spq = em.createStoredProcedureQuery("x"); spq.registerStoredProcedureParameter(0, String.class, ParameterMode.OUT); spq.registerStoredProcedureParameter(1, Number.class, ParameterMode.IN); spq.registerStoredProcedureParameter(2, Object.class, ParameterMode.INOUT); spq.execute(); assertEquals("y", spq.getOutputParameterValue(0)); try { spq.getOutputParameterValue(1); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } assertEquals("z", spq.getOutputParameterValue(2)); verify(query).registerStoredProcedureParameter(0, String.class, ParameterMode.OUT); verify(query).registerStoredProcedureParameter(1, Number.class, ParameterMode.IN); verify(query).registerStoredProcedureParameter(2, Object.class, ParameterMode.INOUT); verify(query).execute(); verify(targetEm).close(); verifyNoMoreInteractions(query); verifyNoMoreInteractions(targetEm); }
Example 4
Source File: SharedEntityManagerCreatorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void deferredStoredProcedureQueryWithNamedParameters() { EntityManagerFactory emf = mock(EntityManagerFactory.class); EntityManager targetEm = mock(EntityManager.class); StoredProcedureQuery query = mock(StoredProcedureQuery.class); given(emf.createEntityManager()).willReturn(targetEm); given(targetEm.createStoredProcedureQuery("x")).willReturn(query); willReturn("y").given(query).getOutputParameterValue("a"); willReturn("z").given(query).getOutputParameterValue("c"); given(targetEm.isOpen()).willReturn(true); EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf); StoredProcedureQuery spq = em.createStoredProcedureQuery("x"); spq.registerStoredProcedureParameter("a", String.class, ParameterMode.OUT); spq.registerStoredProcedureParameter("b", Number.class, ParameterMode.IN); spq.registerStoredProcedureParameter("c", Object.class, ParameterMode.INOUT); spq.execute(); assertEquals("y", spq.getOutputParameterValue("a")); try { spq.getOutputParameterValue("b"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } assertEquals("z", spq.getOutputParameterValue("c")); verify(query).registerStoredProcedureParameter("a", String.class, ParameterMode.OUT); verify(query).registerStoredProcedureParameter("b", Number.class, ParameterMode.IN); verify(query).registerStoredProcedureParameter("c", Object.class, ParameterMode.INOUT); verify(query).execute(); verify(targetEm).close(); verifyNoMoreInteractions(query); verifyNoMoreInteractions(targetEm); }
Example 5
Source File: RemoteProcedureRegister.java From hibernate-demos with Apache License 2.0 | 6 votes |
public void registerMarshaller() { if ( registered ) { return; } StoredProcedureQuery storedProcedureQuery = em.createStoredProcedureQuery( "RegisterMarshallersTask" ); storedProcedureQuery.execute(); registered = true; }
Example 6
Source File: SharedEntityManagerCreatorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void deferredStoredProcedureQueryWithNamedParameters() { EntityManagerFactory emf = mock(EntityManagerFactory.class); EntityManager targetEm = mock(EntityManager.class); StoredProcedureQuery query = mock(StoredProcedureQuery.class); given(emf.createEntityManager()).willReturn(targetEm); given(targetEm.createStoredProcedureQuery("x")).willReturn(query); willReturn("y").given(query).getOutputParameterValue("a"); willReturn("z").given(query).getOutputParameterValue("c"); given(targetEm.isOpen()).willReturn(true); EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf); StoredProcedureQuery spq = em.createStoredProcedureQuery("x"); spq.registerStoredProcedureParameter("a", String.class, ParameterMode.OUT); spq.registerStoredProcedureParameter("b", Number.class, ParameterMode.IN); spq.registerStoredProcedureParameter("c", Object.class, ParameterMode.INOUT); spq.execute(); assertEquals("y", spq.getOutputParameterValue("a")); try { spq.getOutputParameterValue("b"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } assertEquals("z", spq.getOutputParameterValue("c")); verify(query).registerStoredProcedureParameter("a", String.class, ParameterMode.OUT); verify(query).registerStoredProcedureParameter("b", Number.class, ParameterMode.IN); verify(query).registerStoredProcedureParameter("c", Object.class, ParameterMode.INOUT); verify(query).execute(); verify(targetEm).close(); verifyNoMoreInteractions(query); verifyNoMoreInteractions(targetEm); }
Example 7
Source File: SharedEntityManagerCreatorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void deferredStoredProcedureQueryWithIndexedParameters() { EntityManagerFactory emf = mock(EntityManagerFactory.class); EntityManager targetEm = mock(EntityManager.class); StoredProcedureQuery query = mock(StoredProcedureQuery.class); given(emf.createEntityManager()).willReturn(targetEm); given(targetEm.createStoredProcedureQuery("x")).willReturn(query); willReturn("y").given(query).getOutputParameterValue(0); willReturn("z").given(query).getOutputParameterValue(2); given(targetEm.isOpen()).willReturn(true); EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf); StoredProcedureQuery spq = em.createStoredProcedureQuery("x"); spq.registerStoredProcedureParameter(0, String.class, ParameterMode.OUT); spq.registerStoredProcedureParameter(1, Number.class, ParameterMode.IN); spq.registerStoredProcedureParameter(2, Object.class, ParameterMode.INOUT); spq.execute(); assertEquals("y", spq.getOutputParameterValue(0)); try { spq.getOutputParameterValue(1); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected } assertEquals("z", spq.getOutputParameterValue(2)); verify(query).registerStoredProcedureParameter(0, String.class, ParameterMode.OUT); verify(query).registerStoredProcedureParameter(1, Number.class, ParameterMode.IN); verify(query).registerStoredProcedureParameter(2, Object.class, ParameterMode.INOUT); verify(query).execute(); verify(targetEm).close(); verifyNoMoreInteractions(query); verifyNoMoreInteractions(targetEm); }
Example 8
Source File: StoredProcedureJpaRepositoryImpl.java From ueboot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/*** * 执行存储过程 * @param stringQuery 查询对象 * @return Boolean 执行是否成功 */ @Override public Boolean executeStoredProcedure(StringQuery stringQuery){ StoredProcedureQuery query=this.em.createNamedStoredProcedureQuery (stringQuery.getQuery ()); this.setParameter (query,stringQuery.getParams ()); return query.execute (); }
Example 9
Source File: StoredProcedureJpaRepositoryImpl.java From ueboot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/*** * * @param stringQuery stringQuery * @return List<T> 结果集 */ @Override public List<T> executeResultList(StringQuery stringQuery) { StoredProcedureQuery query=this.em.createNamedStoredProcedureQuery (stringQuery.getQuery ()); this.setParameter (query,stringQuery.getParams ()); query.execute (); List list=query.getResultList (); return list; }
Example 10
Source File: UserRepositoryIntegrationTests.java From spring-data-examples with Apache License 2.0 | 5 votes |
@Test public void plainJpa21() { StoredProcedureQuery proc = em.createStoredProcedureQuery("plus1inout"); proc.registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN); proc.registerStoredProcedureParameter(2, Integer.class, ParameterMode.OUT); proc.setParameter(1, 1); proc.execute(); assertThat(proc.getOutputParameterValue(2), is((Object) 2)); }
Example 11
Source File: UserRepositoryIntegrationTests.java From spring-data-examples with Apache License 2.0 | 3 votes |
@Test public void plainJpa21_entityAnnotatedCustomNamedProcedurePlus1IO() { StoredProcedureQuery proc = em.createNamedStoredProcedureQuery("User.plus1"); proc.setParameter("arg", 1); proc.execute(); assertThat(proc.getOutputParameterValue("res"), is((Object) 2)); }