=====================dao================================
package com.jb.xs.Dao.impl;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Service;
import com.jb.entity.PubComp;
import com.jb.entity.PubUser;
import com.jb.xs.Dao.TestCaseDao;
@Service
public class TestCaseDaoImpl implements TestCaseDao {
private EntityManager em = null;
@Override
//更新的方法
public void update(PubComp pc) {
em.merge(pc);//按对象更新
//createQuery不能执行添加(insert)的语句,具体原因还没不清楚
em.createQuery(" update PubComp set aname='22222' where aguid='0.5689057'").executeUpdate();//按语句更新
//注意createNativeQuery可以执行增删改查的语句
em.createNativeQuery(
"insert into sysbilllock(aguid,mtbl,guid_tbl,guid_locker,remark) values('"
+ JTool.getGuid() + "','" + mtbl + "','" + rowguid + "','" +
lockerguid + "','')") .executeUpdate();
}
@Override
public Object getMaxLvl() {
// em.find("select p from PubComp");
return em.createQuery("select max(p.status) from PubComp p ");
}
@PersistenceContext
public void setEntityManager(EntityManager em) {
this.em = em;
}
@Override
public void delete(PubComp pc) {
Object obj = em.merge(pc);
em.remove(obj);// 删除的方法
}
@Override
public void delete(PubUser u) {
em.remove(u);// 删除的方法
}
@Override
public List<PubComp> getPubComp(String sql) {
// em.find("select p from PubComp");
return (List<PubComp>) em.createQuery(sql)
.getResultList();
}
@Override
public void save(PubComp pc) {
em.persist(pc);
}
@Override
public void save(PubUser u) {
em.persist(u);
}
@Override
public void update(String jql) {
//em.merge(pc);
em.createQuery(" update PubComp set aname='ssdff' where aguid='0.5689057'").executeUpdate();
em.createQuery(" insert into PubComp(aguid,acode) value ('主键','编号') ").executeUpdate();
}
}