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

📄 storeoututil.java

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

package model.store.hibernate;

import dbservice.hibernate.HibernateService;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
 *
 * @author Administrator
 */
public class StoreoutUtil {
    
    public static boolean insert(String clientId, String productId, String roomId, Storeout storeout) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            ClientUtil.addStoreouts(clientId, storeout);
            ProductUtil.addStoreouts(productId, storeout);
            StoreroomUtil.addStoreouts(roomId, storeout);
            session.save(storeout);
            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;
        Transaction transaction = null;
        Session session = null;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            list = HibernateService.execQuery("from Storeout");
            transaction.commit();
            HibernateService.closeSession(session);
        }
        catch (HibernateException he) {
            he.printStackTrace();
            HibernateService.rollbackTransaction(transaction);
            list = null;
        }
        catch (Exception e) {
            e.printStackTrace();
            list = null;
        }
        finally {
            HibernateService.closeSession(session);
            return list;            
        }
    }
    
    public static Storeout find(String id) {
        Storeout storeout = null;
        Transaction transaction = null;
        Session session = null;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            storeout = new Storeout();
            session.load(storeout, Integer.valueOf(id));
            transaction.commit();
        }
        catch (HibernateException he) {
            he.printStackTrace();
            HibernateService.rollbackTransaction(transaction);
            storeout = null;
        }
        catch (Exception e) {
            e.printStackTrace();
            storeout = null;
        }
        finally {            
            HibernateService.closeSession(session);
            return storeout;
        }
    }
    
    public static boolean update(String id, String clientId, String productId, String storeroomId, Storeout s) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Storeout storeout = new Storeout();
            session.load(storeout, Integer.valueOf(id));
            storeout.setName(s.getName());
            storeout.setOuttime(s.getOuttime());
            storeout.setRemarks(s.getRemarks());
            
            ClientUtil.addStoreouts(clientId, storeout);
            
            ProductUtil.addStoreouts(productId, storeout);
            
            StoreroomUtil.addStoreouts(storeroomId, storeout);
            
            session.update(storeout);
            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 + -