Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Gerhardus du Toit
Added: Nov 18, 2020 9:16 AM
Modified: Nov 26, 2020 8:08 AM
Views: 9
Tags: no tags
  1. private void clearAll (long listId) {
  2.         String hql = "delete " + CategoryItem.class.getName() + " where categoryitemlist_id = :listId";
  3.         Query q = session.createQuery(hql).setParameter("listId", listId);
  4.         q.executeUpdate();
  5.     }
  6.  
  7.  
  8.  
  9.  
  10.  
  11.     @Override
  12.     public void removeAllListItems(long categoryItemListId) {
  13.         getHibernateTemplate().execute(session -> session.createNativeQuery("DELETE FROM ircm_categoryitem WHERE ircm_categoryitemlist_id = :categoryItemListId").setParameter("categoryItemListId", categoryItemListId).executeUpdate());
  14.         updateListNumItems(categoryItemListId);
  15.     }
  16.  
  17.  
  18.     session.createNativeQuery("UPDATE ircm_categoryitemlist SET ircm_categoryitemlist.num_items=:numItems WHERE ircm.ircm_categoryitemlist.id=:categoryItemListId")
  19.                     .setParameter("numItems", numItems)
  20.                     .setParameter("categoryItemListId", categoryItemListId)
  21.                     .executeUpdate();
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  @Override
  30.     public void archiveAllListItems(long categoryItemListId) {
  31.         getHibernateTemplate().execute(session -> session.createNativeQuery("UPDATE ircm_categoryitem SET ircm_categoryitem.archived=1 WHERE ircm_categoryitem.ircm_categoryitemlist_id=:categoryItemListId")
  32.                 .setParameter("categoryItemListId", categoryItemListId)
  33.                 .executeUpdate());
  34.        
  35.     }
  36.  
  37.     return getHibernateTemplate().execute(session -> {
  38.             Long numItems = (Long)(session.createNativeQuery(
  39.                     "SELECT COUNT(*) as count FROM ircm_categoryitem WHERE ircm_categoryitemlist_id = :categoryItemListId")
  40.                     .setParameter("categoryItemListId", categoryItemListId)
  41.                     .addScalar("count", LongType.INSTANCE)
  42.                     .uniqueResult());
  43.             session.createNativeQuery("UPDATE ircm_categoryitemlist SET ircm_categoryitemlist.num_items=:numItems WHERE ircm.ircm_categoryitemlist.id=:categoryItemListId")
  44.                     .setParameter("numItems", numItems)
  45.                     .setParameter("categoryItemListId", categoryItemListId)
  46.                     .executeUpdate();
  47.             return numItems;
  48.         });
  49.