📄 documentdao.java
字号:
package com.oa.document.db;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Data access object (DAO) for domain model class Document.
* @see com.oa.document.db.Document
* @author MyEclipse - Hibernate Tools
*/
public class DocumentDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(DocumentDAO.class);
//property constants
public static final String SENDER = "sender";
public static final String TITLE = "title";
public static final String CONTENT = "content";
public static final String FILE = "file";
public static final String TRUEFILE = "truefile";
public static final String STATE = "state";
protected void initDao() {
//do nothing
}
public boolean save(Document transientInstance) {
log.debug("saving Document instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
return true;
} catch (RuntimeException re) {
log.error("save failed", re);
re.printStackTrace();
return false;
}
}
public void updateDocstate(Integer id, String state) {
log.debug("updateing Document instance");
try {
Document vo = (Document)getHibernateTemplate().get(Document.class, id);
vo.setState(state);
getHibernateTemplate().saveOrUpdate(vo);
log.debug("update successful");
} catch (RuntimeException re) {
log.error("update failed", re);
throw re;
}
}
public boolean updateDoc(Integer id, Document instance) {
log.debug("updateing Document instance");
try {
Document vo = (Document)getHibernateTemplate().get(Document.class, id);
vo.setTitle(instance.getTitle());
vo.setContent(instance.getContent());
vo.setFile(instance.getFile());
vo.setTruefile(instance.getTruefile());
vo.setState(instance.getState());
getHibernateTemplate().saveOrUpdate(vo);
log.debug("update successful");
return true;
} catch (Exception re) {
log.error("update failed", re);
re.printStackTrace();
return false;
}
}
public void delete(Document persistentInstance) {
log.debug("deleting Document instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Document findById( java.lang.Integer id) {
log.debug("getting Document instance with id: " + id);
try {
Document instance = (Document) getHibernateTemplate()
.get("com.oa.document.db.Document", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Document instance) {
log.debug("finding Document instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
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 Document instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Document as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findBySender(Object sender) {
return findByProperty(SENDER, sender);
}
public List findByTitle(Object title) {
return findByProperty(TITLE, title);
}
public List findByContent(Object content) {
return findByProperty(CONTENT, content);
}
public List findByFile(Object file) {
return findByProperty(FILE, file);
}
public List findByTruefile(Object truefile) {
return findByProperty(TRUEFILE, truefile);
}
public List findByState(Object state) {
return findByProperty(STATE, state);
}
public Document merge(Document detachedInstance) {
log.debug("merging Document instance");
try {
Document result = (Document) getHibernateTemplate()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Document instance) {
log.debug("attaching dirty Document instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Document instance) {
log.debug("attaching clean Document instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static DocumentDAO getFromApplicationContext(ApplicationContext ctx) {
return (DocumentDAO) ctx.getBean("DocumentDAO");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -