当前位置: 首页>>代码示例>>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;未经允许,请勿转载。