javax.persistence.EntityManager.createNamedStoredProcedureQuery()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中javax.persistence.EntityManager.createNamedStoredProcedureQuery()方法的一些代码示例,展示了EntityManager.createNamedStoredProcedureQuery()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.createNamedStoredProcedureQuery()方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:createNamedStoredProcedureQuery

EntityManager.createNamedStoredProcedureQuery介绍

[英]Create an instance of StoredProcedureQuery for executing a stored procedure in the database.

Parameters must be registered before the stored procedure can be executed.

If the stored procedure returns one or more result sets, any result set will be returned as a list of type Object[].
[中]创建StoredProcedureQuery的实例以在数据库中执行存储过程。
必须先注册参数,然后才能执行存储过程。
如果存储过程返回一个或多个结果集,则任何结果集都将作为Object[]类型的列表返回。

代码示例

代码示例来源:origin: rapidoid/rapidoid

@Override
public StoredProcedureQuery createNamedStoredProcedureQuery(String name) {
  return em.createNamedStoredProcedureQuery(name);
}

代码示例来源:origin: rapidoid/rapidoid

@Override
public StoredProcedureQuery createNamedStoredProcedureQuery(String name) {
  return em().createNamedStoredProcedureQuery(name);
}

代码示例来源:origin: spring-projects/spring-data-jpa

/**
 * Creates a new named {@link StoredProcedureQuery} defined via an {@link NamedStoredProcedureQuery} on an entity.
 */
private StoredProcedureQuery newNamedStoredProcedureQuery() {
  return getEntityManager().createNamedStoredProcedureQuery(procedureAttributes.getProcedureName());
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testStoredProcedureRefCursorUsingNamedQuery() {
  doInJPA( this::entityManagerFactory, entityManager -> {
    //tag::sql-jpa-call-sp-ref-cursor-oracle-named-query-example[]
    List<Object[]> postComments = entityManager
    .createNamedStoredProcedureQuery( "sp_person_phones" )
    .setParameter( "personId", 1L )
    .getResultList();
    //end::sql-jpa-call-sp-ref-cursor-oracle-named-query-example[]
    assertNotNull( postComments );
  });
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue(jiraKey = "HHH-12138")
public void testSysRefCursorAsOutParameter() {
  doInJPA( this::entityManagerFactory, entityManager -> {
    StoredProcedureQuery function = entityManager.createNamedStoredProcedureQuery( "singleRefCursor" );
    function.execute();
    Integer value = (Integer) function.getSingleResult();
    assertFalse( function.hasMoreResults() );
    assertEquals( Integer.valueOf( 1 ), value );
  } );
}

代码示例来源:origin: hibernate/hibernate-orm

@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() );
  } );
}

代码示例来源:origin: kumuluz/kumuluzee

@Override
public StoredProcedureQuery createStoredProcedureQuery(String procedureName) {
  return em.createNamedStoredProcedureQuery(procedureName);
}

代码示例来源:origin: com.agapsys.libs/agreste

@Override
public StoredProcedureQuery createNamedStoredProcedureQuery(String name) {
  return wrappedEntityManager.createNamedStoredProcedureQuery(name);
}

代码示例来源:origin: org.evolvis.bsi/kolab-ws

@Override
public StoredProcedureQuery
createNamedStoredProcedureQuery(String name)
{
  return delegate.createNamedStoredProcedureQuery(name);
}

代码示例来源:origin: org.apache.tomee/openejb-core

@Override
public StoredProcedureQuery createNamedStoredProcedureQuery(final String name) {
  return delegate.createNamedStoredProcedureQuery(name);
}

代码示例来源:origin: stackoverflow.com

@Component
public class FooRepositoryImpl implements FooCustomRepository {

  @PersistenceContext
  EntityManager entityManager;

  @Override
  public List<Foo> foo(String arg) {
    Query query = entityManager.createNamedStoredProcedureQuery("MySP");
    query.setParameter("arg", arg);
    return query.getResultList();
  }
}

代码示例来源:origin: stackoverflow.com

