📄 tadmindao.java
字号:
package edu.neu.sspp.hibernate;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
/**
* Data access object (DAO) for domain model class TAdmin.
* @see edu.neu.sspp.hibernate.TAdmin
* @author MyEclipse - Hibernate Tools
*/
public class TAdminDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(TAdminDAO.class);
//property constants
public static final String NAME = "name";
public static final String PASSWORD = "password";
public void save(TAdmin transientInstance) {
log.debug("saving TAdmin instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(TAdmin persistentInstance) {
log.debug("deleting TAdmin instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public TAdmin findById( java.lang.String id) {
log.debug("getting TAdmin instance with id: " + id);
try {
TAdmin instance = (TAdmin) getSession()
.get("edu.neu.sspp.hibernate.TAdmin", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public int getCount() {
log.debug("getting count of TAdmin");
try {
String queryString = "select count(*) from TAdmin";
Query queryObject = getSession().createQuery(queryString);
return ((Integer)queryObject.list().get(0)).intValue();
} catch (RuntimeException re) {
log.error("getting count of TAdmin failed", re);
throw re;
}
}
public List getByPage(int first, int size) {
log.debug("getting TAdmin for page");
try {
//按名字排列
String queryString = "from TAdmin as admin order by admin.name";
Query queryObject = getSession().createQuery(queryString);
queryObject.setFirstResult(first);
//mysql似乎不支持setFetchSize,无法实现部分查询,只能通过setMaxResults在返回结果上控制
//queryObject.setFetchSize(size);
queryObject.setMaxResults(size);
return queryObject.list();
} catch(RuntimeException re) {
log.error("get by page failed", re);
throw re;
}
}
public List findByExample(TAdmin instance) {
log.debug("finding TAdmin instance by example");
try {
List results = getSession()
.createCriteria("edu.neu.sspp.hibernate.TAdmin")
.add(Example.create(instance))
.list();
log.debug("find by example successful, result size: " + results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding TAdmin instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from TAdmin as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByName(Object name) {
return findByProperty(NAME, name);
}
public List findByPassword(Object password) {
return findByProperty(PASSWORD, password);
}
public TAdmin merge(TAdmin detachedInstance) {
log.debug("merging TAdmin instance");
try {
TAdmin result = (TAdmin) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(TAdmin instance) {
log.debug("attaching dirty TAdmin instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(TAdmin instance) {
log.debug("attaching clean TAdmin instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -