?? accountdao.java
字號:
package com.icome.dao;
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.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import com.icome.db.ConnectionFactory;
import com.icome.entity.Account;
import com.mysql.jdbc.CallableStatement;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
/**
* Data access object (DAO) for domain model class Account.
* @see com.icome.dao.Account
* @author MyEclipse - Hibernate Tools
*/
public class AccountDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(AccountDAO.class);
//property constants
public static final String PWD = "pwd";
public static final String REALNAME = "realname";
public static final String SEX = "sex";
public static final String UNIVERSITY = "university";
public static final String DEPARTMENT = "department";
public static final String EMAIL = "email";
public static final String MSN = "msn";
public static final String QQ = "qq";
public static final String TELEPHONE = "telephone";
public static final String CELLPHONE = "cellphone";
public static final String ADDRESS = "address";
public static final String ZIPCODE = "zipcode";
public static final String ABOUT = "about";
public static final String URL = "url";
public void save(Account transientInstance) {
log.debug("saving Account instance");
try {
Session s = getSession();
Transaction t=s.beginTransaction();
s.save(transientInstance);
t.commit();
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Account persistentInstance) {
log.debug("deleting Account instance");
try {
Session s = getSession();
Transaction t=s.beginTransaction();
s.delete(persistentInstance);
t.commit();
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Account findById( java.lang.String id) {
log.debug("getting Account instance with id: " + id);
try {
Account instance = (Account) getSession()
.get("com.icome.entity.Account", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Account instance) {
log.debug("finding Account instance by example");
try {
List results = getSession()
.createCriteria("com.icome.entity.Account")
.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 Account instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Account 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 findByPwd(Object pwd) {
return findByProperty(PWD, pwd);
}
public List findByRealname(Object realname) {
return findByProperty(REALNAME, realname);
}
public List findBySex(Object sex) {
return findByProperty(SEX, sex);
}
public List findByUniversity(Object university) {
return findByProperty(UNIVERSITY, university);
}
public List findByDepartment(Object department) {
return findByProperty(DEPARTMENT, department);
}
public List findByEmail(Object email) {
return findByProperty(EMAIL, email);
}
public List findByMsn(Object msn) {
return findByProperty(MSN, msn);
}
public List findByQq(Object qq) {
return findByProperty(QQ, qq);
}
public List findByTelephone(Object telephone) {
return findByProperty(TELEPHONE, telephone);
}
public List findByCellphone(Object cellphone) {
return findByProperty(CELLPHONE, cellphone);
}
public List findByAddress(Object address) {
return findByProperty(ADDRESS, address);
}
public List findByZipcode(Object zipcode) {
return findByProperty(ZIPCODE, zipcode);
}
public List findByAbout(Object about) {
return findByProperty(ABOUT, about);
}
public List findByUrl(Object url) {
return findByProperty(URL, url);
}
public Account merge(Account detachedInstance) {
log.debug("merging Account instance");
try {
Account result = (Account) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Account instance) {
log.debug("attaching dirty Account instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Account instance) {
log.debug("attaching clean Account instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public boolean login(String uid, String pwd) {
try{
Connection conn = ConnectionFactory.getConnection();
CallableStatement cst = (CallableStatement) conn.prepareCall("{Call login(?,?)}");
cst.setString(1, uid);
cst.setString(2, pwd);
ResultSet rs = (ResultSet) cst.executeQuery();
if(rs.next()) return true;
return false;
}catch(Exception e)
{
e.printStackTrace();
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -