當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.setMaxResults方法代碼示例

本文整理匯總了Java中org.hibernate.Query.setMaxResults方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.setMaxResults方法的具體用法?Java Query.setMaxResults怎麽用?Java Query.setMaxResults使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.Query的用法示例。


在下文中一共展示了Query.setMaxResults方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findLastNChanges

import org.hibernate.Query; //導入方法依賴的package包/類
public static List findLastNChanges(Long sessionId, Long managerId, Long subjAreaId, Long departmentId, int n) {
    try {
        org.hibernate.Session hibSession = new ChangeLogDAO().getSession(); 
        Query q = hibSession.createQuery(
                    "select ch from ChangeLog ch where " +
                    "ch.session.uniqueId=:sessionId " +
                    (managerId==null?"":"and ch.manager.uniqueId=:managerId ") +
                    (subjAreaId==null?"":"and ch.subjectArea.uniqueId=:subjAreaId ") +
                    (departmentId==null?"":"and ch.department.uniqueId=:departmentId ") + 
                    "order by ch.timeStamp desc");
        q.setLong("sessionId", sessionId.longValue());
        if (managerId!=null) q.setLong("managerId",managerId.longValue());
        if (subjAreaId!=null) q.setLong("subjAreaId",subjAreaId.longValue());
        if (departmentId!=null) q.setLong("departmentId",departmentId.longValue());
        q.setMaxResults(n);
        q.setCacheable(true);
        return q.list();
    } catch (Exception e) {
        Debug.error(e);
    }
    return null;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:23,代碼來源:ChangeLog.java

示例2: getUsersFromOrganisation

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   /**
    * @see org.lamsfoundation.lams.usermanagement.service.IUserManagementService#getUsersFromOrganisation(int)
    */
   public List<User> getUsersFromOrganisation(Integer orgId, int page, int size, String sortOrder,
    String searchString) {
final String LOAD_LEARNERS_BY_ORG = "SELECT uo.user FROM UserOrganisation uo"
	+ " WHERE uo.organisation.organisationId=:orgId"
	+ " AND CONCAT(uo.user.lastName, ' ', uo.user.firstName) LIKE CONCAT('%', :searchString, '%') "
	+ " ORDER BY uo.user.lastName " + sortOrder + " , uo.user.firstName " + sortOrder;

Query query = getSession().createQuery(LOAD_LEARNERS_BY_ORG);
query.setLong("orgId", orgId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
return query.list();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:GradebookDAO.java

示例3: getApps

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public List<AppHistory4Index> getApps(int currentPage, int pageSize) {
    String hql = "from AppHistory4Index appIdx where appIdx.indexStatus<>1";

    Session session = null;
    try {
        session = this.sessions.openSession();

        Query q = session.createQuery(hql);
        q.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
        q.setMaxResults(pageSize);
        return HibernateHelper.list(q);
    } catch (Exception e) {
        logger.error("error:", e);
        return null;
    } finally {
        if (session != null && session.isOpen()) {
            session.clear();
            session.close();
        }
    }
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:23,代碼來源:AppHistory4IndexDaoImpl.java

示例4: getLessonEventSubscriptions

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   @SuppressWarnings("unchecked")
   public List<Subscription> getLessonEventSubscriptions(Long lessonId, Integer userId, boolean pendingOnly,
    Integer limit, Integer offset) {
String query = EventDAOHibernate.GET_LESSON_EVENT_SUBSCRIPTIONS;
if (lessonId != null) {
    query += " AND s.event.eventSessionId = ?";
}
if (pendingOnly) {
    query += " AND (s.lastOperationMessage IS NULL OR s.lastOperationMessage != '"
	    + DeliveryMethodNotification.LAST_OPERATION_SEEN + "')";
}
query += " ORDER BY ISNULL(s.lastOperationMessage) DESC, uid DESC";
Query queryObject = getSession().createQuery(query);
queryObject.setInteger(0, userId);
if (lessonId != null) {
    queryObject.setLong(1, lessonId);
}
if (limit != null) {
    queryObject.setMaxResults(limit);
}
if (offset != null) {
    queryObject.setFirstResult(offset);
}
return queryObject.list();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:EventDAOHibernate.java

示例5: processQuery

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public void processQuery(Query query)
{
	if( freetext != null )
	{
		query.setParameter("freetext", freetext); //$NON-NLS-1$
	}
	if( dates != null )
	{
		if( dates[0] != null )
		{
			query.setParameter("start", dates[0]); //$NON-NLS-1$
		}
		if( dates[1] != null )
		{
			query.setParameter("end", dates[1]); //$NON-NLS-1$
		}
	}
	query.setParameter("owner", userId);
	query.setParameter("institution", institution);

	query.setFirstResult(offset);
	query.setFetchSize(max);
	query.setMaxResults(max);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:26,代碼來源:FavouriteSearchDaoImpl.java

示例6: geTasksOfUnfinished

import org.hibernate.Query; //導入方法依賴的package包/類
/**
 * 獲取該用戶未提交或者未完成的任務
 */
@Override
public List<Task> geTasksOfUnfinished(int user_id,int start,int num) { 
	List<Task> tasks = new ArrayList<Task>();  
	Session session = HibernateUtils.getSession();//生成Session實例
	 Transaction tx = session.beginTransaction();//生成事務實例
	 try {
		 Query query =  session.createQuery("SELECT  new Task( task_id,task_img_amount,task_start_time,user_id) FROM Task WHERE task_iscommit = 0 AND user_id = "+user_id);
		 query.setFirstResult(start-1);
		 query.setMaxResults(num);
		 tasks = query.list();
	     tx.commit();//提交事務
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();//事務回滾
	}finally{
		HibernateUtils.closeSession();//關閉session實例
	}
	 return tasks;  
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:23,代碼來源:TaskService.java

示例7: getSingleByHql

import org.hibernate.Query; //導入方法依賴的package包/類
/**
 * 獲取單個實體,根據查詢語句及參數獲取。
 * 查詢列名的別名跟實體必須完全一致(如 select a.uid as uid ao Admin as a , AdminRole as ar where a.uid=ar.adminId and a.uid=?
 */
public <T> T getSingleByHql(Class<T> clazz, CharSequence queryString, Object... params) {
    Query query = getSession().createQuery(queryString.toString());
    setParameter(query, params);
    query.setMaxResults(1);
    query.setResultTransformer(Transformers.aliasToBean(clazz));
    List<T> list = query.list();
    if (list.isEmpty()) {
        return null;
    }
    return list.get(0);
}
 
開發者ID:wu05281,項目名稱:admin-shiro,代碼行數:16,代碼來源:DaoSupport.java

示例8: getPagedCourses

import org.hibernate.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
   @Override
   public List<Organisation> getPagedCourses(Integer parentOrgId, Integer typeId, Integer stateId, int page, int size,
    String sortBy, String sortOrder, String searchString) {
String sortByParam = "o.name";
switch (sortBy) {
    case "id":
	sortByParam = "o.organisationId";
	break;
    case "name":
	sortByParam = "o.name";
	break;
    case "code":
	sortByParam = "o.code";
	break;
    case "description":
	sortByParam = "o.createDate";
	break;
}

Query query = getSession().createQuery(OrganisationDAO.GET_PAGED_COURSES + sortByParam + " " + sortOrder);
query.setInteger("typeId", typeId);
query.setInteger("stateId", stateId);
query.setInteger("parentOrgId", parentOrgId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
return query.list();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:OrganisationDAO.java

示例9: getPriorityImages

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public List<Image_Composition> getPriorityImages(List<Integer> imgIds,int task_img_amount,String orderOfTime,String orderOfAmount) {
	 List<Image_Composition> marks = new ArrayList<Image_Composition>();
	 Session session = HibernateUtils.getSession();//生成Session實例
	 Transaction tx = session.beginTransaction();//生成事務實例
	 //此處img_ids不為空
	 String imgIdsString = "(";
	 for (int i = 0; i < imgIds.size()-1; i++) {
		imgIdsString += imgIds.get(i)+","; 
	 }
	 imgIdsString +=imgIds.get(imgIds.size()-1)+")";
	 try { 
	    Query query = session.createSQLQuery("SELECT img_id,img_machine_tag_label,img_path,img_name"
	    		+ " FROM image_composition WHERE img_id IN "+imgIdsString + " ORDER BY image_composition.upload_time "+orderOfTime +",image_composition.amount " +orderOfAmount)
	    		.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
		    query.setFirstResult(0);
		    query.setMaxResults(task_img_amount);
	    marks = query.list();
	     //調用session的get()方法,找到此用戶到內存中
	    tx.commit();//提交事務
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();//事務回滾
	}finally{
		HibernateUtils.closeSession();//關閉session實例
	} 
	 List<Image_Composition> marks2 = new ArrayList<Image_Composition>(); 
	 
	 for (int i = 0; i < marks.size(); i++) { 
		 Image_Composition image_Composition = new Image_Composition();
		  Map map = (Map) marks.get(i);
		  //img_machine_tag_label,img_path,img_name,user_id,img_id
		  image_Composition.setImg_id(Integer.parseInt(map.get("img_id")+""));
		  image_Composition.setImg_machine_tag_label(map.get("img_machine_tag_label")+"");
		  image_Composition.setImg_name(map.get("img_name")+"");
		  image_Composition.setImg_path(map.get("img_path")+"");
		   marks2.add(image_Composition);
	 }  
	 return marks2;  
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:41,代碼來源:ImageService.java

示例10: getLearnersLatestCompletedForLesson

import org.hibernate.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
   @Override
   public List<User> getLearnersLatestCompletedForLesson(Long lessonId, Integer limit, Integer offset) {
Query query = getSession().createQuery(LearnerProgressDAO.LOAD_LEARNERS_LATEST_COMPLETED_BY_LESSON)
	.setLong("lessonId", lessonId);
if (limit != null) {
    query.setMaxResults(limit);
}
if (offset != null) {
    query.setFirstResult(offset);
}
return query.list();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:LearnerProgressDAO.java

示例11: getTaskOfImages

import org.hibernate.Query; //導入方法依賴的package包/類
/**
 * 獲取指定task_id對應的任務所有圖片
 */
@Override
public List<Image> getTaskOfImages(int task_id) {
	
	 List<Image> images = new ArrayList<Image>();
	 Session session = HibernateUtils.getSession();//生成Session實例
	 Transaction tx = session.beginTransaction();//生成事務實例 
	 try { 
	    Query query = session.createSQLQuery("SELECT  image.img_id,img_name,img_path FROM composition,image WHERE composition.img_id = image.img_id AND composition.task_id = "+task_id).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); 
		    query.setFirstResult(0);
		    query.setMaxResults(5);
	    images = query.list();
	     //調用session的get()方法,找到此用戶到內存中
	    tx.commit();//提交事務
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();//事務回滾
	}finally{
		HibernateUtils.closeSession();//關閉session實例
	}    
	 List<Image> images2 = new ArrayList<Image>(); 
	 
	 for (int i = 0; i < images.size(); i++) { 
		  Image image = new Image();
		  Map map = (Map) images.get(i); 
		  image.setImg_id(Integer.parseInt(map.get("img_id")+"")); 
		  image.setImg_name(map.get("img_name")+"");
		  image.setImg_path(map.get("img_path")+"");
		  images2.add(image);
	 }  
	 return images2;
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:35,代碼來源:CompositionService.java

示例12: seleteListOfCategory

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public List<Integer> seleteListOfCategory(int category_id,int user_id,String orderOfTime,String orderOfAmount) {
	Session session = HibernateUtils.getSession(); //生成session實例
    Transaction tx = session.beginTransaction();  //創建transaction實例
    List<Integer> imgIds = new ArrayList<Integer>();
    ListToString listToString = new ListToString();
    try {   
    	String hql = "SELECT image_category.img_id FROM image_category,image,image_composition WHERE image_category.img_id = image.img_id AND image.img_id = image_composition.img_id AND image.img_is_finish <> 1 AND  category_id ="+category_id;
    	String hql2 = " AND image.img_id NOT IN";
    	String hq3 = "SELECT img_id FROM mark WHERE user_id = "+user_id; 
    	String append = " ORDER BY image_composition.upload_time "+ orderOfTime + ",image_composition.amount " + orderOfAmount;
    List<Integer> integers  = session.createSQLQuery(hq3).list(); 
    if (!integers.isEmpty()) {
		hql = hql + hql2 + listToString.getListToString(integers) + append;
	}else {
		hql = hql + append;
	}
    Query query = session.createSQLQuery(hql);
    query.setFirstResult(0);
	query.setMaxResults(30);
    imgIds = query.list();
    tx.commit();            //提交事務  
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();          //回滾事務 
	}finally {
	  HibernateUtils.closeSession();  //關閉Session實例
	} 
    return imgIds;
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:31,代碼來源:ImageService.java

示例13: findInDetail

import org.hibernate.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void findInDetail(PageUtil pageUtil,String beginTime,String endTime,String type,Long pid,String dids) throws JshException {
    StringBuffer queryString = new StringBuffer();
    queryString.append("select dh.Number,m.`name`,m.Model,di.UnitPrice,di.OperNumber,di.AllPrice,s.supplier,d.dName,date_format(dh.OperTime, '%Y-%m-%d') " +
            "from jsh_depothead dh inner join jsh_depotitem di on di.HeaderId=dh.id " +
            "inner join jsh_material m on m.id=di.MaterialId " +
            "inner join jsh_supplier s on s.id=dh.OrganId " +
            "inner join (select id,name as dName from jsh_depot) d on d.id=di.DepotId " +
            "where dh.Type='"+ type +"' and dh.OperTime >='"+ beginTime +"' and dh.OperTime <='"+ endTime +"' ");
    if(pid!=null){
        queryString.append(" and di.DepotId=" + pid );
    }
    else {
        queryString.append(" and di.DepotId in (" + dids + ")" );
    }
    queryString.append(" ORDER BY OperTime DESC,Number desc");
    Query query;
    query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
    pageUtil.setTotalCount(query.list().size());
    // 分頁查詢
    int pageNo = pageUtil.getCurPage();
    int pageSize = pageUtil.getPageSize();
    if (0 != pageNo && 0 != pageSize) {
        query.setFirstResult((pageNo - 1) * pageSize);
        query.setMaxResults(pageSize);
    }
    pageUtil.setPageList(query.list());
}
 
開發者ID:cendi2005,項目名稱:jshERP,代碼行數:29,代碼來源:DepotHeadDAO.java

示例14: getFromDate

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public QuotePE getFromDate(Date dateStartStep, Date dateEndStep){
	Session session = getSession();
	String requete = "FROM QuotePE "
			+ "WHERE creationDateTime <= :dateMin "
			+ "AND creationDateTime > :dateMax "
			+ "ORDER BY creationDateTime ASC ";
	
	Query query = session.createQuery(requete);
	
	query.setTimestamp("dateMin", dateStartStep);
	query.setTimestamp("dateMax", dateEndStep);
	query.setFirstResult(0);
	query.setMaxResults(1);
	query.uniqueResult();
	
	List<QuotePE> lpe = (List<QuotePE>) query.list();
	

	session.close();
	
	if(lpe.isEmpty())
		return null;
	else 
		return lpe.get(0);
	
	
}
 
開發者ID:auTasso,項目名稱:SandBoxNGSB,代碼行數:29,代碼來源:QuoteDAOImpl.java

示例15: getPreviewLessons

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   @SuppressWarnings("unchecked")
   public List<Long> getPreviewLessons(Integer limit) {
Query query = getSession().createQuery(FIND_PREVIEW_LESSON_IDS);
if (limit != null) {
    query.setMaxResults(limit);
}
return query.list();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:LessonDAO.java


注:本文中的org.hibernate.Query.setMaxResults方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。