📄 mntypedao.java
字号:
package cn.hope.mana.pojo.dao;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import org.apache.log4j.Logger;
import cn.hope.mana.pojo.MNtype;
import cn.hope.mana.pojo.base.BaseMNtypeDAO;
public class MNtypeDAO extends BaseMNtypeDAO {
Logger log = Logger.getLogger(MNtypeDAO.class.getName());
/**
* Default constructor. Can be used in place of getInstance()
*/
public MNtypeDAO () {}
public List searchAll() throws HibernateException {
String sqlStr = "select mNtype from MNtype mNtype where mNtype.flag='0'";
try {
initialize();
return this.getSession().find(sqlStr);
}catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
public MNtype load(Integer typeId) throws HibernateException{
try {
initialize();
return super.load(typeId);
}catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
public void update(MNtype mNtype) throws HibernateException{
try {
initialize();
super.update(mNtype);
}catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
/**
* 添加数据方法
*
* @param MHtype
* @return int
* @throws HibernateException
*/
public Integer insert(MNtype mNtype) throws HibernateException {
try {
initialize();
if (searchByName(mNtype) == null){
this.save(mNtype);
}
return searchByName(mNtype);
}catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
public Integer searchByName(MNtype mNtype) throws HibernateException {
String sqlKey = "select mNtype.typeId from MNtype mNtype where mNtype.flag='0' and mNtype.NType='"
+mNtype.getNType()+"'";
try {
initialize();
Query queryCnt = this.getSession().createQuery(
sqlKey.toString());
Integer i = (Integer)queryCnt.uniqueResult();
return i;
}catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
public int searchByName(String ntype) throws HibernateException {
String sqlCnt = "select count(mNtype.typeId) from MNtype mNtype where mNtype.flag='0' and mNtype.NType='"
+ntype+"'";
try {
initialize();
Query queryCnt = this.getSession().createQuery(
sqlCnt.toString());
return ((Integer)queryCnt.uniqueResult()).intValue();
}catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -