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

📄 d0fc1c4e2d9a001b18abbf5fd3239213

📁 用jsf实现cd商店的程序
💻
字号:
package com.tangjun.data.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.tangjun.data.ICDDao;
import com.tangjun.data.hibernate.HibernateSessionFactory;
import com.tangjun.model.exception.MyException;
import com.tangjun.web.pojo.CD;

public class CDDaoImpl implements ICDDao
{
	public enum Action
	{
		Add,Delete,Update,Select,SelectAll
	}

	public CDDaoImpl()
	{

	}

	public boolean addCD(CD cd)
	{
		Session session = HibernateSessionFactory.getSession();
		Transaction tx = session.beginTransaction();
		session.save(cd);
		tx.commit();
		session.close();
		return true;
	}

	public boolean delCD(Integer id)
	{
		Session session = HibernateSessionFactory.getSession();
		Transaction tx = session.beginTransaction();
		CD cd = (CD)ht.load(CD.class,id);
		ht.delete(cd);
		return true;
	}

	public boolean updateCD(CD cd)
	{
		ht.update(cd);
		return true;
	}

	public CD findCDById(Integer id)
	{
		String hql = "from CD c where id=?";
		List cdList = ht.find(hql,id);
		if(cdList.size() == 1)
			return (CD)cdList.get(0);
		return null;
	}

	public List getAllCD() throws MyException
	{
		String hql = "from CD c";
		try
		{
			List cds = null; // = this.getHibernateTemplate().find(hql);
			return cds;
		}
		catch(Exception e)
		{
			throw new MyException(e.getMessage());
		}
		// return ht.find("from cd c");
	}

	public void destoryHibernateTemplate()
	{
		ht = null;
	}

	public void invoke(Action action,Object obj)throws MyException
	{
		Session session = HibernateSessionFactory.getSession();
		Transaction tx = session.beginTransaction();

		switch(action.ordinal())
		{
			case 0 :
				break;
			case 1 :
				break;
			case 2 :
				break;
			case 3 :
				break;
			case 4 :
				break;
			case 5 :
				break;
			default :
				throw new MyException("没有这个方法供您调用!");
		}
		tx.commit();
		session.close();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -