📄 computerdao.java
字号:
package com.bank.hibernate.pojo;
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 Computer.
*
* @see com.bank.hibernate.pojo.Computer
* @author MyEclipse Persistence Tools
*/
public class ComputerDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(ComputerDAO.class);
// property constants
public static final String COM_NUMBER = "comNumber";
public static final String COM_TYPE = "comType";
public static final String COM_CPU = "comCpu";
public static final String COM_MEMORY = "comMemory";
public static final String COM_HARD_DISK = "comHardDisk";
public static final String COM_OS = "comOs";
public static final String COM_MEND = "comMend";
public static final String COM_ANTI_VIRUS = "comAntiVirus";
public static final String COM_IPADDRESS = "comIpaddress";
public static final String COM_MACADDRESS = "comMacaddress";
public static final String COM_USER_ID = "comUserId";
public static final String COM_USER_NAME = "comUserName";
public static final String COM_USER_UNIT = "comUserUnit";
public static final String COM_HOUSE_ID = "comHouseId";
public static final String COM_DUTY_MAN = "comDutyMan";
public static final String COM_PURPOSE = "comPurpose";
public static final String COM_USE_DEVICE = "comUseDevice";
public void save(Computer transientInstance) {
log.debug("saving Computer instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Computer persistentInstance) {
log.debug("deleting Computer instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Computer findById(java.lang.Integer id) {
log.debug("getting Computer instance with id: " + id);
try {
Computer instance = (Computer) getSession().get(
"com.bank.hibernate.pojo.Computer", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Computer instance) {
log.debug("finding Computer instance by example");
try {
List results = getSession().createCriteria(
"com.bank.hibernate.pojo.Computer").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 Computer instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Computer 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 findByComNumber(Object comNumber) {
return findByProperty(COM_NUMBER, comNumber);
}
public List findByComType(Object comType) {
return findByProperty(COM_TYPE, comType);
}
public List findByComCpu(Object comCpu) {
return findByProperty(COM_CPU, comCpu);
}
public List findByComMemory(Object comMemory) {
return findByProperty(COM_MEMORY, comMemory);
}
public List findByComHardDisk(Object comHardDisk) {
return findByProperty(COM_HARD_DISK, comHardDisk);
}
public List findByComOs(Object comOs) {
return findByProperty(COM_OS, comOs);
}
public List findByComMend(Object comMend) {
return findByProperty(COM_MEND, comMend);
}
public List findByComAntiVirus(Object comAntiVirus) {
return findByProperty(COM_ANTI_VIRUS, comAntiVirus);
}
public List findByComIpaddress(Object comIpaddress) {
return findByProperty(COM_IPADDRESS, comIpaddress);
}
public List findByComMacaddress(Object comMacaddress) {
return findByProperty(COM_MACADDRESS, comMacaddress);
}
public List findByComUserId(Object comUserId) {
return findByProperty(COM_USER_ID, comUserId);
}
public List findByComUserName(Object comUserName) {
return findByProperty(COM_USER_NAME, comUserName);
}
public List findByComUserUnit(Object comUserUnit) {
return findByProperty(COM_USER_UNIT, comUserUnit);
}
public List findByComHouseId(Object comHouseId) {
return findByProperty(COM_HOUSE_ID, comHouseId);
}
public List findByComDutyMan(Object comDutyMan) {
return findByProperty(COM_DUTY_MAN, comDutyMan);
}
public List findByComPurpose(Object comPurpose) {
return findByProperty(COM_PURPOSE, comPurpose);
}
public List findByComUseDevice(Object comUseDevice) {
return findByProperty(COM_USE_DEVICE, comUseDevice);
}
public List findAll() {
log.debug("finding all Computer instances");
try {
String queryString = "from Computer";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Computer merge(Computer detachedInstance) {
log.debug("merging Computer instance");
try {
Computer result = (Computer) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Computer instance) {
log.debug("attaching dirty Computer instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Computer instance) {
log.debug("attaching clean Computer instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static void main(String arg0[]){
new ComputerDAO().findAll();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -