Package org.hibernate

Examples of org.hibernate.Session$LockRequest


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


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

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

   * @param hql
   * @param args
   * @return
   */
  protected static List executeNamedQuery(String hql, int fromIdx, int fetchCount, 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]);
    }
    if(fromIdx > 0)
      q.setFirstResult(fromIdx);
View Full Code Here

   * @param hql
   * @param args
   * @return
   */
  protected static Object namedUniqueResult(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]);
    }
    q.setMaxResults(1);
    return q.uniqueResult();
View Full Code Here

   * @param hql
   * @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

   * @param args
   * @return
   */
  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();
View Full Code Here

  /**
   * ��Ӹ���
   * @param mbean
   */
  public static void addMusic(MusicBean mbean){
    Session ssn = getSession();
    try{
      beginTransaction();
      if(mbean.getStatus()==MusicBean.STATUS_NORMAL){
        if(mbean.getMusicBox()!=null)
          mbean.getMusicBox().incMusicCount(1);
      }
      ssn.save(mbean);
      commit();
    }catch(HibernateException e){
      e.printStackTrace();
      rollback();
      throw e;
View Full Code Here

  /**
   * ɾ������
   * @param mbean
   */
  public static void deleteMusic(MusicBean mbean){
    Session ssn = getSession();
    try{
      beginTransaction();
      if(mbean.getStatus()==MusicBean.STATUS_NORMAL){
        if(mbean.getMusicBox()!=null)
          mbean.getMusicBox().incMusicCount(-1);
      }
      //ɾ�����øø������ռDZ�������
      String hql = "UPDATE DiaryBean d SET d.bgSound = ? WHERE d.bgSound.id=?";
      executeUpdate(hql, new Object[]{null, new Integer(mbean.getId())});
      //ɾ������
      ssn.delete(mbean);
      commit();
    }catch(HibernateException e){
      rollback();
      throw e;
    }
View Full Code Here

  /**
   * ����ɾ������
   * @param mbean
   */
  public static void deleteMusics(int siteid, int[] ids){
    Session ssn = getSession();
    try{
      StringBuffer hql = new StringBuffer("FROM MusicBean m WHERE m.site.id=? AND m.id IN (");
      StringBuffer hql2 = new StringBuffer("UPDATE DiaryBean d SET d.bgSound=? WHERE d.bgSound.id IN (");
      int i=0;
      for(;i<ids.length;i++){
        hql.append("?,");
        hql2.append("?,");
      }
      hql.append("?)")
      hql2.append("?)");     
      Query q = ssn.createQuery(hql.toString());
      q.setInteger(0, siteid);
      i=0;
      for(;i<ids.length;i++){
        q.setInteger(i+1, ids[i]);
      }
      q.setInteger(i+1, ids[0]);
      List musics = q.list();
      if(musics.size()>0){
        beginTransaction();
        //����ռ��жԸ����ֵ�����
        Query q2 = ssn.createQuery(hql2.toString());
        i=0;
        q2.setParameter(0, null);
        for(;i<ids.length;i++){
          q2.setInteger(i+1, ids[i]);
        }
        q2.setInteger(i+1, ids[0]);
        q2.executeUpdate();
        //ɾ������
        for(i=0;i<musics.size();i++){
          MusicBean mbean = (MusicBean)musics.get(i);
          if(mbean.getMusicBox()!=null)
            mbean.getMusicBox().incMusicCount(-1);
          ssn.delete(mbean);
        }
        commit();
      }
    }catch(HibernateException e){
      rollback();
View Full Code Here

TOP

Related Classes of org.hibernate.Session$LockRequest

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.