moduledaoimpl.java

来自「java学习的必要的资料,servlet的说明很好」· Java 代码 · 共 57 行

JAVA
57
字号
package com.estore.struts.daoimpl;

import java.util.Collection;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.estore.struts.dao.ModuleDao;
import com.estore.struts.entity.Admin;
import com.estore.struts.entity.Module;
import com.estore.struts.utils.HibernateSessionFactory;
import com.estore.struts.utils.StoreException;


public class ModuleDaoImpl implements ModuleDao {
	
	public Collection selectAll() throws Exception {
		Transaction tx = null;
		Session session = null;
		Collection modules=null;
		try {
			session = HibernateSessionFactory.getSession();
			tx = session.beginTransaction();
			modules=session.createQuery("from Module ").list();
			tx.commit();
		} catch (Exception ex) {
			tx.rollback();
			throw new StoreException(ex);
		}finally {
			session.close();
		}
		
		return modules;
	}

	public Module selectModuleById(Integer moduleId) throws Exception {
		Transaction tx = null;
		Session session = null;
		Module module=null;
		try {
			session = HibernateSessionFactory.getSession();
			tx = session.beginTransaction();
			module=(Module)session.createQuery("from Module m where m.moduleid=:moduleId ").setInteger("moduleId", moduleId).uniqueResult();
			tx.commit();
		} catch (Exception ex) {
			tx.rollback();
			throw new StoreException(ex);
		}finally {
			session.close();
		}
		
		return module;
	}

}

⌨️ 快捷键说明

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