?? recipeinfodao.java
字號(hào):
package com.xttc.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.classic.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.xttc.pojo.Managerinfo;
import com.xttc.pojo.Recipeinfo;
/**
* A data access object (DAO) providing persistence and search support for
* Recipeinfo entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see com.xttc.pojo.Recipeinfo
* @author MyEclipse Persistence Tools
*/
public class RecipeinfoDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(RecipeinfoDAO.class);
// property constants
public static final String PATIENT_NAME = "patientName";
public static final String AGE = "age";
public static final String REMARK = "remark";
public static final String SEX= "sex";
public static final String TOTAL = "total";
public static final String DATE= "date";
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
protected void initDao() {
// do nothing
}
public void save(Recipeinfo transientInstance) {
log.debug("saving Recipeinfo instance");
try {
getHibernateTemplate().saveOrUpdate(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Recipeinfo persistentInstance) {
log.debug("deleting Recipeinfo instance");
boolean i = false;
Connection conn = null;
PreparedStatement pstm = null;
String sql = "delete from recipeinfo where id="+persistentInstance.getId();
Session session = getHibernateTemplate().getSessionFactory().openSession().getSessionFactory().openSession();
conn = session.connection();
try {
pstm = conn.prepareStatement(sql);
i = pstm.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
pstm = null;
conn = null;
}
}
public Recipeinfo findById(java.lang.Integer id) {
log.debug("getting Recipeinfo instance with id: " + id);
try {
Recipeinfo instance = (Recipeinfo) getHibernateTemplate().get(
"com.xttc.pojo.Recipeinfo", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Recipeinfo instance) {
log.debug("finding Recipeinfo 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 Recipeinfo instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Recipeinfo 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 findByPatientName(Recipeinfo instance ) {
// String sql = "select * from recipeinfo where patientName like '%"
// + instance.getPatientName() + "%'";
// Session session = this.getSessionFactory().openSession();
// return session.createSQLQuery(sql).addEntity(
// "com.flourmill.pojo.InventoryView").list();}
log.debug("finding Recipeinfo instance by example");
List<Recipeinfo> list = new ArrayList<Recipeinfo>();
String sql = "select * from recipeinfo where patientName like '%" + instance.getPatientName()+ "%'";
Session session = getHibernateTemplate().getSessionFactory()
.openSession();
conn = session.connection();
try {
pstm = conn.prepareStatement(sql);
rs = pstm.executeQuery();
while (rs.next()) {
Recipeinfo recipeinfo= new Recipeinfo();
recipeinfo.setPatientName(rs.getString("patientName"));
recipeinfo.setId(rs.getInt("id"));
recipeinfo.setAge(rs.getInt("age"));
recipeinfo.setSex(rs.getInt("sex"));
recipeinfo.setDate(rs.getString("date"));
recipeinfo.setTotal(rs.getInt("total"));
list.add(recipeinfo);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
rs.close();
pstm.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
}
public List findByPatientName(Object patientName) {
return findByProperty(PATIENT_NAME, patientName);
}
public List findByAge(Object age) {
return findByProperty(AGE, age);
}
public List findByRemark(Object remark) {
return findByProperty(REMARK, remark);
}
public List findBySex(Object sex) {
return findByProperty(SEX, sex);
}
public List findByTotal(Object total) {
return findByProperty(TOTAL, total);
}
public List findByDate(Object date) {
return findByProperty(DATE, date);
}
public List findAll() {
log.debug("finding all Recipeinfo instances");
try {
String queryString = "from Recipeinfo";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Recipeinfo merge(Recipeinfo detachedInstance) {
log.debug("merging Recipeinfo instance");
try {
Recipeinfo result = (Recipeinfo) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Recipeinfo instance) {
log.debug("attaching dirty Recipeinfo instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public int getMaxId(){
String sql = "select max(id) from recipeinfo";
Session session = getHibernateTemplate().getSessionFactory().openSession();
return (Integer)session.createSQLQuery(sql).list().get(0);
}
public void attachClean(Recipeinfo instance) {
log.debug("attaching clean Recipeinfo instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static RecipeinfoDAO getFromApplicationContext(ApplicationContext ctx) {
return (RecipeinfoDAO) ctx.getBean("RecipeinfoDAO");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -