Package org.hibernate

Examples of org.hibernate.Session


   */
  public void closeSession(){
    if(sessions == null)
      return;
    // Would be written as a no-op in an EJB container with CMT
    Session ssn = (Session)sessions.get();
    if(ssn == null)
      return;
    else if(ssn.isOpen())
      ssn.close();   
   
    sessions.set(null);
  }
View Full Code Here


    if(transactions == null)
      return;
    // Would be written as a no-op in an EJB container with CMT
    Transaction tx = (Transaction)transactions.get();
    if (tx == null || tx.wasCommitted() || tx.wasRolledBack()) {
      Session ssn = (Session)sessions.get();
      if(ssn == null){
        ssn = getSession();
        tx = ssn.beginTransaction();
        transactions.set(tx);
      }
      else if(ssn != null){
        tx = ssn.beginTransaction();
        transactions.set(tx);       
      }
    }
    else{
      if(tx!=null && log.isWarnEnabled())
View Full Code Here

      msg.setContent(content);
      msg.setSendTime(new Date());
      msg.setFromUser(sender);
      msg.setStatus(MessageBean.STATUS_NEW);
      //����д�����ݿ�
      Session ssn = getSession();
      beginTransaction();
      for(int i=0;i<users.size();i++){
        UserBean user = (UserBean)users.get(i);
        msg.setToUser(user);
        ssn.save(msg);
        if(i % 20 == 0){
          ssn.flush();
          ssn.clear();
        }
      }
      commit();
    }catch(HibernateException e){
      rollback();
View Full Code Here

   * @param old_msg_id
   * @param msg
   */
  public static void replyAndDeleteMessage(int old_msg_id, MessageBean msg){
    try{
      Session ssn = getSession();
      beginTransaction();
      //�ظ�����Ϣ
      ssn.save(msg);
      //ɾ�����ظ��Ķ���Ϣ
      if(old_msg_id > 0)
        executeNamedUpdate("DELETE_MESSAGE", old_msg_id, msg.getFromUser().getId());
      commit();
    }catch(HibernateException e){
View Full Code Here

    StringBuffer hql = new StringBuffer("DELETE FROM MessageBean AS f WHERE f.toUser.id=? AND f.id IN (");
    for(int i=0;i<max_msg_count;i++){
      hql.append("?,");
    }
    hql.append("?)");
    Session ssn = getSession();
    try{
      beginTransaction();
      Query q = ssn.createQuery(hql.toString());
      q.setInteger(0, ownerId);
      int i=0;
      for(;i<max_msg_count;i++){
        String s_id = (String)msgIds[i];
        int id = -1;
View Full Code Here

    StringBuffer hql = new StringBuffer("DELETE FROM FriendBean f WHERE f.owner=? AND f.friend.id IN (");
    for(int i=0;i<friendIds.length;i++){
      hql.append("?,");
    }
    hql.append("?)");
    Session ssn = getSession();
    try{
      beginTransaction();
      Query q = ssn.createQuery(hql.toString());
      q.setInteger(0, ownerId);
      int i=0;
      for(;i<friendIds.length;i++){
        String s_id = (String)friendIds[i];
        int id = -1;
View Full Code Here

    StringBuffer hql = new StringBuffer("DELETE FROM MyBlackListBean f WHERE f.myId=? AND f.other.id IN (");
    for(int i=0;i<otherIds.length;i++){
      hql.append("?,");
    }
    hql.append("?)");
    Session ssn = getSession();
    try{
      beginTransaction();
      Query q = ssn.createQuery(hql.toString());
      q.setInteger(0, ownerId);
      int i=0;
      for(;i<otherIds.length;i++){
        String s_id = (String)otherIds[i];
        int id = -1;
View Full Code Here

   * @param lastLogin ���һ�ε�¼��ʱ��
   * @param manual_logout �Ƿ��ֹ�ע��
   * @return
   */
  public static int userLogout(int userid, Timestamp lastLogin, boolean manual_logout){
    Session ssn = getSession();
    if(ssn == null)
      return -1;
    try{
      beginTransaction();
      Query q = ssn.getNamedQuery(manual_logout?"USER_LOGOUT_1":"USER_LOGOUT_2");
      q.setInteger("online_status", UserBean.STATUS_OFFLINE);
      if(manual_logout)
        q.setInteger("keep_day", 0);
      q.setInteger("user_id", userid);
      q.setTimestamp("last_time", lastLogin);
View Full Code Here

  /**
   * Ǩ���ռ�����
   * @throws Exception
   */
  protected static void transfer_diary_replies() throws Exception{
    Session ssn = HibernateUtils.getSession();
    try{
      HibernateUtils.beginTransaction();
      List rpls = ssn.createQuery("FROM DiaryReplyBean AS r ORDER BY r.id").list();
      for(int i=0;i<rpls.size();i++){
        DiaryReplyBean rpl = (DiaryReplyBean)rpls.get(i);
        CommentBean cb = new CommentBean();
        cb.setClient(rpl.getClient());
        AuthorInfo author = new AuthorInfo();
        author.setEmail(rpl.getAuthorEmail());
        author.setName(rpl.getAuthor());
        author.setUrl(rpl.getAuthorURL());
        if(rpl.getUser()!=null){
          author.setId(rpl.getUser().getId());
        }
        cb.setAuthor(author);
        cb.setContent(rpl.getContent());
        cb.setCreateTime(rpl.getReplyTime());
        cb.setEid(rpl.getDiary().getId());
        cb.setEtype(DiaryReplyBean.TYPE_DIARY);
        cb.setSite(rpl.getSite());
        cb.setStatus(rpl.getStatus());
        cb.setTitle(StringUtils.abbreviate(rpl.getContent(), 20));
        ssn.save(cb);
        System.out.println("DiaryReplyBean: " + rpl.getId() + " -> " + cb.getId());
      }
      HibernateUtils.commit();
    }catch(Exception e){
      HibernateUtils.rollback();
View Full Code Here

  /**
   * Ǩ���������
   * @throws Exception
   */
  protected static void transfer_photo_replies() throws Exception{
    Session ssn = HibernateUtils.getSession();
    try{
      HibernateUtils.beginTransaction();
      List rpls = ssn.createQuery("FROM PhotoReplyBean AS r ORDER BY r.id").list();
      for(int i=0;i<rpls.size();i++){
        PhotoReplyBean rpl = (PhotoReplyBean)rpls.get(i);
        CommentBean cb = new CommentBean();
        cb.setClient(rpl.getClient());
        AuthorInfo author = new AuthorInfo();
        author.setEmail(rpl.getAuthorEmail());
        author.setUrl(rpl.getAuthorURL());
        author.setName(rpl.getAuthor());
        if(rpl.getUser()!=null){
          author.setId(rpl.getUser().getId());
        }
        cb.setAuthor(author);
        cb.setContent(rpl.getContent());
        cb.setCreateTime(rpl.getReplyTime());
        cb.setEid(rpl.getPhoto().getId());
        cb.setEtype(DiaryReplyBean.TYPE_PHOTO);
        cb.setSite(rpl.getSite());
        cb.setStatus(rpl.getStatus());
        cb.setTitle(StringUtils.abbreviate(rpl.getContent(), 20));
        ssn.save(cb);
        System.out.println("PhotoReplyBean: " + rpl.getId() + " -> " + cb.getId());
      }
      HibernateUtils.commit();
    }catch(Exception e){
      HibernateUtils.rollback();
View Full Code Here

TOP

Related Classes of org.hibernate.Session

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.