📄 jimuserdao.java
字号:
package com.jim.database;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Example;
/**
* Data access object (DAO) for domain model class JIMUser.
* @see com.jim.database.JIMUser
* @author MyEclipse - Hibernate Tools
*/
public class JIMUserDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(JIMUserDAO.class);
//property constants
public static final String PWD = "pwd";
public static final String NICKNM = "nicknm";
public static final String STATUS = "status";
public static final String IP = "ip";
public static final String GENDER = "gender";
public static final String EMAIL = "email";
public static final String INFOR = "infor";
public static final String PICINDEX = "picindex";
public void save(JIMUser transientInstance) {
log.debug("saving JIMUser instance via JIMUserDAO");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(JIMUser persistentInstance) {
log.debug("deleting JIMUser instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public JIMUser findById( java.lang.Integer id) {
log.debug("getting JIMUser instance with id: " + id);
try {
JIMUser instance = (JIMUser) getSession()
.get(JIMUser.class , id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
@SuppressWarnings("unchecked")
public List<JIMUser> findByExample(JIMUser instance) {
log.debug("finding JIMUser instance by example");
try {
List results = getSession()
.createCriteria(JIMUser.class)
.add(Example.create(instance))
.list();
log.debug("find by example successful, result size: " + results.size());
return (List<JIMUser>)results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
@SuppressWarnings("unchecked")
public List<JIMUser> findByCriteria(Criterion... criterion) {
log.debug("finding JIMUser instance by Criteria");
try {
Criteria crit = getSession().createCriteria(JIMUser.class);
for (Criterion c : criterion) {
crit.add(c);
}
List results = crit.list();
return (List<JIMUser>)results;
} catch (RuntimeException re) {
log.error("find by Criteria failed", re);
throw re;
}
}
@SuppressWarnings("unchecked")
public List<JIMUser> findByProperty(String propertyName, Object value) {
log.debug("finding JIMUser instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from JIMUser as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return (List<JIMUser>)queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List<JIMUser> findByPwd(Object pwd) {
return findByProperty(PWD, pwd);
}
public List<JIMUser> findByNicknm(Object nicknm) {
return findByProperty(NICKNM, nicknm);
}
public List<JIMUser> findByStatus(boolean status) {
return findByProperty(STATUS, new Boolean(status));
}
public List<JIMUser> findByIp(Object ip) {
return findByProperty(IP, ip);
}
public List<JIMUser> findByGender(Object gender) {
return findByProperty(GENDER, gender);
}
public List<JIMUser> findByEmail(Object email) {
return findByProperty(EMAIL, email);
}
public List<JIMUser> findByInfor(Object infor) {
return findByProperty(INFOR, infor);
}
public List<JIMUser> findByPicindex(Object picindex) {
return findByProperty(PICINDEX, picindex);
}
public JIMUser merge(JIMUser detachedInstance) {
log.debug("merging JIMUser instance");
try {
JIMUser result = (JIMUser) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(JIMUser instance) {
log.debug("attaching dirty JIMUser instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(JIMUser instance) {
log.debug("attaching clean JIMUser instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void update(JIMUser instance){
log.debug("update changed JIMUser instance");
try{
getSession().update(instance);
log.debug("update successful");
}catch (RuntimeException re){
log.error("update failed",re);
throw re;
}
}
public List<JIMUser> findFriendsById(Integer id){
log.debug("find friends by id: "+id);
try{
String query = "select {A.*} from JIMUSER A join FRIENDSHIP B on (B.masterno='"
+ id
+ "' and B.subno=A.jimno)";
List results = getSession().createSQLQuery(query)
.addEntity("A", JIMUser.class)
.list();
log.debug("find friends by id successful");
return results;
} catch (RuntimeException re) {
log.error("find friends by id failed", re);
throw re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -