List of usage examples for org.springframework.dao DataAccessException getCause
public synchronized Throwable getCause()
From source file:eu.databata.engine.util.PropagationUtils.java
public static void handleDataAccessException(DataAccessException e, String sql, SQLExceptionHandler handler) { if (!(e.getCause() instanceof SQLException) || !handler.isHandled((SQLException) e.getCause(), sql, null, null)) { throw e;/*from w w w .jav a2s . c o m*/ } }
From source file:com.pontecultural.flashcards.WebServicesController.java
/** * Fetch cards for deck. /*from w w w . java 2s.com*/ */ @RequestMapping(value = "/deckId/{deckId}/cards.json", method = RequestMethod.GET) public String getCards(HttpServletRequest req, @PathVariable Integer deckId, Model model) { logger.info("get cards for deck: " + deckId); try { model.addAttribute("flashcards", jdbcFlashcardsDao.fetchCardsByDeck(deckId)); } catch (DataAccessException e) { SQLException sqle = (SQLException) e.getCause(); logger.error("Error code: " + sqle.getErrorCode()); logger.error("SQL state: " + sqle.getSQLState()); logger.error("Error msg: " + sqle.getMessage()); model.addAttribute("flashcards", null); } return "flashcardstemplate"; // was "observationtemplate" - do I need to configure this someone? }
From source file:org.springextensions.neodatis.NeoDatisUtilsTest.java
@Test public void testConvertException() { DataAccessException converted = NeoDatisUtils.translateException(new RuntimeException()); Assert.assertNotNull(converted);//from w w w . java 2s . co m Assert.assertNotNull(converted.getCause()); Assert.assertEquals(converted.getCause().getClass(), RuntimeException.class); }
From source file:org.onesun.atomator.dao.OAuthResultDAOImpl.java
@Override public void append(String user, OAuthResult entry, boolean update) { String query = "INSERT INTO " + AUTH_ENTRY_TABLE + " (identity, user_id, channel_name, access_key, access_secret, verification_code) " + " VALUES (?,?,?,?,?,?)"; /**/*from www . j av a 2 s.co m*/ * Specify the values */ try { Configuration.getJdbcTemplate().update(query, new Object[] { entry.getIdentity(), user, entry.getChannelName(), entry.getAccessKey(), entry.getAccessSecret(), entry.getVerificationCode() }); logger.info("Added Authentication Results for " + entry.getChannelName()); } catch (DataAccessException e1) { if (e1.getCause().getMessage().contains( "integrity constraint violation: unique constraint or index violation; SYS_PK_10029")) { if (update == true) { query = "UPDATE " + AUTH_ENTRY_TABLE + " SET access_key=?, access_secret=?, verification_code=? WHERE identity=?"; try { Configuration.getJdbcTemplate().update(query, new Object[] { entry.getAccessKey(), entry.getAccessSecret(), entry.getVerificationCode(), entry.getIdentity() }); logger.info("Updated Authentication Results for " + entry.getChannelName()); } catch (DataAccessException e2) { logger.error("Exception while updating authentication results for " + entry.getChannelName() + " " + e2.getMessage()); } } } } }
From source file:be.bittich.quote.controller.impl.DefaultExceptionHandler.java
@RequestMapping(produces = APPLICATION_JSON) @ExceptionHandler(DataAccessException.class) @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) public @ResponseBody Map<String, Object> handleDataAccessException(DataAccessException ex) throws IOException { Map<String, Object> map = newHashMap(); map.put("error", "Data Error"); map.put("cause", ex.getCause().getMessage()); return map;/*from w ww . j av a 2 s. co m*/ }
From source file:com.pontecultural.flashcards.ReadSpreadsheet.java
public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equals(TAG_FOR_TEXT)) { if (inSrcLang == true) { inSrcLang = false;//www . j a va2 s. co m srcColumnSetP = true; } else if (inDestLang == true) { inDestLang = false; srcColumnSetP = false; } } else if (qName.equals(TAG_FOR_CARD)) { if (!(srcPhrase.isEmpty() && destPhrase.isEmpty())) { if (inDescription) { logger.debug("deck name: " + deckName + " - " + destPhrase + "\n"); Deck d = new Deck(deckName, destPhrase); try { this.deckId = this.jdbcFlashcardsDao.insert(d); } catch (DataAccessException e) { SQLException sqle = (SQLException) e.getCause(); logger.error(e.getCause().getMessage()); logger.error("Error code: " + sqle.getErrorCode()); logger.error("SQL state: " + sqle.getSQLState()); } testCountDecks++; } else { Card c = new Card(srcPhrase, destPhrase, deckId); try { this.jdbcFlashcardsDao.insert(c); } catch (DataAccessException e) { SQLException sqle = (SQLException) e.getCause(); logger.error(e.getCause().getMessage()); logger.error("Error code: " + sqle.getErrorCode()); logger.error("SQL state: " + sqle.getSQLState()); } catch (Exception e) { logger.error("hmm..what happened here: " + e.getMessage()); } logger.debug("card completed"); logger.debug("\t en: " + srcPhrase); logger.debug("\t pt: " + destPhrase); testCountCards++; } this.initializeCardState(); } } else if (qName.equals(TAG_FOR_DECK)) { logger.debug("deck completed."); } }
From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCPhotoDAO.java
@Override public List<Photo> readPhotosByJourney(Journey journey) throws DAOException { if (journey == null) throw new IllegalArgumentException(); if (journey.getId() == null) throw new IllegalArgumentException(); logger.debug("retrieving photos for journey {}", journey); try {//from w w w .j ava 2 s . c o m List<Photo> photos = jdbcTemplate.query(READ_JOURNEY_STATEMENT, new PhotoRowMapper(), journey.getId()); logger.debug("Successfully retrieved photos"); return photos; } catch (DataAccessException ex) { logger.error("Failed to read photos from given journey", ex); throw new DAOException("Failed to read photos from given journey", ex); } catch (ValidationException.Unchecked | DAOException.Unchecked ex) { logger.error("Failed to read photos from given journey", ex); throw new DAOException("Failed to read photos from given journey", ex.getCause()); } }
From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCPhotoDAO.java
@Override public List<Photo> readPhotosBetween(LocalDateTime start, LocalDateTime end) throws DAOException { if (start == null) throw new IllegalArgumentException(); if (end == null) throw new IllegalArgumentException(); logger.debug("retrieving photos between {} and {}", start, end); try {//from ww w .ja v a 2 s . c om List<Photo> photos = jdbcTemplate.query(READ_INTERVAL_STATEMENT, new PhotoRowMapper(), Timestamp.valueOf(start), Timestamp.valueOf(end)); logger.debug("Successfully retrieved photos"); return photos; } catch (DataAccessException ex) { logger.error("Failed to read photos from given interval", ex); throw new DAOException("Failed to read photos from given interval", ex); } catch (ValidationException.Unchecked | DAOException.Unchecked ex) { logger.error("Failed to read photos from given interval", ex); throw new DAOException("Failed to read photos from given interval", ex.getCause()); } }
From source file:com.gst.portfolio.savings.service.SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override//from ww w.j ava2s .c o m public CommandProcessingResult submitApplication(final JsonCommand command) { try { this.savingsAccountDataValidator.validateForSubmit(command.json()); final AppUser submittedBy = this.context.authenticatedUser(); final SavingsAccount account = this.savingAccountAssembler.assembleFrom(command, submittedBy); this.savingAccountRepository.save(account); generateAccountNumber(account); final Long savingsId = account.getId(); if (command.parameterExists(SavingsApiConstants.datatables)) { this.entityDatatableChecksWritePlatformService.saveDatatables( StatusEnum.CREATE.getCode().longValue(), EntityTables.SAVING.getName(), savingsId, account.productId(), command.arrayOfParameterNamed(SavingsApiConstants.datatables)); } this.entityDatatableChecksWritePlatformService.runTheCheckForProduct(savingsId, EntityTables.SAVING.getName(), StatusEnum.CREATE.getCode().longValue(), EntityTables.SAVING.getForeignKeyColumnNameOnDatatable(), account.productId()); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .build(); } catch (final DataAccessException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.virtusa.akura.common.controller.ManageGradeController.java
/** * Delete a grade and classes belongs to. * /*from w w w .j av a2 s . co m*/ * @param request {@link HttpServletRequest} * @param model {@link ModelMap} * @return name of the view which is redirected to. * @throws AkuraAppException - throw this. */ @RequestMapping(value = REQ_MAP_VALUE_DELETE, method = RequestMethod.POST) public String deleteGrade(HttpServletRequest request, ModelMap model) throws AkuraAppException { String description = request.getParameter(REQ_SELECTEDGRADE); Grade grade = commonService.getGradeByGradeName(description); List<GradeSubject> gradeSubjectList = commonService.getGradeSubjectIdListByGrade(grade.getGradeId()); List<ClassGrade> classGrades = commonService.getClassGradeListByGrade(grade); List<Integer> classGradeIds = new ArrayList<Integer>(); for (ClassGrade classGrade : classGrades) { classGradeIds.add(classGrade.getClassGradeId()); } try { if ((gradeSubjectList == null || gradeSubjectList.isEmpty())) { commonService.deleteClassGradeList(classGrades); commonService.deleteGrade(grade); } else { String message = new ErrorMsgLoader().getErrorMessage(ERROR_MSG_DELETE); Grade newGrade = new Grade(); model.addAttribute(MODEL_ATT_GRADE, newGrade); model.addAttribute(MESSAGE, message); return VIEW_GET_MANAGE_GRADE; } } catch (DataAccessException ex) { LOG.error("ManageGradeController - error occured while deleting list of class grade " + classGrades + "-->" + ex.toString()); throw new AkuraAppException(AkuraWebConstant.HIBERNATE_INVALID_DEL_OPERATION, ex); } catch (AkuraAppException ex) { if (ex.getCause() instanceof DataIntegrityViolationException) { String message = new ErrorMsgLoader().getErrorMessage(ERROR_MSG_DELETE); Grade newGrade = new Grade(); model.addAttribute(MODEL_ATT_GRADE, newGrade); model.addAttribute(MESSAGE, message); return VIEW_GET_MANAGE_GRADE; } else { LOG.error("ManageGradeController - error occured while deleting grade object " + grade + "-->" + ex.toString()); throw new AkuraAppException(AkuraWebConstant.HIBERNATE_INVALID_DEL_OPERATION, ex); } } return VIEW_POST_MANAGE_GRADE; }