📄 moduledaoimpl.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -