本文整理匯總了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;
}
示例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();
}
示例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);
}
}
}
示例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());
}
示例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);
}
示例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());
}
示例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();
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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);
}
}
}
示例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();
}