?? choiceutil.java
字號:
/*
* ChoiceUtil.java
*
* Created on 2006年8月12日, 下午9:18
*
* 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.HashSet;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
*
* @author Administrator
*/
public class ChoiceUtil {
public static boolean insert(String themeId, Choice choice) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
ThemeUtil.addChoices(themeId, choice);
session.save(choice);
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 themeId, Choice choice) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Choice c = new Choice();
session.load(c, Integer.valueOf(id));
c.setName(choice.getName());
ThemeUtil.addChoices(themeId, c);
session.update(c);
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(String themeId) {
List list = null;
list = HibernateService.execQuery("from Choice c where c.theme.id=" + themeId);
return list;
}
public static Choice find(String id) {
Choice choice = null;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
choice = new Choice();
session.load(choice, Integer.valueOf(id));
transaction.commit();
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
choice = null;
}
catch (Exception e) {
e.printStackTrace();
choice = null;
}
finally {
HibernateService.closeSession(session);
return choice;
}
}
public static boolean delete(String id) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Choice choice = new Choice();
session.load(choice, Integer.valueOf(id));
session.delete(choice);
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 addResults(String id, Result result) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Choice choice = new Choice();
session.load(choice, Integer.valueOf(id));
result.setChoice(choice);
session.update(choice);
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 + -