Package org.hibernate

Examples of org.hibernate.Query


   * @param args
   * @return
   */
  protected static int executeNamedUpdate(String hql, Object[] args){
    Session ssn = getSession();
    Query q = ssn.getNamedQuery(hql);
    for(int i=0;args!=null&&i<args.length;i++){
      q.setParameter(i, args[i]);
    }
    return q.executeUpdate();
  }
View Full Code Here


   */
  protected static int commitNamedUpdate(String hql, Object[] args){
    try{
      Session ssn = getSession();
      beginTransaction();
      Query q = ssn.getNamedQuery(hql);
      for(int i=0;args!=null&&i<args.length;i++){
        q.setParameter(i, args[i]);
      }
      int er = q.executeUpdate();
      commit();
      return er;
    }catch(HibernateException e){
      rollback();
      throw e;
View Full Code Here

  public static List listCatalogs(SiteBean site, SessionUserObject user, boolean maintain) {
    List catalogs = new ArrayList();
    catalogs.addAll(site.getCatalogs());
    List perms = null;
    if(user != null){
      Query q = getSession().getNamedQuery("USER_PERMS");
      q.setInteger(0, user.getId());
      perms = q.list();
    }
    Iterator iter = catalogs.iterator();
    while (iter.hasNext()) {
      CatalogBean catalog = (CatalogBean) iter.next();
      // ���ɷ����κ��˶����Է���
View Full Code Here

      hql.append(" AND t.site.id=:site");
    if(fbean!=null)
      hql.append(" AND t.forum.id=:forum");
    hql.append(" AND (t.type=:elite OR t.type=:top_elite)");
    Session ssn = getSession();
    Query q = ssn.createQuery(hql.toString());
    q.setInteger("status", TopicBean.STATUS_NORMAL);
    q.setInteger("elite", TopicBean.INFO_TYPE_ELITE);
    q.setInteger("top_elite", TopicBean.INFO_TYPE_TOP_ELITE);
    if(site!=null)
      q.setInteger("site", site.getId());
    if(fbean!=null)
      q.setInteger("forum", fbean.getId());   
    return ((Number)q.uniqueResult()).intValue();
  }
View Full Code Here

      hql.append(" AND t.site.id=:site");
    if(fbean!=null)
      hql.append(" AND t.forum.id=:forum");
    hql.append(" AND (t.type=:elite OR t.type=:top_elite) ORDER BY ROUND(t.type / 16, 0) DESC, t.id DESC");
    Session ssn = getSession();
    Query q = ssn.createQuery(hql.toString());
    q.setInteger("status", TopicBean.STATUS_NORMAL);
    q.setInteger("elite", TopicBean.INFO_TYPE_ELITE);
    q.setInteger("top_elite", TopicBean.INFO_TYPE_TOP_ELITE);
    if(site!=null)
      q.setInteger("site", site.getId());
    if(fbean!=null)
      q.setInteger("forum", fbean.getId());
    if(fromIdx > 0)
      q.setFirstResult(fromIdx);
    if(count > 0)
      q.setMaxResults(count);
    return q.list();
  }
View Full Code Here

    if(forum != null)
      hql.append(" AND t.forum.id=?");
    hql.append(" ORDER BY ROUND(t.type / 16, 0) DESC, t.replyCount DESC, t.id DESC");
    Session ssn = getSession();
    try{
      Query q = ssn.createQuery(hql.toString());
      q.setInteger(0, site.getId());
      q.setInteger(1, TopicOutlineBean.STATUS_NORMAL);
      Calendar cur_time = Calendar.getInstance();
      cur_time.add(Calendar.DATE, -days);
      q.setTimestamp(2, new Timestamp(cur_time.getTime().getTime()));
      if(forum != null)
        q.setInteger(3, forum.getId());
      if(fromIdx > 0)
        q.setFirstResult(fromIdx);
      q.setMaxResults(count);
      return q.list();
    }finally{
      hql = null;
    }
  }
View Full Code Here

  public static List listTags(SiteBean site, int fromIdx, int count){
    StringBuffer hql = new StringBuffer("SELECT t.name,COUNT(*) FROM TagBean t");
    if(site!=null)
      hql.append(" WHERE t.site.id = ?");
    hql.append(" GROUP BY t.name ORDER BY 2 DESC");
    Query query = getSession().createQuery(hql.toString());
    if(site!=null)
      query.setInteger(0,site.getId());
    if(fromIdx>0)
      query.setFirstResult(fromIdx);
    if(count > 0)
      query.setMaxResults(count);
    List tags = new ArrayList();
    List results = query.list();
    for(int i=0;results!=null && i<results.size();i++){
      tags.add(((Object[])results.get(i))[0]);
    }
    return tags;
  }
View Full Code Here

  public static List listHotTags(SiteBean site, int count){
    StringBuffer hql = new StringBuffer("SELECT t.name,COUNT(*) FROM TagBean t");
    if(site!=null)
      hql.append(" WHERE t.site.id = ?");
    hql.append(" GROUP BY t.name ORDER BY 2 DESC");
    Query query = getSession().createQuery(hql.toString());
    if(site!=null)
      query.setInteger(0,site.getId());
    query.setMaxResults(count);
    List tags = new ArrayList();
    List results = query.list();
    for(int i=0;results!=null && i<results.size();i++){
      tags.add(((Object[])results.get(i))[0]);
    }
    return tags;
  }
View Full Code Here

    Calendar cal = Calendar.getInstance();
    int statDate = cal.get(Calendar.YEAR)*10000 + cal.get(Calendar.MONTH)*100 + cal.get(Calendar.DATE);
    Session ssn = getSession();
    try{
      beginTransaction();
      Query update_q = ssn.getNamedQuery((siteid>0)?"UPDATE_SITE_STAT_1":"UPDATE_SITE_STAT_2");
      update_q.setInteger(0, uvCount);
      update_q.setInteger(1, statDate);
      update_q.setInteger(2, source);
      if(siteid>0)
        update_q.setInteger(3, siteid);
      if(update_q.executeUpdate()<1){
        SiteStatBean ssb = new SiteStatBean();
        ssb.setSiteId(siteid);
        ssb.setUvCount(uvCount);
        ssb.setUpdateTime(new Date());
        ssb.setSource(source);
View Full Code Here

    }
    hql.append(')');
    try{
      Session ssn = getSession();
      beginTransaction();
      Query q = ssn.createQuery(hql.toString());
      q.setInteger(0, incCount);
      for(int i=1;i<=music_ids.length;i++){
        q.setParameter(i, new Integer(music_ids[i-1]));
      }
      int er = q.executeUpdate();
      commit();
      return er;
    }catch(HibernateException e){
      rollback();
      throw e;
View Full Code Here

TOP

Related Classes of org.hibernate.Query

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.