📄 resultutil.java
字号:
/*
* ResultUtil.java
*
* Created on 2006年8月20日, 下午5:25
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package model.vote.hibernate;
import dbservice.hibernate.HibernateService;
import java.util.*;
import model.hr.hibernate.*;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
*
* @author Administrator
*/
public class ResultUtil {
public static boolean insert(String choiceId, String employeeId) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Result result = new Result();
// Choice choice = new Choice();
// Employee employee = new Employee();
//
// session.load(choice, Integer.valueOf(choiceId));
// session.load(employee, employeeId);
//
// choice.getResults().add(result);
// employee.getResults().add(result);
// result.setChoice(choice);
// result.setEmployee(employee);
ChoiceUtil.addResults(choiceId, result);
EmployeeUtil.addResults(employeeId, result);
session.save(result);
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 List findAll() {
List list = null;
list = HibernateService.execQuery("from Result");
return list;
}
public static List getResultByTheme(String themeId) {
String hql = "from Choice choice " +
" where choice.theme.id=" + themeId;
List list = HibernateService.execQuery(hql);
if (list == null) {
return null;
}
Choice[] choiceList = new Choice[list.size()];
list.toArray(choiceList);
String sql = "select count(*) from Result result " +
" where result.choice.theme.id=" + themeId;
int rows = HibernateService.getRows(sql);
list.clear();
for (int i=0; i<choiceList.length; i++) {
list.add(choiceList[i].getName());
hql = "select count(*) from Result result " +
" where result.choice.id=" + choiceList[i].getId();
int total = HibernateService.getRows(hql);
list.add(new Integer(total));
list.add(new Integer(rows));
}
return list;
}
public static List getResultByDepartment(String themeId, Department department) {
String hql = "from Choice choice " +
" where choice.theme.id=" + themeId;
List list = HibernateService.execQuery(hql);
Choice[] choiceList = new Choice[list.size()];
list.toArray(choiceList);
hql = "select count(*) from Result result " +
" where result.choice.theme.id=" + themeId +
" and result.employee.department.id=" + department.getId();
int total = HibernateService.getRows(hql);
list = new ArrayList();
for (int i=0; i<choiceList.length; i++) {
list.add(choiceList[i].getName());
hql = "select count(*) from Result result " +
" where result.choice.id=" + choiceList[i].getId() +
" and result.choice.theme.id=" + themeId +
" and result.employee.department.id=" + department.getId();
int rows = HibernateService.getRows(hql);
list.add(new Integer(rows));
list.add(new Integer(total));
}
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -