org.hibernate.Criteria.setFirstResult()方法的使用及代码示例

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

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

Criteria.setFirstResult介绍

[英]Set the first result to be retrieved.
[中]

代码示例

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

DetachedCriteria idsOnlyCriteria = DetachedCriteria.forClass(MyClass.class);
//add other joins and query params here
idsOnlyCriteria.setProjection(Projections.distinct(Projections.id()));

Criteria criteria = getSession().createCriteria(myClass);
criteria.add(Subqueries.propertyIn("id", idsOnlyCriteria));
criteria.setFirstResult(0).setMaxResults(50);
return criteria.list();

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

@Override
@SuppressWarnings({"unchecked", "deprecation"})
public <T> List<T> findByExample(
    @Nullable final String entityName, final T exampleEntity, final int firstResult, final int maxResults)
    throws DataAccessException {
  Assert.notNull(exampleEntity, "Example entity must not be null");
  return nonNull(executeWithNativeSession((HibernateCallback<List<T>>) session -> {
    Criteria executableCriteria = (entityName != null ?
        session.createCriteria(entityName) : session.createCriteria(exampleEntity.getClass()));
    executableCriteria.add(Example.create(exampleEntity));
    prepareCriteria(executableCriteria);
    if (firstResult >= 0) {
      executableCriteria.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
      executableCriteria.setMaxResults(maxResults);
    }
    return executableCriteria.list();
  }));
}

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

@Override
@SuppressWarnings("unchecked")
public List<?> findByCriteria(final DetachedCriteria criteria, final int firstResult, final int maxResults)
    throws DataAccessException {
  Assert.notNull(criteria, "DetachedCriteria must not be null");
  return nonNull(executeWithNativeSession((HibernateCallback<List<?>>) session -> {
    Criteria executableCriteria = criteria.getExecutableCriteria(session);
    prepareCriteria(executableCriteria);
    if (firstResult >= 0) {
      executableCriteria.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
      executableCriteria.setMaxResults(maxResults);
    }
    return executableCriteria.list();
  }));
}

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

@Override
@SuppressWarnings({"unchecked", "deprecation"})
public <T> List<T> findByExample(
    @Nullable final String entityName, final T exampleEntity, final int firstResult, final int maxResults)
    throws DataAccessException {
  Assert.notNull(exampleEntity, "Example entity must not be null");
  return nonNull(executeWithNativeSession((HibernateCallback<List<T>>) session -> {
    Criteria executableCriteria = (entityName != null ?
        session.createCriteria(entityName) : session.createCriteria(exampleEntity.getClass()));
    executableCriteria.add(Example.create(exampleEntity));
    prepareCriteria(executableCriteria);
    if (firstResult >= 0) {
      executableCriteria.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
      executableCriteria.setMaxResults(maxResults);
    }
    return executableCriteria.list();
  }));
}

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

Criteria criteria=session.createCriteria(Student.class);
  criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
  criteria.add(Restrictions.ne("enquiryStatus", ENQUIRY.JOINED));
  criteria.setMaxResults(10);
  criteria.setFirstResult((paginate.getStartIndex()-1)*10);
  List<Student> students = criteria.list();
 criteria.setProjection(null);
 criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
 Long resultCount = (Long)criteria.uniqueResult();

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

@Override
@SuppressWarnings("unchecked")
public List<?> findByCriteria(final DetachedCriteria criteria, final int firstResult, final int maxResults)
    throws DataAccessException {
  Assert.notNull(criteria, "DetachedCriteria must not be null");
  return nonNull(executeWithNativeSession((HibernateCallback<List<?>>) session -> {
    Criteria executableCriteria = criteria.getExecutableCriteria(session);
    prepareCriteria(executableCriteria);
    if (firstResult >= 0) {
      executableCriteria.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
      executableCriteria.setMaxResults(maxResults);
    }
    return executableCriteria.list();
  }));
}

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

@Test
public void testCriteria() {
  Session session = openSession();
  session.beginTransaction();
  Criteria criteria = session.createCriteria( Door.class );
  criteria.setLockMode( LockMode.PESSIMISTIC_WRITE );
  criteria.setFirstResult( 2 );
  criteria.setMaxResults( 2 );
  @SuppressWarnings("unchecked") List<Door> results = criteria.list();
  assertEquals( 2, results.size() );
  for ( Door door : results ) {
    assertEquals( LockMode.PESSIMISTIC_WRITE, session.getCurrentLockMode( door ) );
  }
  session.getTransaction().commit();
  session.close();
}

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

assertTrue( list.size()==1 && list.get(0)==f );
list = s.createCriteria(Foo.class)
  .setFirstResult(1)
  .addOrder( Order.asc("date") )
  .addOrder( Order.desc("string") )

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.api.db.OpenmrsDataDAO#getAll(boolean, java.lang.Integer, java.lang.Integer)
 */
@Override
public List<T> getAll(boolean includeVoided, Integer firstResult, Integer maxResults) {
  Criteria crit = sessionFactory.getCurrentSession().createCriteria(mappedClass);
  
  if (!includeVoided) {
    crit.add(Restrictions.eq("voided", false));
  }
  crit.setFirstResult(firstResult);
  crit.setMaxResults(maxResults);
  
  return crit.list();
  
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.api.db.OpenmrsMetadataDAO#getAll(boolean, java.lang.Integer, java.lang.Integer)
 */
@Override
public List<T> getAll(boolean includeRetired, Integer firstResult, Integer maxResults) {
  Criteria crit = sessionFactory.getCurrentSession().createCriteria(mappedClass);
  
  if (!includeRetired) {
    crit.add(Restrictions.eq("retired", false));
  }
  crit.setFirstResult(firstResult);
  crit.setMaxResults(maxResults);
  
  return crit.list();
  
}

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

.setFirstResult( 1 ).setMaxResults( 3 ).list();

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

Criteria crit = HibernateUtil.getSession().createCriteria( persistentClass );
crit.setFirstResult(startIndex);
crit.setFetchSize(fetchSize);
crit.setCachable(true); // Enable caching of this query result
return crit.list();

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.api.db.EncounterDAO#getEncounters(String, Integer, Integer, Integer,
 *      boolean)
 */
