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


Java Query.setParameter方法代碼示例

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


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

示例1: getToolSessionByLearner

import org.hibernate.Query; //導入方法依賴的package包/類
/**
    * Get the tool session by learner and activity. Will attempted to get an appropriate grouped tool session (the most
    * common case as this covers a normal group or a whole of class group) and then attempts to get a non-grouped base
    * tool session. The non-grouped tool session is meant to be unique against the user and activity.
    *
    * @see org.lamsfoundation.lams.tool.dao.IToolSessionDAO#getToolSessionByLearner(org.lamsfoundation.lams.usermanagement.User,
    *      org.lamsfoundation.lams.learningdesign.Activity)
    * @returns toolSession may be of subclass NonGroupedToolSession or GroupedToolSession
    */
   @Override
   public ToolSession getToolSessionByLearner(final User learner, final Activity activity) {
Query query = getSessionFactory().getCurrentSession()
	.createQuery(ToolSessionDAO.LOAD_GROUPED_TOOL_SESSION_BY_GROUP2);
query.setParameter("learner", learner);
query.setParameter("activity", activity);
GroupedToolSession groupedToolSession = (GroupedToolSession) query.uniqueResult();
if (groupedToolSession != null) {
    return groupedToolSession;
}

query = getSessionFactory().getCurrentSession()
	.createQuery(ToolSessionDAO.LOAD_NONGROUPED_TOOL_SESSION_BY_LEARNER);
query.setParameter("learner", learner);
query.setParameter("activity", activity);
NonGroupedToolSession nonGroupedSession = (NonGroupedToolSession) query.uniqueResult();
return nonGroupedSession;

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

示例2: executeHQLQuery

import org.hibernate.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public List<T> executeHQLQuery(final String hql,
      final List<SQLVisitor.SQLVisitorParameter> parameters,
      final int skip, final int top)
{
   Session session = getSessionFactory().getCurrentSession();
   Query query = session.createQuery(hql);
   for (int i = 0; i < parameters.size(); i++)
   {
      SQLVisitor.SQLVisitorParameter param = parameters.get(i);
      query.setParameter(i, param.getValue(), param.getType());
   }

   if (skip > -1)
   {
      query.setFirstResult(skip);
   }
   if (top > -1)
   {
      query.setMaxResults(top);
   }
   query.setReadOnly(true);
   return (List<T>) query.list();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:25,代碼來源:HibernateDao.java

示例3: setParams

import org.hibernate.Query; //導入方法依賴的package包/類
private void setParams(Query q, final Map<String, Object> ps)
{
	for( Map.Entry<String, Object> entry : ps.entrySet() )
	{
		String key = entry.getKey();
		Object obj = entry.getValue();
		if( obj instanceof Collection<?> )
		{
			q.setParameterList(key, (Collection<?>) obj);
		}
		else
		{
			q.setParameter(key, obj);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:ItemDaoImpl.java

示例4: countAppsOfDropMarket

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

示例5: findPhoneListByParams

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public List<PhoneBasicInfo> findPhoneListByParams(String brand, String product) {
    Query query = null;
    if (StringUtils.isEmpty(product)) {
        query = getSession().createQuery(" from PhoneBasicInfo where brand = :brand and Product <> 'Android設備'");
        query.setParameter("brand", brand);
    } else {
        query = getSession().createQuery(
                " from PhoneBasicInfo where brand = :brand and product =:product and Product <> 'Android設備'");
        query.setParameter("brand", brand);
        query.setParameter("product", product);
    }
    return HibernateHelper.list(query);
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:15,代碼來源:PhoneBaseInfoDaoImpl.java

示例6: getFirstTotalScoreByUser

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   public Float getFirstTotalScoreByUser(Long sessionId, Long userId) {
Query q = getSession().createQuery(FIRST_SCORE_BY_SESSION_AND_USER);
q.setParameter(0, userId);
q.setParameter(1, sessionId);
q.setMaxResults(1);
return ((Float) q.uniqueResult());
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:AssessmentResultDAOHibernate.java

示例7: selectCount

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public long selectCount( String _db , String _hql , Object[] _param ) {
	Query query = _get_session( _db ).createQuery( _hql );
	int i = 0;
	if ( _param != null ) for ( Object o : _param )
		query.setParameter( i++ , o );

	return ( long ) query.iterate().next();
}
 
開發者ID:aiyoyoyo,項目名稱:jeesupport,代碼行數:10,代碼來源:AbsSupportDao.java

示例8: 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,代碼來源:MoFeaturedDaoImpl.java

示例9: countDownloads

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

示例10: updateSort

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public boolean updateSort(int id, int rank) {
    final String hql = "update MoAppAndTag set rank = :rank   where id = :id ";
    Query query = getSession().createQuery(hql);
    query.setParameter("rank", rank);
    query.setParameter("id", id);
    return query.executeUpdate() > 0;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:9,代碼來源:MoAppAndTagDaoImpl.java

示例11: getApps

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public List<App> getApps(String pkname, String marketname) {
    String queryString = "from App where pkname =:pkname and marketname =:marketname  order by versioncode desc , lastupdatetime desc";
    Query query = sessions.getCurrentSession().createQuery(queryString);
    query.setParameter("pkname", pkname);
    query.setParameter("marketname", marketname);
    List<App> apps = HibernateHelper.list(query);
    return apps;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:10,代碼來源:AppDaoImpl.java

示例12: existRelating

import org.hibernate.Query; //導入方法依賴的package包/類
private boolean existRelating(int catalogId) {
    Query query = getSession().createSQLQuery(
            "select count(id) from CatalogConvertor where TargetCatalog =:id or TargetSubCatalog =:id");
    query.setParameter("id", catalogId);
    Object o = query.uniqueResult();
    int result = Integer.valueOf(o.toString());
    if (result > 0)
        return true;

    Query queryApp = getSession().createSQLQuery("select count(id) from App where Catalog =:id or SubCatalog =:id");
    queryApp.setParameter("id", catalogId);
    o = queryApp.uniqueResult();
    result = Integer.valueOf(o.toString());
    return result > 0;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:16,代碼來源:CatalogDaoImpl.java

示例13: getBestTotalScoreByUser

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
   public Float getBestTotalScoreByUser(Long sessionId, Long userId) {
Query q = getSession().createQuery(BEST_SCORE_BY_SESSION_AND_USER);
q.setParameter(0, userId);
q.setParameter(1, sessionId);
return ((Float) q.uniqueResult());
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:AssessmentResultDAOHibernate.java

示例14: setQueryParameters

import org.hibernate.Query; //導入方法依賴的package包/類
public void setQueryParameters(Query query, Map<String, Object> parameters) {
	if (parameters == null)
		return;
	for (String name : parameters.keySet()) {
		Object obj = parameters.get(name);
		if (obj instanceof Collection) {
			query.setParameterList(name, (Collection<?>) obj);
		} else if (obj instanceof Object[]) {
			query.setParameterList(name, (Object[]) obj);
		} else {
			query.setParameter(name, obj);
		}
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:15,代碼來源:HibernateDao.java

示例15: selectByHQL

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
@SuppressWarnings( "unchecked" )
public < T > List< T > selectByHQL( String _db , String _hql , int _first , int _limit , Object[] _param ,
				Class< T > _cls ) {
	Session sess = _get_session( _db );
	Query query = sess.createQuery( _hql );
	query.setFirstResult( _first );
	query.setMaxResults( _limit );
	int i = 0;
	if ( _param != null ) for ( Object o : _param )
		query.setParameter( i++ , o );
	return query.list();
}
 
開發者ID:aiyoyoyo,項目名稱:jeesupport,代碼行數:14,代碼來源:AbsSupportDao.java


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