papertypedaoimp.java

来自「该在线考试关系统(B/S结构)主要采用JAVA语言开发涉及主要WEB技术有:St」· Java 代码 · 共 88 行

JAVA
88
字号
package dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import po.Opapertype;
import dao.IPaperTypeDao;

public class PaperTypeDaoImp implements IPaperTypeDao
{
	private SessionFactory sf;
	private HibernateTemplate template;
	
	public SessionFactory getSf()
	{
		return sf;
	}

	public void setSf(SessionFactory sf)
	{
		this.sf = sf;
		template = new HibernateTemplate(sf);
	}

	public void addPaperType(Opapertype ptype)
	{
		template.save(ptype);
		sf.close();
	}

	public void delPaperType(long id)
	{
		template.delete(this.findPaperType(id));
		sf.close();
	}

	public List findAllPaperType()
	{
		List list = template.find("from Opapertype");
		sf.close();
		return list;
	}

	public void updataPaperType(Opapertype ptype)
	{
		template.saveOrUpdate(ptype);
		sf.close();
	}

	public Opapertype findPaperType(long id)
	{
		Opapertype ptype = (Opapertype) template.get(Opapertype.class, id);
		sf.close();
		return ptype;
	}

	public boolean judgeTypeContain(String name)
	{	
		
		SessionFactory sf = template.getSessionFactory();
		Session s = sf.openSession();
		String hql = "from Opapertype as o WHERE o.name=?" ;
	    Query q = s.createQuery(hql);
	    q.setString(0,name);
		List list  = q.list();
		sf.close();
		if(list.size()==0)
		{
			return true;
		}
		else
		{
			return false;
		}
	    
	    
/*		String hql = "select o from Opapertype o where o.name = '"+name+"'";
		System.out.print(hql);
//        String sql = "select * from Opapertype where name = '"+name+"'";
		List list = template.find(hql);*/
		
	}
	
}

⌨️ 快捷键说明

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