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

📄 themeutil.java

📁 J2EE电子商务系统开发从入门到精通---基于Struts和Hibernate技术实现
💻 JAVA
字号:
/*
 * ThemeUtil.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 ThemeUtil {
    
    public static boolean insert(Theme theme) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            theme.setChoices(new HashSet());
            session.save(theme);
            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, Theme theme) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Theme t = new Theme();
            session.load(t, Integer.valueOf(id));
            t.setName(theme.getName());
            t.setContent(theme.getContent());
            t.setRemarks(theme.getRemarks());
            session.update(t);
            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 Theme");
        return list;
    }
    
    public static Theme find(String id) {
        Theme theme = null;
        Transaction transaction = null;
        Session session = null;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            theme = new Theme();
            session.load(theme, Integer.valueOf(id));
            transaction.commit();            
        } 
        catch (HibernateException he) {
            he.printStackTrace();
            HibernateService.rollbackTransaction(transaction);
            theme = null;
        } 
        catch (Exception e) {
            e.printStackTrace();
            theme = null;
        }
        finally {
            HibernateService.closeSession(session);
            return theme;
        }
    }
    
    public static boolean delete(String id) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Theme theme = new Theme();
            session.load(theme, Integer.valueOf(id));
            theme.getChoices().clear();
            session.delete(theme);
            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 addChoices(String id, Choice choice) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Theme theme = new Theme();
            session.load(theme, Integer.valueOf(id));
            choice.setTheme(theme);
            session.update(theme);
            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 + -