📄 00a8a2602d9a001b18abbf5fd3239213
字号:
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)session.load(CD.class,id);
session.delete(cd);
tx.commit();
session.close();
return true;
}
public boolean updateCD(CD cd)
{
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
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 + -