BlogService.java
资源名称:cindyblog.rar [点击查看]
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:2k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.appspot.cindyblog.service;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.persistence.EntityManager;
- import org.json.JSONArray;
- import com.appspot.cindyblog.common.EMF;
- import com.appspot.cindyblog.pojo.TypeBean;
- import com.appspot.cindyblog.util.Counter;
- public class BlogService extends BaseService{
- public int getDisscussCount(Long value,EntityManager em){
- int count = -1;
- try{
- em = EMF.get().createEntityManager();
- discussDAO = getDiscussDAO();
- count = discussDAO.getDiscussCount(em, value);
- }catch(Exception ex){
- ex.printStackTrace();
- }finally{
- discussDAO = null;
- return count;
- }
- }
- public String getType(EntityManager em) {
- String str= "";
- try{
- em = EMF.get().createEntityManager();
- typeDAO = getTypeDAO();
- List<TypeBean> list = (List<TypeBean>) typeDAO.getObjectList(TypeBean.class, em);
- JSONArray jsonArray = new JSONArray();
- if (list.isEmpty()) {
- str = "false";
- }else{
- int allCount = 0;
- Map<String,Object> map = null;
- Map<String,Integer> articleMap = new HashMap<String,Integer>();
- for(TypeBean type :list){
- map = new HashMap<String,Object>();
- map.put("name",type.getName());
- map.put("typeCount",type.getTypeCount());
- jsonArray.put(map);
- allCount+=type.getTypeCount();
- articleMap.put(type.getName(), type.getTypeCount());
- }
- map = new HashMap<String,Object>();
- map.put("name","All");
- map.put("typeCount", allCount);
- articleMap.put("All", allCount);
- Counter.setArticleCount(articleMap);
- jsonArray.put(map);
- str = jsonArray.toString();
- }
- }catch(Exception ex){
- ex.printStackTrace();
- }finally{
- typeDAO = null;
- return str;
- }
- }
- }