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