Exemplo n.º 1
0
 public ServiceResult<Page> findPage(Long id, boolean isIncreaseView) {
   ServiceResult<Page> result = new ServiceResult<Page>();
   Page page = null;
   PersistenceManager pm = null;
   try {
     pm = PMF.get().getPersistenceManager();
     page = pm.getObjectById(Page.class, id);
     if (page == null) {
       result.setOK(false);
       result.setMessage(Global.messages.getString("no_page_found"));
     } else {
       result.setMessage(Global.messages.getString("page_found"));
       result.setOK(true);
       result.setResult(page);
       if (isIncreaseView) {
         page.setPage_view(page.getPage_view() + 1);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     result.setMessage(Global.messages.getString("find_page_fail"));
   } finally {
     try {
       pm.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return result;
 }
Exemplo n.º 2
0
 public ServiceResult<Void> updatePage(Page editPage) {
   ServiceResult<Void> result = new ServiceResult<Void>();
   Page page = null;
   PersistenceManager pm = null;
   try {
     pm = PMF.get().getPersistenceManager();
     page = pm.getObjectById(Page.class, editPage.getId());
     if (page == null) {
       result.setOK(false);
       result.setMessage(Global.messages.getString("no_page_found"));
     } else {
       page.setContent(editPage.getContent());
       page.setDate_post(editPage.getDate_post());
       page.setLast_modified(editPage.getLast_modified());
       page.setLink_thumbnail(editPage.getLink_thumbnail());
       page.setName(editPage.getName());
       page.setPage_view(editPage.getPage_view());
       page.setSetCategoryKeys(editPage.getSetCategoryKeys());
       page.setSetProduct(editPage.getSetProduct());
       result.setOK(true);
       result.setMessage(Global.messages.getString("update_page_successfully"));
     }
   } catch (Exception e) {
     result.setMessage(Global.messages.getString("update_page_fail"));
     result.setOK(false);
     e.printStackTrace();
   } finally {
     try {
       pm.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return result;
 }