Example usage for org.springframework.dao EmptyResultDataAccessException getClass

List of usage examples for org.springframework.dao EmptyResultDataAccessException getClass

Introduction

In this page you can find the example usage for org.springframework.dao EmptyResultDataAccessException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.mxhero.engine.plugin.attachmentlink.fileserver.servlet.DownloadAll.java

public void doAction(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ContentService service = null;//w ww . j  a va 2 s . c  om
    Long idToSearch = null;
    String id = request.getParameter("id");
    String recipient = request.getParameter("recipient");
    MDC.put("message", id);
    List<ContentDTO> contents = null;
    try {
        if (StringUtils.isEmpty(id)) {
            log.debug("Error. No params in URL present. Forwarding to error URL page");
            request.getRequestDispatcher("/errorParams.jsp").forward(request, response);
        } else {
            ApplicationContext context = WebApplicationContextUtils
                    .getWebApplicationContext(getServletContext());
            StandardPBEStringEncryptor encryptor = (StandardPBEStringEncryptor) context.getBean("encryptor");
            String decrypt = encryptor.decrypt(id);
            idToSearch = Long.valueOf(decrypt);
            log.debug("Trying dowload all files for messageId " + idToSearch);
            service = context.getBean(ContentService.class);
            contents = service.getContentList(idToSearch, recipient);
            if (contents == null || contents.size() < 1) {
                throw new EmptyResultDataAccessException(1);
            }
            // Set the content type based to zip
            response.setContentType("Content-type: text/zip");
            response.setHeader("Content-Disposition", "attachment; filename=allFiles.zip");

            ServletOutputStream out = response.getOutputStream();
            ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(out));
            Set<String> addedFiles = new HashSet<String>();

            for (ContentDTO content : contents) {
                boolean alreadyThere = false;
                for (String addedFile : addedFiles) {
                    if (addedFile.equalsIgnoreCase(content.getFileName())) {
                        alreadyThere = true;
                        break;
                    }
                }
                if (alreadyThere) {
                    continue;
                }
                addedFiles.add(content.getFileName());
                log.debug("Adding file " + content.getFileName());
                zos.putNextEntry(new ZipEntry(content.getFileName()));

                // Get the file
                InputStream fis = null;
                try {
                    fis = content.getInputStream();
                } catch (FileNotFoundException fnfe) {
                    // If the file does not exists, write an error entry instead of
                    // file
                    // contents
                    zos.write(("ERROR: Could not find file " + content.getFileName()).getBytes());
                    zos.closeEntry();
                    log.warn("Could not find file " + content.getPath());
                    continue;
                }

                BufferedInputStream fif = new BufferedInputStream(fis);

                // Write the contents of the file
                int data = 0;
                while ((data = fif.read()) != -1) {
                    zos.write(data);
                }
                fif.close();

                zos.closeEntry();
                log.debug("Finished adding file " + content.getFileName());
            }

            zos.close();

            for (ContentDTO content : contents) {
                service.successContent(content.getIdMessageAttach());
            }

        }
    } catch (EmptyResultDataAccessException e) {
        log.debug("Content not more available. Forwarding to not available page");
        request.getRequestDispatcher("/contentNotAvailable.jsp").forward(request, response);
    } catch (Exception e) {
        if (contents != null) {
            for (ContentDTO content : contents) {
                try {
                    service.failDownload(content.getIdMessageAttach());
                } catch (Exception e2) {
                }
            }
        }
        log.error("Exception: " + e.getClass().getName());
        log.error("Message Exception: " + e.getMessage());
        log.debug("Error General. Forwarding to page error general");
        request.getRequestDispatcher("/error.jsp").forward(request, response);
    } finally {
        MDC.put("message", id);
    }
}

From source file:org.mxhero.engine.plugin.attachmentlink.fileserver.servlet.Unsubscribe.java