public void callStoredProc(java.math.BigDecimal myNullableInParam) {
  EntityManager entityManager = EMF.createEntityManager();

  StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery("storedProcName");

  query.setParameter("my_nullable_in_param", (myNullableInParam == null ? "" : myNullableInParam.toString()));

  // set more parameters, execute query, commit transaction, etc.
}

代码示例来源:origin: org.springframework.data/spring-data-jpa

/**
 * Creates a new named {@link StoredProcedureQuery} defined via an {@link NamedStoredProcedureQuery} on an entity.
 */
private StoredProcedureQuery newNamedStoredProcedureQuery() {
  return getEntityManager().createNamedStoredProcedureQuery(procedureAttributes.getProcedureName());
}

代码示例来源:origin: kumuluz/kumuluzee

@Override
public StoredProcedureQuery createNamedStoredProcedureQuery(String name) {
  EntityManager em = getEntityManager();
  StoredProcedureQuery storedProcedureQuery = em.createNamedStoredProcedureQuery(name);
  return detachLoadedNonTxStoredProcedureQueryEntities(storedProcedureQuery, em);
}

代码示例来源:origin: com.kumuluz.ee/kumuluzee-jpa-common

@Override
public StoredProcedureQuery createNamedStoredProcedureQuery(String name) {
  EntityManager em = getEntityManager();
  StoredProcedureQuery storedProcedureQuery = em.createNamedStoredProcedureQuery(name);
  return detachLoadedNonTxStoredProcedureQueryEntities(storedProcedureQuery, em);
}

代码示例来源:origin: org.apache.tomee/openejb-core

@Override
public StoredProcedureQuery createNamedStoredProcedureQuery(final String name) {
  final Timer timer = Op.createNamedStoredProcedureQuery.start(this.timer, this);
  try {
    return getEntityManager().createNamedStoredProcedureQuery(name);
  } finally {
    timer.stop();
  }
}

代码示例来源:origin: ueboot/ueboot

/***
 * 执行存储过程
 * @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 ();
}

代码示例来源:origin: hibernate/hibernate-ogm

@Test
public void testResultSetStaticCallWithResultClass() throws Exception {
  inTransaction( entityManager -> {
    StoredProcedureQuery storedProcedureQuery = entityManager.createNamedStoredProcedureQuery(
        "returnPositionalParametersWithEntity" );
    // First parameter is void
    storedProcedureQuery.setParameter( 2, 1 );
    storedProcedureQuery.setParameter( 3, "title" );
    @SuppressWarnings("unchecked")
    List<Car> listResult = storedProcedureQuery.getResultList();
    assertThat( listResult ).containsOnly( new Car( 1, "title" ) );
  } );
}

代码示例来源:origin: hibernate/hibernate-ogm

@Test
public void testResultSetStaticCallWithResultMapping() throws Exception {
  inTransaction( entityManager -> {
    StoredProcedureQuery storedProcedureQuery = entityManager.createNamedStoredProcedureQuery(
        "returnNamedParametersWithMapping" );
    storedProcedureQuery.setParameter( RESULT_SET_PROC_ID_PARAM, 2 );
    storedProcedureQuery.setParameter( RESULT_SET_PROC_TITLE_PARAM, "title'2" );
    @SuppressWarnings("unchecked")
    List<Car> listResult = storedProcedureQuery.getResultList();
    assertThat( listResult ).containsExactly( new Car( 2, "title'2" ) );
  } );
}

代码示例来源:origin: hibernate/hibernate-ogm

@Test
public void testResultSetStaticCallWithResultClass() throws Exception {
  inTransaction( entityManager -> {
    StoredProcedureQuery storedProcedureQuery = entityManager.createNamedStoredProcedureQuery(
        "returnNamedParametersWithEntity" );
    storedProcedureQuery.setParameter( RESULT_SET_PROC_ID_PARAM, 1 );
    storedProcedureQuery.setParameter( RESULT_SET_PROC_TITLE_PARAM, "title" );
    @SuppressWarnings("unchecked")
    List<Car> listResult = storedProcedureQuery.getResultList();
    assertThat( listResult ).containsExactly( new Car( 1, "title" ) );
  } );
}

相关文章