List of usage examples for org.springframework.dao DataAccessException getRootCause
@Nullable
public Throwable getRootCause()
From source file:io.github.benas.jql.shell.Shell.java
private static void process(String command) { if (!command.trim().isEmpty()) { try {/* w w w. j a va 2 s . co m*/ System.out.println(queryExecutor.execute(command, resultSetExtractor)); } catch (DataAccessException e) { System.err.println("Unable to execute query: " + command); System.err.println(e.getRootCause().getMessage()); } } }
From source file:org.itracker.web.actions.admin.workflow.EditWorkflowScriptAction.java
public ActionForward execute(ActionMapping mapping, final ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ActionMessages errors = new ActionMessages(); if (!LoginUtilities.hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) { return mapping.findForward("unauthorized"); }// w w w . j a v a 2 s . c om if (!isTokenValid(request)) { log.debug("Invalid request token while editing workflow script."); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.transaction")); saveErrors(request, errors); return mapping.findForward("listworkflow"); } resetToken(request); try { ConfigurationService configurationService = ServletContextUtils.getItrackerServices() .getConfigurationService(); WorkflowScript workflowScript = new WorkflowScript(); WorkflowScriptForm form = (WorkflowScriptForm) actionForm; workflowScript.setId(form.getId()); workflowScript.setName(form.getName()); workflowScript.setEvent(form.getEvent()); workflowScript.setScript(form.getScript()); workflowScript.setLanguage(WorkflowScript.ScriptLanguage.valueOf(form.getLanguage())); String action = form.getAction(); if ("create".equals(action)) { workflowScript = configurationService.createWorkflowScript(workflowScript); } else if ("update".equals(action)) { workflowScript = configurationService.updateWorkflowScript(workflowScript); } if (log.isDebugEnabled()) { log.debug("updated workflowscript was: " + workflowScript); } if (workflowScript == null) { throw new Exception("Error creating/updating workflow script."); } HttpSession session = request.getSession(true); session.removeAttribute(Constants.WORKFLOW_SCRIPT_KEY); request.setAttribute("action", action); saveToken(request); return new ActionForward(mapping.findForward("listworkflow").getPath() + "?id=" + workflowScript.getId() + "&action=update"); } catch (DataAccessException dae) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system.message", dae.getRootCause().getMessage(), "Data")); saveErrors(request, errors); return toInputForward(request, mapping); } catch (Exception e) { log.error("Exception processing form data", e); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system")); } if (!errors.isEmpty()) { saveErrors(request, errors); } return mapping.findForward("error"); }
From source file:net.jkratz.igdb.controller.advice.ErrorController.java
@RequestMapping(produces = "application/json") @ExceptionHandler(DataAccessException.class) @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) public @ResponseBody Map<String, Object> handleDataAccessException(DataAccessException ex) throws IOException { logger.error("Database Error", ex); Map<String, Object> map = Maps.newHashMap(); map.put("error", "Data Error"); map.put("message", ex.getMessage()); if (ex.getRootCause() != null) { map.put("cause", ex.getRootCause().getMessage()); }/*from www. j a v a 2 s .c o m*/ return map; }
From source file:com.bbm.common.aspect.ExceptionTransfer.java
/** * ? Exception ? ? ?? ?? ? ./*from w w w .j a v a 2 s . c o m*/ * @param thisJoinPoint joinPoint ? * @param exception ? Exception */ public void transfer(JoinPoint thisJoinPoint, Exception exception) throws Exception { log.debug("execute ExceptionTransfer.transfer "); Class clazz = thisJoinPoint.getTarget().getClass(); Signature signature = thisJoinPoint.getSignature(); Locale locale = LocaleContextHolder.getLocale(); /** * BizException ? ?? ? ?. * Exception ?? ? ?? Exception? ? ? ?. * ? . * ? ?? Handler ? ?. */ String servicename = ""; // String errorCode = ""; // ? String errorMessage = ""; // ? String classname = ""; // ?? int servicepos = clazz.getCanonicalName().lastIndexOf("."); // .? if (servicepos > 0) { String tempStr = clazz.getCanonicalName().substring(servicepos + 1); servicepos = tempStr.lastIndexOf("Impl"); // Impl? servicename = tempStr.substring(0, servicepos); } else { servicename = clazz.getCanonicalName(); } classname = exception.getClass().getName(); //EgovBizException ? ? if (exception instanceof EgovBizException) { log.debug("Exception case :: EgovBizException "); EgovBizException be = (EgovBizException) exception; getLog(clazz).error(be.getMessage(), be.getCause()); // Exception Handler ? ?? Package Exception . (runtime ? ExceptionHandlerService ) processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices); throw be; //RuntimeException ? ? ? DataAccessException ? ?? throw . } else if (exception instanceof RuntimeException) { log.debug("RuntimeException case :: RuntimeException "); RuntimeException be = (RuntimeException) exception; getLog(clazz).error(be.getMessage(), be.getCause()); // Exception Handler ? ?? Package Exception . processHandling(clazz, signature.getName(), exception, pm, exceptionHandlerServices); if (be instanceof DataAccessException) { /* log.debug("RuntimeException case :: DataAccessException "); DataAccessException sqlEx = (DataAccessException) be; throw sqlEx; */ log.debug("RuntimeException case :: DataAccessException "); DataAccessException dataEx = (DataAccessException) be; Throwable t = dataEx.getRootCause(); String exceptionname = t.getClass().getName(); if (exceptionname.equals("java.sql.SQLException")) { java.sql.SQLException sqlException = (java.sql.SQLException) t; errorCode = String.valueOf(sqlException.getErrorCode()); errorMessage = sqlException.getMessage(); } else if (exception instanceof org.springframework.jdbc.BadSqlGrammarException) { org.springframework.jdbc.BadSqlGrammarException sqlEx = (org.springframework.jdbc.BadSqlGrammarException) exception; errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode()); errorMessage = sqlEx.getSQLException().toString(); } else if (exception instanceof org.springframework.jdbc.UncategorizedSQLException) { org.springframework.jdbc.UncategorizedSQLException sqlEx = (org.springframework.jdbc.UncategorizedSQLException) exception; errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode()); errorMessage = sqlEx.getSQLException().toString(); } else if (exception instanceof org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) { org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException sqlEx = (org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException) exception; errorCode = String.valueOf(sqlEx.getActualRowsAffected()); errorMessage = sqlEx.getMessage().toString(); } else if (exception instanceof org.springframework.jdbc.SQLWarningException) { org.springframework.jdbc.SQLWarningException sqlEx = (org.springframework.jdbc.SQLWarningException) exception; errorCode = String.valueOf(sqlEx.SQLWarning().getErrorCode()); errorMessage = sqlEx.getMessage().toString(); } else if (exception instanceof org.springframework.jdbc.CannotGetJdbcConnectionException) { org.springframework.jdbc.CannotGetJdbcConnectionException sqlEx = (org.springframework.jdbc.CannotGetJdbcConnectionException) exception; errorCode = String.valueOf(sqlEx.getMessage()); errorMessage = sqlEx.getMessage().toString(); } else if (exception instanceof org.springframework.jdbc.InvalidResultSetAccessException) { org.springframework.jdbc.InvalidResultSetAccessException sqlEx = (org.springframework.jdbc.InvalidResultSetAccessException) exception; errorCode = String.valueOf(sqlEx.getSQLException().getErrorCode()); errorMessage = sqlEx.getSQLException().toString(); } else { if (exception instanceof java.lang.reflect.InvocationTargetException) { java.lang.reflect.InvocationTargetException ce = (java.lang.reflect.InvocationTargetException) exception; errorCode = ""; errorMessage = ce.getTargetException().getMessage(); //strErrorMessage = getValue(ce.getTargetException().toString(), ""); } } // , ?, ?, , String[] messages = new String[] { "DataAccessException", errorCode, errorMessage, servicename, signature.getName(), classname }; throw processException(clazz, "fail.common.msg", messages, exception, locale); } // , ?, ?, , errorMessage = exception.getMessage(); String[] messages = new String[] { "RuntimeException", errorCode, errorMessage, servicename, signature.getName(), classname }; throw processException(clazz, "fail.common.msg", messages, exception, locale); //throw be; // ? ? Exception (: ) :: ? ?. } else if (exception instanceof FdlException) { log.debug("FdlException case :: FdlException "); FdlException fe = (FdlException) exception; getLog(clazz).error(fe.getMessage(), fe.getCause()); errorMessage = exception.getMessage(); // , ?, ?, , String[] messages = new String[] { "FdlException", errorCode, errorMessage, servicename, signature.getName(), classname }; throw processException(clazz, "fail.common.msg", messages, exception, locale); //throw fe; } else { //? ? Exception ? BaseException (: fail.common.msg) ?. //:: ? ?. log.debug("case :: Exception "); getLog(clazz).error(exception.getMessage(), exception.getCause()); errorMessage = exception.getMessage(); // , ?, ?, , String[] messages = new String[] { "Exception", errorCode, errorMessage, servicename, signature.getName(), classname }; throw processException(clazz, "fail.common.msg", messages, exception, locale); } }