package sunyang.functions.dao; import java.util.List; import javax.persistence.*; import sunyang.functions.domain.Function; import sunyang.persistence.EntityManagerHelper; public class FunctionDAO implements IFunctionDAO { // 声明静态常量 public static final String URL = "url"; public static final String FUNCTIONNAME = "functionname"; // 得到实体管理器 private EntityManager getEntityManager() { return EntityManagerHelper.getEntityManager(); } // 新增数据 public void save(Function entity) { EntityManagerHelper.beginTransaction(); try { getEntityManager().persist(entity); EntityManagerHelper.commit(); } catch (RuntimeException re) { EntityManagerHelper.rollback(); throw re; } } // 删除数据 public void delete(Function entity) { EntityManagerHelper.beginTransaction(); try { entity = getEntityManager().getReference(Function.class, entity.getId()); getEntityManager().remove(entity); EntityManagerHelper.commit(); } catch (RuntimeException re) { EntityManagerHelper.rollback(); throw re; } } // 修改数据 public Function update(Function entity) { EntityManagerHelper.beginTransaction(); try { Function result = getEntityManager().merge(entity); EntityManagerHelper.commit(); return result; } catch (RuntimeException re) { EntityManagerHelper.rollback(); throw re; } } // 通过id查询数据 public Function findById(Integer id) { try { Function instance = getEntityManager().find(Function.class, id); return instance; } catch (RuntimeException re) { throw re; } } // 通过表中一个字段查询数据 @SuppressWarnings("unchecked") public List<Function> findByProperty(String propertyName, final Object value) { try { final String queryString = "select model from Function model where model." + propertyName + "= :propertyValue"; Query query = getEntityManager().createQuery(queryString).setHint( "toplink.refresh", true); query.setParameter("propertyValue", value); return query.getResultList(); } catch (RuntimeException re) { throw re; } } // 查询所有数据 @SuppressWarnings("unchecked") public List<Function> findAll() { try { final String queryString = "select model from Function model"; Query query = getEntityManager().createQuery(queryString).setHint( "toplink.refresh", true); return query.getResultList(); } catch (RuntimeException re) { throw re; } } }

hesu2020 LV1
2023年3月21日
微信网友_6044559891320832 LV2
2022年7月14日
2022982038 LV1
2022年1月27日
lizhiquan_119 LV2
2020年9月4日
281273445 LV3
2020年6月18日
qijie_nm LV1
2020年5月29日
luojiaqi LV1
2019年11月9日
11ssjhw LV1
2019年10月16日
A1231Q LV1
2019年6月18日
122582456 LV1
2019年6月17日

xianyu091012 LV5
2024年12月26日
WDWDWD123 LV1
2024年12月24日
040313 LV1
2024年10月26日
forkchen
2024年7月25日
暂无贡献等级
mxkyma
2024年5月13日
暂无贡献等级
sunrandong LV4
2024年4月29日
操作者
2024年4月12日
暂无贡献等级
朱俪的邮件及存储 LV8
2024年3月11日
故里逢春 LV2
2023年12月25日
微信网友_6714345438400512
2023年10月30日
暂无贡献等级