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


Java Query.uniqueResult方法代碼示例

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


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

示例1: getUsersNumOfFrozenOrUnfrozen

import org.hibernate.Query; //導入方法依賴的package包/類
/**
 * 獲取凍結未凍結用戶的總數
 */
@Override
public long getUsersNumOfFrozenOrUnfrozen(int is_frozen) {
	 long num =0l;
	 Session session = HibernateUtils.getSession();//生成Session實例
	 Transaction tx = session.beginTransaction();//生成事務實例 
	 try { 
	    Query query = session.createQuery("SELECT count(*) from User where is_frozen = ?"); 
		    query.setInteger(0, is_frozen);
	    num = (long) query.uniqueResult();
	     //調用session的get()方法,找到此用戶到內存中
	    tx.commit();//提交事務
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();//事務回滾
	}finally{
		HibernateUtils.closeSession();//關閉session實例
	}   
	 return num;
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:23,代碼來源:UserService.java

示例2: getPendingNotificationCount

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   public long getPendingNotificationCount(Long lessonId, Integer userId) {
String query = EventDAOHibernate.COUNT_PENDING_NOTIFICATIONS;
if (lessonId != null) {
    query += " AND s.event.eventSessionId = ?";
}
Query queryObject = getSession().createQuery(query);
queryObject.setInteger(0, userId);
if (lessonId != null) {
    queryObject.setLong(1, lessonId);
}
return (Long) queryObject.uniqueResult();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:EventDAOHibernate.java

示例3: isExists

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public boolean isExists(String marketName, short catalog, int subCatalog) {
    Query query = getSession()
            .createQuery(
                    "select count(id) from CatalogConvertor where   catalog= :catalog and marketName= :marketName and subCatalog =:subCatalog")
            .setInteger("catalog", catalog)
            .setString("marketName", StringUtils.defaultIfEmpty(marketName, "").trim())
            .setInteger("subCatalog", subCatalog);
    Object o = query.uniqueResult();
    return Integer.valueOf(o.toString()) > 0;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:12,代碼來源:CatalogConvertorDaoImpl.java

示例4: getCountActiveLearnerByLesson

import org.hibernate.Query; //導入方法依賴的package包/類
/**
    * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getActiveLearnerByLesson(long) Note: Hibernate 3.1
    *      query.uniqueResult() returns Integer, Hibernate 3.2 query.uniqueResult() returns Long
    */
   @Override
   public Integer getCountActiveLearnerByLesson(long lessonId) {
Query query = getSession().createQuery(LessonDAO.COUNT_ACTIVE_LEARNERS);
query.setLong("lessonId", lessonId);
Object value = query.uniqueResult();
return new Integer(((Number) value).intValue());
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:LessonDAO.java

示例5: getOrderDetails

import org.hibernate.Query; //導入方法依賴的package包/類
public Order getOrderDetails(int orderId){
	String sql = "from Order where orderId=:orderId";
	Session session = this.sessionFactory.openSession();
	Query query = session.createQuery(sql);
	query.setParameter("orderId", orderId);
	
	Order order = (Order) query.uniqueResult();
	session.close();
	return order;
	
}
 
開發者ID:axd164330,項目名稱:Restaurant,代碼行數:12,代碼來源:OrderDaoImpl.java

示例6: countDownloads

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public long countDownloads(Session session, String marketName) {
    Query query = session.createQuery("select sum(downloads) from MarketApp where marketName =:marketName");
    query.setParameter("marketName", marketName);
    Object o = query.uniqueResult();
    if (o != null) {
        return Long.valueOf(o.toString());
    }
    return 0;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:11,代碼來源:MarketAppDaoImpl.java

示例7: getAppsRollRecommendNum

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public int getAppsRollRecommendNum() {
    Query query = getSession().createQuery("select intValue from SysDictionary where name = 'recommendCount'");
    Object o = query.uniqueResult();
    if (o != null) {
        return ((Integer) o).intValue();
    }
    return 0;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:10,代碼來源:SysDictionaryDaoImpl.java

示例8: getQuestionResultMark

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   public Float getQuestionResultMark(Long assessmentUid, Long userId, int questionSequenceId) {
Query q = getSession().createQuery(GET_ANSWER_MARK);
q.setParameter(0, assessmentUid);
q.setParameter(1, userId);
q.setParameter(2, questionSequenceId);
q.setMaxResults(1);
Object result = q.uniqueResult();
return result != null ? ((Number) result).floatValue() : null;

   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:AssessmentQuestionResultDAOHibernate.java

示例9: getCountUsers

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   public int getCountUsers(String searchPhrase) {
StringBuilder queryBuilder = new StringBuilder("SELECT count(*) FROM User user WHERE user.disabledFlag=0 ");
// support for custom search from a toolbar
UserDAO.addNameSearch(queryBuilder, "user", searchPhrase);

Query query = getSession().createQuery(queryBuilder.toString());

Number count = (Number) query.uniqueResult();
return count == null ? 0 : count.intValue();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:UserDAO.java

示例10: getLastTotalScoreByUser

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   public Float getLastTotalScoreByUser(Long assessmentUid, Long userId) {

Query q = getSession().createQuery(LAST_ASSESSMENT_RESULT_GRADE);
q.setParameter(0, userId);
q.setParameter(1, assessmentUid);
Object lastTotalScore = q.uniqueResult();

return (lastTotalScore == null) ? 0 : (Float)lastTotalScore;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:AssessmentResultDAOHibernate.java

示例11: exists

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public boolean exists(String name) {
    String queryString = "select count(id) from Keyword where name = :name ";
    Query q = getSession().createQuery(queryString);
    q.setParameter("name", name);
    Long count = (Long) q.uniqueResult();
    if (count != null && count.longValue() > 0L) {
        return true;
    }
    return false;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:12,代碼來源:KeywordDaoImpl.java

示例12: count

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public long count(String type) {
    StringBuilder queryString = new StringBuilder("select count(id) from ").append(getType().getName());
    queryString.append(" where type = :type and hidden = 0");
    Query query = getSession().createQuery(queryString.toString());
    query.setParameter("type", type);
    Object o = query.uniqueResult();
    return Long.valueOf(o.toString());
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:10,代碼來源:MoMixFeaturedDaoImpl.java

示例13: count

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public long count() {
    Query query = getSession().createQuery("select count(id) from App");
    Object o = query.uniqueResult();
    return Long.valueOf(o.toString());
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:7,代碼來源:AppDaoImpl.java

示例14: count

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public long count() {
    Query query = getSession().createQuery("select count(id) from App where hidden = 0");
    Object o = query.uniqueResult();
    return Long.valueOf(o.toString());
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:7,代碼來源:AppDaoImpl.java

示例15: findUniObjs

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public Object findUniObjs(String hql,Object... values ) {
	Query q = createQuery(hql, values);
	return q.uniqueResult();
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:6,代碼來源:HibernateDao.java


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