⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 articleresponseutil.java

📁 J2EE电子商务系统开发从入门到精通---基于Struts和Hibernate技术实现
💻 JAVA
字号:
/*
 * ArticleresponseUtil.java
 *
 * Created on 2006年6月14日, 上午12:35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package model.bbs.hibernate;
import dbservice.hibernate.HibernateService;
import java.util.*;
import model.hr.hibernate.Employee;
import model.hr.hibernate.EmployeeUtil;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
 *
 * @author Administrator
 */
public class ArticleresponseUtil {
    public static boolean insert(String employeeId, String articleId, Articleresponse response) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Date date = new Date();
            response.setPresstime(new Date().toString());
            
//            Employee employee = new Employee();
//            Article article = new Article();
//            
//            session.load(employee, employeeId);
//            session.load(article, Integer.valueOf(articleId));
//            
//            employee.getArticleresponses().add(response);
//            response.setEmployee(employee);
//            
//            article.getArticleresponses().add(response);
//            response.setArticle(article);
            EmployeeUtil.addArticleresponses(employeeId, response);
            ArticleUtil.addArticleresponses(articleId, response);
            
            session.save(response);
            transaction.commit();
            b = true;
        }
        catch (HibernateException he) {
            he.printStackTrace();
            HibernateService.rollbackTransaction(transaction);
            b = false;
        }
        catch (Exception e) {
            e.printStackTrace();
            b = false;
        }
        finally {
            HibernateService.closeSession(session);
            return b;
        }
    }
    
    public static boolean update(String id, String employeeId, String articleId, Articleresponse response) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Articleresponse ar = new Articleresponse();
            session.load(response, Integer.valueOf(id));
            
            ar.setContent(response.getContent());
            ar.setPresstime(new Date().toString());
            
            Employee employee = new Employee();
            session.load(employee, employeeId);
            response.getEmployee().getArticleresponses().remove(response);
            employee.getArticleresponses().add(response);
            response.setEmployee(employee);
            
            Article article = new Article();
            session.load(article, Integer.valueOf(articleId));
            response.getArticle().getArticleresponses().remove(response);
            article.getArticleresponses().add(response);
            response.setArticle(article);
            
            session.update(ar);
            transaction.commit();
            b = true;
        }
        catch (HibernateException he) {
            he.printStackTrace();
            HibernateService.rollbackTransaction(transaction);
            b = false;
        }
        catch (Exception e) {
            e.printStackTrace();
            b = false;
        }
        finally {
            HibernateService.closeSession(session);
            return b;
        }
    }
    
    public static Article find(String id) {
        Article article = null;
        Transaction transaction = null;
        Session session = null;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            article = new Article();
            session.load(article, Integer.valueOf(id));
            transaction.commit();
            HibernateService.closeSession(session);
        }
        catch (HibernateException he) {
            he.printStackTrace();
            HibernateService.rollbackTransaction(transaction);
            article = null;
        }
        catch (Exception e) {
            e.printStackTrace();
            article = null;
        }
        finally {
            HibernateService.closeSession(session);
            return article;
        }
    }
    
    public static boolean delete(String id) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Articleresponse response = new Articleresponse();
            session.load(response, Integer.valueOf(id));
            session.delete(response);
            transaction.commit();
            b = true;
        }
        catch (HibernateException he) {
            he.printStackTrace();
            HibernateService.rollbackTransaction(transaction);
            b = false;
        }
        catch (Exception e) {
            e.printStackTrace();
            b = false;
        }
        finally {
            HibernateService.closeSession(session);
            return b;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -