本文整理匯總了Java中javax.persistence.Query.setMaxResults方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.setMaxResults方法的具體用法?Java Query.setMaxResults怎麽用?Java Query.setMaxResults使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.Query
的用法示例。
在下文中一共展示了Query.setMaxResults方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNotifications
import javax.persistence.Query; //導入方法依賴的package包/類
public List<Notificaciones> getNotifications(boolean all, int maxResults, int firstResult, String _id) {
EntityManager em = getEntityManager();
List<Notificaciones> result = new ArrayList<>();
try {
Query q = em.createNativeQuery(String.format(SQL_NOTIFICATION, _id), Notificaciones.class);
if (!all) {
q.setMaxResults(maxResults);
q.setFirstResult(firstResult);
}
result = q.getResultList();
return result;
} finally {
em.close();
}
}
示例2: findRecent
import javax.persistence.Query; //導入方法依賴的package包/類
@GET
@Path("/recent/")
@Produces({"application/xml", "application/json"})
public List<TransitCumulativeSales> findRecent() {
Query baseRangeQuery = em.createQuery(BASE_RANGE_QUERY);
//Query baseRangeQuery = getEntityManager().createQuery(BASE_RANGE_QUERY);
baseRangeQuery.setMaxResults(200);
List<TransitCumulativeSales> result = new ArrayList<TransitCumulativeSales>();
List<Object[]> resultList = baseRangeQuery.getResultList();
System.out.print("hello world");
for (int i=0; i < resultList.size(); i++){
Object o[] = resultList.get(i);
TransitCumulativeSales t = new TransitCumulativeSales();
t.setStartDailySalesId((Integer)o[0]);
t.setEndDailySalesId((Integer)o[1]);
t.setCost((Double)o[2]);
t.setSales((Double) o[3]);
t.setDate((Date)o[4]);
result.add(t);
}
return result;
}
示例3: findPersonaEntities
import javax.persistence.Query; //導入方法依賴的package包/類
private List<Usuario> findPersonaEntities(boolean all, int maxResults, int firstResult) {
EntityManager em = getEntityManager();
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(Usuario.class));
Query q = em.createQuery(cq);
if (!all) {
q.setMaxResults(maxResults);
q.setFirstResult(firstResult);
}
return q.getResultList();
} finally {
em.close();
}
}
示例4: findRecentProductTypeFrom
import javax.persistence.Query; //導入方法依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/producttype/{id}/{orderLineId}")
public List<LiveSalesList> findRecentProductTypeFrom(@PathParam("id") Integer productTypeId, @PathParam("orderLineId") Integer orderLineId) {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
cq.select(liveSalesList);
cq.where(cb.and(
cb.equal(liveSalesList.get(LiveSalesList_.productTypeId), productTypeId),
cb.gt(liveSalesList.get(LiveSalesList_.orderLineId), orderLineId)
));
Query q = getEntityManager().createQuery(cq);
q.setMaxResults(500);
return q.getResultList();
}
示例5: loadOperatorRevenueSharePercentage
import javax.persistence.Query; //導入方法依賴的package包/類
@Override
public BigDecimal loadOperatorRevenueSharePercentage(long serviceKey,
long endPeriod) {
Query query = dm
.createNamedQuery("RevenueShareModelHistory.findOperatorRevenueSharePercentage");
query.setParameter("productObjKey", Long.valueOf(serviceKey));
query.setParameter("modDate", new Date(endPeriod));
query.setMaxResults(1);
BigDecimal percentage;
try {
RevenueShareModelHistory revenueShareModelHistory = (RevenueShareModelHistory) query
.getSingleResult();
percentage = revenueShareModelHistory.getDataContainer()
.getRevenueShare();
} catch (NoResultException e) {
logger.logError(
Log4jLogger.SYSTEM_LOG,
e,
LogMessageIdentifier.ERROR_OPERATOR_REVENUE_SHARE_OF_SERVICE_NOT_FOUND,
Long.toString(serviceKey));
throw e;
}
return percentage;
}
示例6: findLastRelevantJobHistory
import javax.persistence.Query; //導入方法依賴的package包/類
/**
* Finds the most recently started job history record matching the given jobName/env1/env2 which is no older
* than maxAge. Null if none found.
*/
public JobHistory findLastRelevantJobHistory(String jobName, String env1, String env2, long maxAge)
{
String queryString = "SELECT jh FROM " + JobHistory.class.getSimpleName() + " jh WHERE "
+ "jh.jobName = '" + jobName + "' "
+ "AND jh.env1 = '" + env1 + "' "
+ "AND " + makeNullableCondition("jh.env2", env2) + " "
+ "AND jh.startTime > :oldestAllowedStartTime "
+ "ORDER BY jh.startTime DESC ";
Query query = entityManager.createQuery(queryString);
query.setParameter("oldestAllowedStartTime", makeTimestampBeforeNow(maxAge));
query.setMaxResults(1);
List<JobHistory> results = query.getResultList();
if (results != null && results.size() > 0)
{
return results.get(0);
}
else
{
return null;
}
}
示例7: pagingQuery
import javax.persistence.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void pagingQuery(String jpql,String countJpql,Page<?> page,Map<String,Object> parameter,String dataSourceName){
EntityManager em=this.getEntityManager(dataSourceName);
Query query=em.createQuery(jpql);
if(parameter!=null){
this.setParameter(query, parameter);
}
query.setFirstResult((page.getPageNo()-1)*page.getPageSize());
query.setMaxResults(page.getPageSize());
page.setEntities(query.getResultList());
Query countQuery=em.createQuery(countJpql);
if(parameter!=null){
this.setParameter(countQuery, parameter);
}
int count=0;
Object obj=countQuery.getSingleResult();
if(obj instanceof Integer){
count=(Integer)obj;
}else if(obj instanceof Long){
count=((Long)obj).intValue();
}else{
throw new IllegalArgumentException("The ql["+countJpql+"] fetch result is "+obj+",can not convert to int value");
}
page.setEntityCount(count);
}
示例8: queryByMapParams
import javax.persistence.Query; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
public List queryByMapParams(String hql, Map<String, Object> params, Integer currentPage,Integer pageSize){
//EntityManager em = this.emf.createEntityManager();
Query query = em.createQuery(hql);
List list = null;
try {
if(params != null && !params.isEmpty()){
for(Map.Entry<String,Object> entry: params.entrySet()){
query.setParameter(entry.getKey(), entry.getValue());
}
}
if(currentPage != null && pageSize != null){
query.setFirstResult((currentPage-1)*pageSize);
query.setMaxResults(pageSize);
}
list = query.getResultList();
} catch (Exception e) {
e.printStackTrace();
}finally{
em.close();
}
return list;
}
示例9: getPrevious
import javax.persistence.Query; //導入方法依賴的package包/類
public Menu getPrevious(@NotNull LocalDate current) {
Query query = em.createQuery("select m from Menu m where (m.date < :current) order by m.date DESC ");
query.setParameter("current", current);
query.setMaxResults(1);
List list = query.getResultList();
if (list.isEmpty()) {
return null;
} else {
return (Menu) list.get(0);
}
}
示例10: canBeDeleted
import javax.persistence.Query; //導入方法依賴的package包/類
public boolean canBeDeleted(long id){
Dish dish = getDish(id);
if(dish == null){
return false;
}
Query query = em.createQuery("select m from Menu m where :dish member of m.dishes");
query.setParameter("dish", dish);
query.setMaxResults(1);
List results = query.getResultList();
return results==null || results.isEmpty();
}
示例11: findRecent
import javax.persistence.Query; //導入方法依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/")
public List<LiveSalesList> findRecent() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(LiveSalesList.class));
Query q = getEntityManager().createQuery(cq);
q.setMaxResults(500);
return q.getResultList();
}
示例12: getNext
import javax.persistence.Query; //導入方法依賴的package包/類
public Menu getNext(@NotNull LocalDate current) {
Query query = em.createQuery("select m from Menu m where (m.date > :current) order by m.date ASC ");
query.setParameter("current", current);
query.setMaxResults(1);
List list = query.getResultList();
if (list.isEmpty()) {
return null;
} else {
return (Menu) list.get(0);
}
}
示例13: setPaginationParameters
import javax.persistence.Query; //導入方法依賴的package包/類
private void setPaginationParameters(PaginationInt pagination,
Query query) {
setSortingParameter(query, pagination);
setFilterParameters(query, pagination);
query.setFirstResult(pagination.getOffset());
query.setMaxResults(pagination.getLimit());
}
示例14: loadVendorHistoryOfProduct
import javax.persistence.Query; //導入方法依賴的package包/類
private OrganizationHistory loadVendorHistoryOfProduct(long serviceKey) {
Query query = dm
.createNamedQuery("OrganizationHistory.findVendorOfProduct");
query.setParameter("productKey", Long.valueOf(serviceKey));
query.setMaxResults(1);
try {
return (OrganizationHistory) query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
示例15: queryForPageBySql
import javax.persistence.Query; //導入方法依賴的package包/類
/**
* 根據SQL語句查詢分頁
* @param sql
* @param currentPage
* @param pageSize
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public PageModel queryForPageBySql(String sql,Integer currentPage,Integer pageSize){
PageModel page = new PageModel();
Integer totalCount = 0;
Integer totalPage = 0;
//EntityManager em = this.emf.createEntityManager();
Query qry = em.createNativeQuery(sql);
Query qry2 = em.createNativeQuery(sql);
SQLQuery s = qry.unwrap(SQLQuery.class);
if (currentPage != null && pageSize != null) {//判斷是否有分頁
// 起始對象位置
qry.setFirstResult(pageSize * (currentPage - 1));
// 查詢對象個數
qry.setMaxResults(pageSize);
}
s.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
List<Map> resultList=new ArrayList<Map>();
List list = qry2.getResultList();
totalCount = (list == null ? 0 : list.size());
if(totalCount % pageSize == 0){
totalPage = totalCount/pageSize;
}else{
totalPage = totalCount/pageSize + 1;
}
try {
resultList=s.list();
page.setCurrentPage(currentPage);
page.setPageSize(pageSize);
page.setList(resultList);
page.setTotalCount(totalCount);
page.setTotalPage(totalPage);
} catch (Exception e) {
e.printStackTrace();
}finally{
em.close();
}
return page;
}