【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-ArticleresponseUtil.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;
}
}
}
上一篇:
Articleresponse.java
下一篇:
离开学校,走进社会的100条忠告