@Override
@SuppressWarnings("unchecked")
public List<Encounter> getEncounters(String query, Integer patientId, Integer start, Integer length,
    boolean includeVoided) {
  if (StringUtils.isBlank(query) && patientId == null) {
    return Collections.emptyList();
  }
  
  Criteria criteria = createEncounterByQueryCriteria(query, patientId, includeVoided, true);
  
  if (start != null) {
    criteria.setFirstResult(start);
  }
  if (length != null && length > 0) {
    criteria.setMaxResults(length);
  }
  
  return criteria.list();
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.api.db.ConceptDAO#getConceptReferenceTerms(String, ConceptSource, Integer,
 *      Integer, boolean)
 */
@SuppressWarnings("unchecked")
@Override
public List<ConceptReferenceTerm> getConceptReferenceTerms(String query, ConceptSource conceptSource, Integer start,
    Integer length, boolean includeRetired) throws APIException {
  Criteria criteria = createConceptReferenceTermCriteria(query, conceptSource, includeRetired);
  
  if (start != null) {
    criteria.setFirstResult(start);
  }
  if (length != null && length > 0) {
    criteria.setMaxResults(length);
  }
  
  return criteria.list();
}

代码示例来源:origin: openmrs/openmrs-core

private void setFirstAndMaxResult(Criteria criteria, Integer start, Integer length) {
  if (start != null) {
    criteria.setFirstResult(start);
  }
  
  int maximumSearchResults = HibernatePersonDAO.getMaximumSearchResults();
  if (length != null && length < maximumSearchResults) {
    criteria.setMaxResults(length);
  } else {
    if (log.isDebugEnabled()) {
      log.debug("Limiting the size of the number of matching patients to " + maximumSearchResults);
    }
    criteria.setMaxResults(maximumSearchResults);
  }
}

代码示例来源:origin: openmrs/openmrs-core

@Override
public ListPart<T> listPart(Long firstResult, Long maxResults) {
  criteria.setProjection(null);
  criteria.setResultTransformer(Criteria.ROOT_ENTITY);
  
  if (firstResult != null) {
    criteria.setFirstResult(firstResult.intValue());
  }
  
  if (maxResults != null) {
    criteria.setMaxResults(maxResults.intValue());
  }
  
  @SuppressWarnings("unchecked")
  List<T> list = criteria.list();
  
  return ListPart.newListPart(list, firstResult, maxResults, null, null);
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.hl7.db.HL7DAO#getHL7Batch(Class, int, int, Integer, String)
 */
@Override
@SuppressWarnings( { "rawtypes", "unchecked" })
public <T> List<T> getHL7Batch(Class clazz, int start, int length, Integer messageState, String query)
    throws DAOException {
  Criteria crit = getHL7SearchCriteria(clazz, messageState, query);
  crit.setFirstResult(start);
  crit.setMaxResults(length);
  crit.addOrder(Order.asc("dateCreated"));
  return crit.list();
}

代码示例来源:origin: bill1012/AdminEAP

public List<?> getListByCriteria(DetachedCriteria criteria, Integer startPage, Integer pageSize) {
  if (startPage != null && pageSize != null) {
    return criteria.getExecutableCriteria(getCurrentSession()).setProjection(null)
        .setResultTransformer(CriteriaSpecification.ROOT_ENTITY).setFirstResult(startPage).setMaxResults(pageSize).list();
  } else {
    return criteria.getExecutableCriteria(getCurrentSession()).setProjection(null)
        .setResultTransformer(CriteriaSpecification.ROOT_ENTITY).list();
  }
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.api.db.ProviderDAO#getProviders(String, Map, Integer, Integer, boolean)
 */
@Override
public List<Provider> getProviders(String name, Map<ProviderAttributeType, String> serializedAttributeValues,
    Integer start, Integer length, boolean includeRetired) {
  Criteria criteria = prepareProviderCriteria(name, includeRetired);
  if (start != null) {
    criteria.setFirstResult(start);
  }
  if (length != null) {
    criteria.setMaxResults(length);
  }
  
  if (includeRetired) {
    //push retired Provider to the end of the returned list
    criteria.addOrder(Order.asc("retired"));
  }
  
  List<Provider> providers = criteria.list();
  if (serializedAttributeValues != null) {
    CollectionUtils.filter(providers, new AttributeMatcherPredicate<Provider, ProviderAttributeType>(
        serializedAttributeValues));
  }
  return providers;
}

代码示例来源:origin: bill1012/AdminEAP

public <T> List<T> getListByCriteria(DetachedCriteria criteria, PageInfo page) {
  if (page == null) {
    return criteria.getExecutableCriteria(getCurrentSession()).setProjection(null)
        .setResultTransformer(CriteriaSpecification.ROOT_ENTITY).list();
  } else {
    return criteria.getExecutableCriteria(getCurrentSession()).setProjection(null)
        .setResultTransformer(CriteriaSpecification.ROOT_ENTITY).setFirstResult((page.getPageNum() - 1) * page.getPageSize())
        .setMaxResults(page.getPageSize()).list();
  }
}

相关文章