Example usage for org.springframework.dao DataAccessException toString

List of usage examples for org.springframework.dao DataAccessException toString

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.sakaiproject.tool.tasklist.impl.TaskListManagerJdbcImpl.java

public boolean saveTask(Task t) {
    try {//from ww  w  .j  ava 2s.c  o  m
        if (t.getId() == null) {
            // if the id is not set the we are inserting a new record
            getJdbcTemplate().update(TASK_INSERT_QUERY,
                    new Object[] { t.getOwner(), t.getSiteId(), t.getCreationDate(), t.getTask() },
                    new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.CLOB });
        } else {
            getJdbcTemplate().update(TASK_UPDATE_QUERY,
                    new Object[] { t.getOwner(), t.getSiteId(), t.getTask(), t.getId() },
                    new int[] { Types.VARCHAR, Types.VARCHAR, Types.CLOB, Types.BIGINT });
        }
    } catch (DataAccessException e) {
        log.error("Exception: Could not add task:" + e.toString());
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:org.sakaiproject.tool.tasklist.impl.TaskListManagerJdbcImpl.java

public boolean deleteTask(Task t) {
    try {//from  w  ww  . j av  a 2 s .c  o  m
        getJdbcTemplate().update(TASK_DELETE_QUERY, new Object[] { t.getId() }, new int[] { Types.BIGINT });
    } catch (DataAccessException e) {
        log.error("Exception: Could not delete task:" + t.getId() + ":" + e.toString());
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.trenako.web.controllers.RollingStocksController.java

@RequestMapping(method = RequestMethod.PUT)
public String save(@ModelAttribute @Valid RollingStockForm form, BindingResult bindingResult, ModelMap model,
        RedirectAttributes redirectAtts) {

    RollingStock rs = form.buildRollingStock(valuesService, secContext, new Date());

    if (bindingResult.hasErrors()) {
        model.addAttribute(newForm(rs, valuesService));
        return "rollingstock/edit";
    }/*from w  w  w  .  jav a 2  s  . com*/

    try {
        service.save(rs);

        redirectAtts.addFlashAttribute("message", ROLLING_STOCK_SAVED_MSG);
        redirectAtts.addAttribute("slug", rs.getSlug());
        return "redirect:/rollingstocks/{slug}";
    } catch (DataAccessException dataEx) {
        log.error(dataEx.toString());
        model.addAttribute(newForm(rs, valuesService));
        model.addAttribute("message", ROLLING_STOCK_DATABASE_ERROR_MSG);
        return "rollingstock/edit";
    }
}

From source file:com.trenako.web.controllers.RollingStocksController.java

@RequestMapping(method = RequestMethod.POST)
public String create(@ModelAttribute @Valid RollingStockForm form, BindingResult bindingResult, ModelMap model,
        RedirectAttributes redirectAtts) {

    MultipartFile file = form.getFile();
    RollingStock rs = form.buildRollingStock(valuesService, secContext, new Date());

    if (bindingResult.hasErrors()) {
        model.addAttribute(rejectForm(form, valuesService));
        return "rollingstock/new";
    }//  w  w w . j  a v a 2s . c  o m

    try {
        service.createNew(rs);
        if (!file.isEmpty()) {
            imgService.saveImageWithThumb(UploadRequest.create(rs, file), 100);
        }

        redirectAtts.addFlashAttribute("message", ROLLING_STOCK_CREATED_MSG);
        redirectAtts.addAttribute("slug", rs.getSlug());
        return "redirect:/rollingstocks/{slug}";
    } catch (DuplicateKeyException duplEx) {
        log.error(duplEx.toString());
        model.addAttribute(newForm(rs, valuesService));
        model.addAttribute("message", ROLLING_STOCK_DUPLICATED_VALUE_MSG);
        return "rollingstock/new";
    } catch (DataAccessException dataEx) {
        log.error(dataEx.toString());
        model.addAttribute(newForm(rs, valuesService));
        model.addAttribute("message", ROLLING_STOCK_DATABASE_ERROR_MSG);
        return "rollingstock/new";
    }
}

From source file:com.virtusa.akura.common.controller.ManageGradeController.java

/**
 * Delete a grade and classes belongs to.
 * /*from  ww  w .j ava 2 s . c o 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;
}

From source file:com.virtusa.akura.student.controller.FaithLifeRatingController.java

/**
 * Delete FaithLifeRating details./*from   www .  j  a v  a  2 s  . c  o m*/
 * 
 * @param faithLifeRating - FaithLifeRating object
 * @param request - HttpServletRequest
 * @param session - HttpSession
 * @param model - ModelMap
 * @return name of the view which is redirected to.
 * @throws AkuraAppException - if error occurs when deleting a FaithLifeRating instance.
 */
@RequestMapping(value = DELETE_FAITHLIFE_HTM, method = RequestMethod.POST)
public String deleteFaithLifeRating(@ModelAttribute(MODEL_ATT_FAITH_LIFE) FaithLifeRating faithLifeRating,
        HttpServletRequest request, HttpSession session, ModelMap model) throws AkuraAppException {

    try {
        studentService.deleteFaithLifeRating(faithLifeRating.getFaithLifeRatingId());
    } catch (DataAccessException ex) {
        LOG.error(ERROR_OCCURED_WHILE_DELETING_FAITH_LIFE_RATING_OBJECT + ex.toString());
        throw new AkuraAppException(AkuraWebConstant.HIBERNATE_INVALID_DEL_OPERATION, ex);
    } catch (AkuraAppException ex) {
        LOG.error(ERROR_OCCURED_WHILE_DELETING_FAITH_LIFE_RATING_OBJECT + ex.toString());
        throw new AkuraAppException(AkuraWebConstant.HIBERNATE_INVALID_DEL_OPERATION, ex);
    }

    return populateData(request, session, model);
}

From source file:org.sakaiproject.poll.service.impl.PollListManagerImpl.java

public void deleteOption(Option option) {
    try {//  w w w.j a  v  a  2s. co m
        dao.delete(option);
    } catch (DataAccessException e) {
        log.error("Hibernate could not delete: " + e.toString());
        e.printStackTrace();
        return;
    }
    log.info("Option id " + option.getId() + " deleted");
}

From source file:org.sakaiproject.poll.service.impl.PollListManagerImpl.java

public boolean saveOption(Option t) {
    if (t.getUUId() == null || t.getUUId().trim().length() == 0) {
        t.setUUId(UUID.randomUUID().toString());
    }//from  ww w . j a va2 s  . c  o m

    try {
        dao.save(t);
    } catch (DataAccessException e) {
        log.error("Hibernate could not save: " + e.toString());
        e.printStackTrace();
        return false;
    }
    log.info("Option  " + t.toString() + "successfuly saved");
    return true;
}

From source file:org.sakaiproject.poll.service.impl.PollListManagerImpl.java

public boolean savePoll(Poll t) throws SecurityException, IllegalArgumentException {
    boolean newPoll = false;

    if (t == null || t.getText() == null || t.getSiteId() == null || t.getVoteOpen() == null
            || t.getVoteClose() == null) {
        throw new IllegalArgumentException("you must supply a question, siteId & open and close dates");
    }/*w  ww  .  j  a  v  a  2s. co m*/

    if (!externalLogic.isUserAdmin() && !externalLogic.isAllowedInLocation(PollListManager.PERMISSION_ADD,
            externalLogic.getSiteRefFromId(t.getSiteId()), externalLogic.getCurrentuserReference())) {
        throw new SecurityException();
    }

    if (t.getId() == null) {
        newPoll = true;
        t.setId(idManager.createUuid());
    }

    try {
        dao.save(t);

    } catch (DataAccessException e) {
        log.error("Hibernate could not save: " + e.toString());
        e.printStackTrace();
        return false;
    }
    log.debug(" Poll  " + t.toString() + "successfuly saved");
    externalLogic.registerStatement(t.getText(), newPoll);
    if (newPoll)
        externalLogic.postEvent("poll.add", "poll/site/" + t.getSiteId() + "/poll/" + t.getId(), true);
    else
        externalLogic.postEvent("poll.update", "poll/site/" + t.getSiteId() + " /poll/" + t.getId(), true);

    return true;
}

From source file:com.virtusa.akura.student.controller.CoCurricularActivityController.java

/**
 * Delete Achievement details./*from  w w  w  . ja v a2s .  c  o  m*/
 * 
 * @param request - HttpServletRequest
 * @param session - HttpSession
 * @param model - ModelMap
 * @return name of the view which is redirected to.
 * @throws AkuraAppException - if error occurs when deleting a Achievement instance.
 */
@RequestMapping(value = ACTION_FOR_DELETE_ACHIEVEMENT, method = RequestMethod.POST)
public String deleteAchievement(HttpServletRequest request, HttpSession session, ModelMap model)
        throws AkuraAppException {

    int achievementId = Integer.parseInt(request.getParameter(SELECTED_ACHIEVEMENT_ID));
    try {
        studentService.deleteAchievement(achievementId);
    } catch (DataAccessException ex) {
        LOG.error("ManageCoCurricularController - error occured while deleting achievement " + "-->"
                + ex.toString());
        throw new AkuraAppException(AkuraWebConstant.HIBERNATE_INVALID_DEL_OPERATION, ex);
    } catch (AkuraAppException ex) {
        LOG.error("ManageCoCurricularController - error occured while deleting achievement object " + "-->"
                + ex.toString());
        throw new AkuraAppException(AkuraWebConstant.HIBERNATE_INVALID_DEL_OPERATION, ex);
    }

    return populateStudentCoCurricularData(request, session, model);
}