private void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ContentService service = null;/*from www  . j  a va  2  s.  c  o m*/
    Long idToSearch = null;
    String id = req.getParameter("id");
    MDC.put("message", id);
    try {
        if (StringUtils.isEmpty(id)) {
            log.debug("Error. No params in URL present. Forwarding to error URL page");
            req.getRequestDispatcher("/errorParams.jsp").forward(req, resp);
        } else {
            ApplicationContext context = WebApplicationContextUtils
                    .getWebApplicationContext(getServletContext());
            StandardPBEStringEncryptor encryptor = (StandardPBEStringEncryptor) context.getBean("encryptor");
            String decrypt = encryptor.decrypt(id);
            idToSearch = Long.valueOf(decrypt);
            log.debug("Trying update files for messageId " + idToSearch);
            service = context.getBean(ContentService.class);
            service.unsubscribe(idToSearch);
            req.getRequestDispatcher("/unsubscribe.jsp").forward(req, resp);
        }
    } catch (EmptyResultDataAccessException e) {
        log.debug("Content not more available. Forwarding to not available page");
        req.getRequestDispatcher("/contentNotAvailable.jsp").forward(req, resp);
    } catch (Exception e) {
        log.error("Exception: " + e.getClass().getName());
        log.error("Message Exception: " + e.getMessage());
        log.debug("Error General. Forwarding to page error general");
        req.getRequestDispatcher("/error.jsp").forward(req, resp);
    } finally {
        MDC.put("message", id);
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public List<CalendarItem> getCalendarItems(RepeatingCalendarItem repeatingEvent) {
    if (log.isDebugEnabled()) {
        log.debug("getInstancesOfRepeatingEvents(" + repeatingEvent + ")");
    }/* w  w w .j a va  2s. com*/
    String sql = getStatement("select.CalendarItems.by.repeatingEvent");
    Object[] params = new Object[] { repeatingEvent.getId() };

    try {
        return (List<CalendarItem>) getJdbcTemplate().query(sql, params, new CalendarItemMapper());
    } catch (EmptyResultDataAccessException ex) {
        log.debug("getInstancesOfRepeatingEvents: Empty result executing query: " + ex.getClass() + ":"
                + ex.getMessage());
        return null;
    } catch (DataAccessException ex) {
        log.warn("getInstancesOfRepeatingEvents: Error executing query: " + ex.getClass() + ":"
                + ex.getMessage());
        return new ArrayList<CalendarItem>();
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public SourceType getSourceType(String sourceTypeName) {
    if (log.isDebugEnabled()) {
        log.debug("getSourceType( " + sourceTypeName + ")");
    }//from www. j ava  2s.c  om

    try {
        return (SourceType) getJdbcTemplate().queryForObject(getStatement("select.SourceType.by.identifier"),
                new Object[] { sourceTypeName }, new SourceTypeMapper());
    } catch (EmptyResultDataAccessException ex) {
        log.debug("getSourceType: Empty result executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    } catch (DataAccessException ex) {
        log.warn("getSourceType: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public CalendarItem getCalendarItem(long id) {
    if (log.isDebugEnabled()) {
        log.debug("getCalendarItem(" + id + ")");
    }//  ww  w  .j  a  va  2s.  co  m

    try {
        return (CalendarItem) getJdbcTemplate().queryForObject(getStatement("select.CalendarItem.by.id"),
                new Object[] { id }, new CalendarItemMapper());
    } catch (EmptyResultDataAccessException ex) {
        log.debug("getCalendarItem: Empty result executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    } catch (DataAccessException ex) {
        log.warn("getCalendarItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    }

}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public CalendarItem getCalendarItem(String entityReference, String calendarTimeLabelKey,
        Integer sequenceNumber) {
    if (log.isDebugEnabled()) {
        log.debug(//from   w ww.j a v  a2 s .  co m
                "getCalendarItem(" + entityReference + "," + calendarTimeLabelKey + "," + sequenceNumber + ")");
    }

    String sql = null;
    Object[] params = null;
    if (sequenceNumber == null) {
        sql = getStatement("select.CalendarItem.by.entityReference.calendarTimeLabelKey");
        params = new Object[] { entityReference, calendarTimeLabelKey };
    } else if (calendarTimeLabelKey == null) {
        sql = getStatement("select.CalendarItem.by.entityReference.sequenceNumber");
        params = new Object[] { entityReference, sequenceNumber };
    } else {
        sql = getStatement("select.CalendarItem.by.entityReference.calendarTimeLabelKey.sequenceNumber");
        params = new Object[] { entityReference, calendarTimeLabelKey, sequenceNumber };
    }

    try {
        return (CalendarItem) getJdbcTemplate().queryForObject(sql, params, new CalendarItemMapper());
    } catch (EmptyResultDataAccessException ex) {
        log.debug("getCalendarItem: Empty result executing query: " + ex.getClass() + ":" + ex.getMessage());
        // System.out.println("addCalendarItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    } catch (DataAccessException e) {
        log.warn("getCalendarItem: Error executing query: " + e.getClass() + ":" + e.getMessage());
        // System.out.println("addCalendarItem: Error executing query: " + e.getClass() + ":" + e.getMessage());
        return null;
    } catch (Exception e) {
        log.warn("addCalendarItem: Error executing query: " + e.getClass() + ":" + e.getMessage());
        // System.out.println("addCalendarItem: Error executing query: " + e.getClass() + ":" + e.getMessage());
        return null;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public List<CalendarItem> getCalendarItems(String entityReference) {
    if (log.isDebugEnabled()) {
        log.debug("getCalendarItems(" + entityReference + ")");
    }/*from ww  w  .  jav  a 2s .  c  om*/

    try {
        return (List<CalendarItem>) getJdbcTemplate().query(
                getStatement("select.CalendarItems.by.entityReference"), new Object[] { entityReference },
                new CalendarItemMapper());
    } catch (EmptyResultDataAccessException ex) {
        log.debug("getCalendarItems: Empty result executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    } catch (DataAccessException ex) {
        log.warn("getCalendarItems: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    }

}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public List<CalendarItem> getCalendarItems(String sakaiUserId, String contextId, boolean saved,
        boolean hidden) {
    if (log.isDebugEnabled()) {
        log.debug("getCalendarItems(" + sakaiUserId + "," + contextId + ")");
    }//from w  ww .  j a va 2  s.c  o  m
    String sql = null;
    Object[] params = null;
    if (contextId == null) {
        if (hidden) {
            sql = getStatement("select.CalendarItems.by.sakaiId.hidden");
        } else if (saved) {
            sql = getStatement("select.CalendarItems.by.sakaiId.sticky");
        } else {
            sql = getStatement("select.CalendarItems.by.sakaiId");
        }
        params = new Object[] { sakaiUserId };
    } else {
        if (hidden) {
            sql = getStatement("select.CalendarItems.by.sakaiId.contextId.hidden");
        } else if (saved) {
            sql = getStatement("select.CalendarItems.by.sakaiId.contextId.sticky");
        } else {
            sql = getStatement("select.CalendarItems.by.sakaiId.contextId");
        }
        params = new Object[] { sakaiUserId, contextId };
    }

    try {
        return (List<CalendarItem>) getJdbcTemplate().query(sql, params, new CalendarItemMapper());
    } catch (EmptyResultDataAccessException ex) {
        log.debug("getCalendarItems: Empty result executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    } catch (DataAccessException ex) {
        log.warn("getCalendarItems: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return new ArrayList<CalendarItem>();
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public List<CalendarItem> getCalendarItemsByContext(String contextId) {

    if (log.isDebugEnabled()) {
        log.debug("getCalendarItemsByContext(" + contextId + ")");
    }/*from   w  w  w. j  a v a2  s.  c  om*/
    String sql = null;
    Object[] params = null;
    if (contextId != null) {
        sql = getStatement("select.CalendarItems.by.contextId");
        params = new Object[] { contextId };
    }
    if (log.isDebugEnabled()) {
        log.debug("getCalendarItemsByContext(" + contextId + ") sql = " + sql);
    }
    // TODO: what do do if sql and/or params null ??
    try {
        return (List<CalendarItem>) getJdbcTemplate().query(sql, params, new CalendarItemMapper());
    } catch (EmptyResultDataAccessException ex) {
        log.debug("getCalendarItemsByContext: Empty result executing query: " + ex.getClass() + ":"
                + ex.getMessage());
        return null;
    } catch (DataAccessException ex) {
        log.warn("getCalendarItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return new ArrayList<CalendarItem>();
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public CalendarLink getCalendarLink(long calendarItemId, long personId) {
    if (log.isDebugEnabled()) {
        log.debug("getCalendarLink(" + calendarItemId + ", " + personId + ")");
    }/*from  ww w .ja v  a  2s.  com*/

    try {
        return (CalendarLink) getJdbcTemplate().queryForObject(
                getStatement("select.CalendarLink.by.calendarItemId.personId"),
                new Object[] { calendarItemId, personId }, new CalendarLinkMapper());
    } catch (EmptyResultDataAccessException ex) {
        log.debug("getCalendarLink: Empty result executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    } catch (DataAccessException ex) {
        log.warn("getCalendarLink: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return null;
    }
}