Пример #1
0
 @Override
 public long standbyCount() throws OperationalException {
   Session session = null;
   long count = 0;
   try {
     session = parkingSessionFactory.getSessionFactory().openSession();
     Criteria criteria = session.createCriteria(Notice.class);
     User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
     String role = user.getRole();
     criteria.add(Restrictions.eq("author", user));
     criteria.add(Restrictions.ne(STATUS, NoticeStatus.DELETED.name()));
     criteria.setProjection(Projections.rowCount());
     count = (long) criteria.uniqueResult();
   } catch (Exception e) {
     LOGGER.error("unreadCount: error in unreadCount notfication", e);
     throw new OperationalException(
         HttpConstants.INTERNAL_SERVER_ERROR,
         ResponseConstants.ERROR_FETCHING_FROM_DB,
         HttpStatus.INTERNAL_SERVER_ERROR);
   } finally {
     if (session != null) {
       session.close();
     }
   }
   return count;
 }
Пример #2
0
  @Override
  public Notice findById(int noticeId) throws OperationalException {
    Session session = null;
    Notice notice = null;
    try {
      session = parkingSessionFactory.getSessionFactory().openSession();
      session.beginTransaction();

      Criteria criteria = session.createCriteria(Notice.class);
      criteria.add(Restrictions.eq(NOTICEID, noticeId));
      criteria.add(Restrictions.ne(STATUS, NoticeStatus.DELETED.name()));
      criteria.setMaxResults(1);
      notice = (Notice) criteria.uniqueResult();
      return notice;
    } catch (Exception e) {
      LOGGER.error("findById: Exception ", e);
      throw new OperationalException(
          HttpConstants.INTERNAL_SERVER_ERROR,
          ResponseConstants.ERROR_FETCHING_FROM_DB,
          HttpStatus.INTERNAL_SERVER_ERROR);
    } finally {
      if (session != null) {
        session.close();
      }
    }
  }