?? recipedetailinfodao.java
字號:
package com.xttc.dao;
import java.util.ArrayList;
import java.util.List;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.xttc.pojo.MyRecipDetail;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.xttc.pojo.Classinfo;
import com.xttc.pojo.Druginfo;
import com.xttc.pojo.Recipedetailinfo;
/**
* A data access object (DAO) providing persistence and search support for
* Recipedetailinfo 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.Recipedetailinfo
* @author MyEclipse Persistence Tools
*/
public class RecipedetailinfoDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(RecipedetailinfoDAO.class);
// property constants
public static final String AMOUNT = "amount";
protected void initDao() {
// do nothing
}
public void save(Recipedetailinfo transientInstance) {
log.debug("saving Recipedetailinfo instance");
try {
getHibernateTemplate().saveOrUpdate(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Recipedetailinfo persistentInstance) {
log.debug("deleting Recipedetailinfo instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Recipedetailinfo findById(java.lang.Integer id) {
log.debug("getting Recipedetailinfo instance with id: " + id);
try {
Recipedetailinfo instance = (Recipedetailinfo) getHibernateTemplate()
.get("com.xttc.pojo.Recipedetailinfo", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Recipedetailinfo instance) {
log.debug("finding Recipedetailinfo 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 Recipedetailinfo instance with property: "
+ propertyName + ", value: " + value);
try {
String queryString = "from Recipedetailinfo 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 findByAmount(Object amount) {
return findByProperty(AMOUNT, amount);
}
public List findAll() {
log.debug("finding all Recipedetailinfo instances");
try {
String queryString = "from Recipedetailinfo";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Recipedetailinfo merge(Recipedetailinfo detachedInstance) {
log.debug("merging Recipedetailinfo instance");
try {
Recipedetailinfo result = (Recipedetailinfo) getHibernateTemplate()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Recipedetailinfo instance) {
log.debug("attaching dirty Recipedetailinfo instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Recipedetailinfo instance) {
log.debug("attaching clean Recipedetailinfo instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public List<MyRecipDetail> findByRecipe(int id){
Connection conn = null;
List<MyRecipDetail> list = new ArrayList<MyRecipDetail>();
PreparedStatement pstm = null;
ResultSet rs = null;
String sql = "select dr.drugName,rd.amount,cl.className,cl.unit from recipedetailinfo rd, druginfo dr,classinfo cl where rd.recipeid= "+id+" and rd.drugid=dr.id and dr.subClassId=cl.id";
Session session = getHibernateTemplate().getSessionFactory().openSession();
conn = session.connection();
try {
pstm = conn.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
MyRecipDetail recipe = new MyRecipDetail();
recipe.setDrugName(rs.getString("drugName"));
recipe.setAmount(rs.getInt("amount"));
recipe.setUnit(rs.getString("unit"));
recipe.setClassName(rs.getString("className"));
list.add(recipe);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public boolean delRecipeDedtail(int id) {
boolean i = false;
Connection conn = null;
PreparedStatement pstm = null;
String sql = "delete from recipedetailinfo where recipeid="+id;
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;
}
return i;
}
public static RecipedetailinfoDAO getFromApplicationContext(
ApplicationContext ctx) {
return (RecipedetailinfoDAO) ctx.getBean("RecipedetailinfoDAO");
}
public List<Recipedetailinfo> findByDrugId(int id) {
List<Recipedetailinfo> list = new ArrayList<Recipedetailinfo>();
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
String sql = "select * from recipedetailinfo where drugid="+id;
Session session = getHibernateTemplate().getSessionFactory().openSession().getSessionFactory().openSession();
conn = session.connection();
try {
pstm = conn.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
Recipedetailinfo re = new Recipedetailinfo();
re.setId(rs.getInt("id"));
list.add(re);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
rs=null;
pstm = null;
conn = null;
}
return list;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -