javax.persistence.Query.getFirstResult()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(676)

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

Query.getFirstResult介绍

[英]The position of the first result the query object was set to retrieve. Returns 0 if setFirstResult was not applied to the query object.
[中]查询对象设置为检索的第一个结果的位置。如果setFirstResult未应用于查询对象,则返回0。

代码示例

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

/**
 * Restricts the max results of the given {@link Query} if the current {@code tree} marks this {@code query} as
 * limited.
 */
private Query restrictMaxResultsIfNecessary(Query query) {
  if (tree.isLimiting()) {
    if (query.getMaxResults() != Integer.MAX_VALUE) {
      /*
       * In order to return the correct results, we have to adjust the first result offset to be returned if:
       * - a Pageable parameter is present
       * - AND the requested page number > 0
       * - AND the requested page size was bigger than the derived result limitation via the First/Top keyword.
       */
      if (query.getMaxResults() > tree.getMaxResults() && query.getFirstResult() > 0) {
        query.setFirstResult(query.getFirstResult() - (query.getMaxResults() - tree.getMaxResults()));
      }
    }
    query.setMaxResults(tree.getMaxResults());
  }
  if (tree.isExistsProjection()) {
    query.setMaxResults(1);
  }
  return query;
}

代码示例来源:origin: Impetus/Kundera

@Override
public int getFirstResult()
{
  return query.getFirstResult();
}

代码示例来源:origin: de.mhus.lib/mhu-lib-persistence

/** {@inheritDoc} */
@Override
public int getFirstResult() {
  return query.getFirstResult();
}

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

finally {
  entityTransaction = entityManager.getTransaction();
  entityTransaction.begin();
  Query query = entityManager.createNamedQuery("findEmployeeByName");
  supplierID = query.getFirstResult();
  entityTransaction.commit();
  entityManager.close();
}

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

@Override
public int
getFirstResult()
{
  return delegate.getFirstResult();
}

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

@Override
public int getFirstResult() {
  return query.getFirstResult();
}

代码示例来源:origin: org.apache.geronimo.modules/geronimo-persistence-jpa20

@Override
public int getFirstResult() {
  return query.getFirstResult();
}

代码示例来源:origin: org.wildfly/wildfly-jpa

@Override
public int getFirstResult() {
  return underlyingQuery.getFirstResult();
}

代码示例来源:origin: org.jboss.eap/wildfly-jpa

@Override
public int getFirstResult() {
  return underlyingQuery.getFirstResult();
}

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

@Override
public int getFirstResult() {
  return query.getFirstResult();
}

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

public int getFirstResult() {
  return query.getFirstResult();
}

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

public int getFirstResult() {
  return query.getFirstResult();
}

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

public int getFirstResult() {
  return query.getFirstResult();
}

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

em.getTransaction().begin();
 String get_employee_id = "SELECT emp.id FROM Employee as emp WHERE emp.bsn=:bsn";
 Query employee_query = em.createQuery(get_employee_id);
 employee_query.setParameter("bsn", object.getEmployee().getBsn());
 long id = employee_query.getFirstResult();
 System.out.println("query returns employee id: " + id);
 em.getTransaction().commit();

代码示例来源:origin: org.glassfish.main.common/container-common

public int getFirstResult() {
  try {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerQueryStart(EntityManagerQueryMethod.GET_FIRST_RESULT);
    }
    return queryDelegate.getFirstResult();
  } finally {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerQueryEnd();
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-core

public static QueryKey create(String queryString, boolean softDeletion, boolean singleResult, javax.persistence.Query jpaQuery) {
  return new QueryKey(queryString, jpaQuery.getFirstResult(), jpaQuery.getMaxResults(), softDeletion, singleResult, getNamedParameters(jpaQuery), getPositionalParameters(jpaQuery));
}

代码示例来源:origin: com.haulmont.cuba/cuba-core

public static QueryKey create(String queryString, boolean softDeletion, javax.persistence.Query jpaQuery) {
  return new QueryKey(queryString, jpaQuery.getFirstResult(), jpaQuery.getMaxResults(), softDeletion, false, getNamedParameters(jpaQuery), getPositionalParameters(jpaQuery));
}

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

/**
 * Restricts the max results of the given {@link Query} if the current {@code tree} marks this {@code query} as
 * limited.
 */
private Query restrictMaxResultsIfNecessary(Query query) {
  if (tree.isLimiting()) {
    if (query.getMaxResults() != Integer.MAX_VALUE) {
      /*
       * In order to return the correct results, we have to adjust the first result offset to be returned if:
       * - a Pageable parameter is present
       * - AND the requested page number > 0
       * - AND the requested page size was bigger than the derived result limitation via the First/Top keyword.
       */
      if (query.getMaxResults() > tree.getMaxResults() && query.getFirstResult() > 0) {
        query.setFirstResult(query.getFirstResult() - (query.getMaxResults() - tree.getMaxResults()));
      }
    }
    query.setMaxResults(tree.getMaxResults());
  }
  if (tree.isExistsProjection()) {
    query.setMaxResults(1);
  }
  return query;
}

代码示例来源:origin: org.glassfish.common/container-common

public int getFirstResult() {
  try {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerQueryStart(EntityManagerQueryMethod.GET_FIRST_RESULT);
    }
    Query delegate = getQueryDelegate();
    return delegate.getFirstResult();
  } finally {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerQueryEnd();
    }
  }
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

public void addNamedQuery(String name, Query query) {
  DatabaseQuery unwrapped = (DatabaseQuery) query.unwrap(DatabaseQuery.class).clone();
  if (((QueryImpl)query).lockMode != null){
    ((ObjectLevelReadQuery)unwrapped).setLockModeType(((QueryImpl)query).lockMode.name(), session);
  }
  if (unwrapped.isReadQuery()){
    ((ReadQuery)unwrapped).setInternalMax((((QueryImpl)query).getMaxResultsInternal()));
    if (query.getFirstResult() != QueryImpl.UNDEFINED){
      ((ReadQuery)unwrapped).setFirstResult(query.getFirstResult());
    }
  }
  this.getServerSession().addQuery(name, unwrapped, true);
}

相关文章