TypeDAO.java.svn-base
资源名称:cindyblog.rar [点击查看]
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:1k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.appspot.cindyblog.dao;
- import javax.persistence.EntityManager;
- import javax.persistence.Query;
- import com.appspot.cindyblog.pojo.TypeBean;
- public class TypeDAO extends BaseDAO{
- public boolean addTypeCount(String typeName,EntityManager em) {
- boolean b = false;
- try {
- String queryString = "SELECT FROM "+TypeBean.class.getName()+" WHERE name =:typeName";
- Query query = em.createQuery(queryString);
- query.setParameter("typeName", typeName);
- TypeBean type = (TypeBean) query.getSingleResult();
- int count = type.getTypeCount()+1;
- type.setTypeCount(count);
- b = true;
- }catch(Exception ex){
- ex.printStackTrace();
- } finally {
- return b;
- }
- }
- public boolean updateType(TypeBean o,EntityManager em) {
- boolean b = false;
- try {
- TypeBean f = em.find(TypeBean.class, o.getId());
- f.setName(o.getName());
- f.setTypeCount(o.getTypeCount());
- b = true;
- }catch(Exception ex){
- ex.printStackTrace();
- } finally {
- em.flush();
- return b;
- }
- }
- }