Java Code Examples for org.springframework.dao.DataAccessException#getMessage()

The following examples show how to use org.springframework.dao.DataAccessException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserDetailsAuthenticationProviderImpl.java    From spring-backend-boilerplate with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation of an abstract method defined in the base class. The
 * retrieveUser() method is called by authenticate() method of the base
 * class. The latter is called by the AuthenticationManager.
 */
@Override
protected final UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
		throws AuthenticationException {
	UserDetails details;
	try {
		details = this.getUserDetailsService().loadUserByUsername(username);
		authentication.setDetails(details);
	}
	catch (DataAccessException repositoryProblem) {
		throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem);
	}

	if (details == null) {
		throw new AuthenticationServiceException(
				"UserDetailsService returned null, which is an interface contract violation");
	}
	return details;
}
 
Example 2
Source File: TicketAuthenticationProvider.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Find tickets.
 * @param path The path.
 * @param key The key.
 * @return  The ticket.
 */
private Ticket findTicket(String path, String key) {
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("authenticating ticket " + key + " for resource at path " + path);
        }

        Item item = findItem(path);
        Ticket ticket = contentDao.getTicket(item, key);
        if (ticket == null) {
            return null;
        }

        if (ticket.hasTimedOut()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("removing timed out ticket " + ticket.getKey());
            }
            contentDao.removeTicket(item, ticket);
            return null;
        }

        return ticket;
    } catch (DataAccessException e) {
        throw new AuthenticationServiceException(e.getMessage(), e);
    }
}
 
Example 3
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public List<McOptionDTO> getOptionDtos(Long mcQueContentId) throws McApplicationException {
try {
    return mcOptionsContentDAO.getOptionDtos(mcQueContentId);
} catch (DataAccessException e) {
    throw new McApplicationException(
	    "Exception occured when lams is populating candidate answers dto" + e.getMessage(), e);
}
   }
 
Example 4
Source File: SubEquipmentDAOImpl.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves the subEquipment entity specified by its id
 *
 * @param subEquipmentId
 *          The id of the subEquipment to be retrieved
 * @return A SubEquipmentCacheObject representing a row of the equipment table
 * @throws SubEquipmentException
 *           An exception is thrown if the execution of the query failed
 */
@Override
public SubEquipment getSubEquipmentById(final Long subEquipmentId) throws SubEquipmentException {
  SubEquipment eq = null;
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("getSubEquipmentById() - Getting the subEquipment with id: " + subEquipmentId);
  }
  try {
    eq = (SubEquipment) getItem(subEquipmentId);
  } catch (DataAccessException e) {
    throw new SubEquipmentException(e.getMessage());
  }
  return eq;
}
 
Example 5
Source File: SubEquipmentDAOImpl.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new subEquipment entity in the database
 *
 * @param subEquipment
 *          The information representing the subEquipment to be stored
 * @throws SubEquipmentException
 *           A SubEquipmentException is thrown in case the entity could not be
 *           stored
 */
@Override
public void create(final SubEquipmentCacheObject subEquipment) throws SubEquipmentException {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("create() - Create a subEquipment with the id: " + subEquipment.getId());
  }
  try {
    subEquipmentMapper.insertSubEquipment(subEquipment);
  } catch (DataAccessException e) {
    //TODO add these catch clauses to all the DAO classes...
    throw new SubEquipmentException(e.getMessage());
  }
}
 
Example 6
Source File: CustomPersistentRememberMeServices.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional
protected UserDetails processAutoLoginCookie(String[] cookieTokens, HttpServletRequest request, HttpServletResponse response) {

    Token token = getPersistentToken(cookieTokens);

    // Refresh token if refresh period has been passed
    if (new Date().getTime() - token.getTokenDate().getTime() > tokenRefreshDurationInMilliseconds) {

        // log.info("Refreshing persistent login token for user '{}', series '{}'", token.getUserId(), token.getSeries());
        try {

            // Refreshing: creating a new token to be used for subsequent calls

            token = persistentTokenService.createToken(identityService.createUserQuery().userId(token.getUserId()).singleResult(),
                    request.getRemoteAddr(), request.getHeader("User-Agent"));
            addCookie(token, request, response);

        } catch (DataAccessException e) {
            LOGGER.error("Failed to update token: ", e);
            throw new RememberMeAuthenticationException("Autologin failed due to data access problem: " + e.getMessage());
        }

    }

    return customUserDetailService.loadByUserId(token.getUserId());
}
 
Example 7
Source File: SubmitFilesService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public void createToolSession(Long toolSessionId, String toolSessionName, Long toolContentId) {
// pre-condition validation
if ((toolSessionId == null) || (toolContentId == null)) {
    throw new SubmitFilesException(
	    "Fail to create a submission session" + " based on null toolSessionId or toolContentId");
}

log.debug("Start to create submission session based on toolSessionId[" + toolSessionId.longValue()
	+ "] and toolContentId[" + toolContentId.longValue() + "]");
try {
    SubmitFilesContent submitContent = getSubmitFilesContent(toolContentId);
    if ((submitContent == null) || !toolContentId.equals(submitContent.getContentID())) {
	submitContent = new SubmitFilesContent();
	submitContent.setContentID(toolContentId);
    }
    SubmitFilesSession submitSession = new SubmitFilesSession();

    submitSession.setSessionID(toolSessionId);
    submitSession.setSessionName(toolSessionName);
    submitSession.setStatus(SubmitFilesSession.INCOMPLETE);
    submitSession.setContent(submitContent);
    submitFilesSessionDAO.createSession(submitSession);
    log.debug("Submit File session created");
} catch (DataAccessException e) {
    throw new SubmitFilesException(
	    "Exception occured when lams is creating" + " a submission Session: " + e.getMessage(), e);
}

   }
 
Example 8
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public void updateMcOptionsContent(McOptsContent mcOptsContent) throws McApplicationException {
try {
    mcOptionsContentDAO.updateMcOptionsContent(mcOptsContent);
} catch (DataAccessException e) {
    throw new McApplicationException(
	    "Exception occured when lams is updating" + " the mc options content: " + e.getMessage(), e);
}
   }
 
Example 9
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public List<McOptsContent> findOptionsByQuestionUid(Long mcQueContentId) throws McApplicationException {
try {
    return mcOptionsContentDAO.findMcOptionsContentByQueId(mcQueContentId);
} catch (DataAccessException e) {
    throw new McApplicationException(
	    "Exception occured when lams is finding by que id" + " the mc options: " + e.getMessage(), e);
}
   }
 
Example 10
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public void updateMc(McContent mc) throws McApplicationException {
try {
    mcContentDAO.updateMcContent(mc);
} catch (DataAccessException e) {
    throw new McApplicationException(
	    "Exception occured when lams is updating" + " the mc content: " + e.getMessage(), e);
}
   }
 
Example 11
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public McSession getMcSessionById(Long mcSessionId) throws McApplicationException {
try {
    return mcSessionDAO.getMcSessionById(mcSessionId);
} catch (DataAccessException e) {
    throw new McApplicationException(
	    "Exception occured when lams is retrieving by id mc session : " + e.getMessage(), e);
}
   }
 
Example 12
Source File: GlobalExceptionHandler.java    From sureness with Apache License 2.0 5 votes vote down vote up
/**
 * 对于所有数据库dao操作的异常统一处理
 * @param exception 数据库异常
 * @return 统一错误信息体
 */
@ExceptionHandler(DataAccessException.class)
@ResponseBody
ResponseEntity<Message> handleDataAccessException(DataAccessException exception) {
    String errorMessage = "database error happen";
    if (exception != null) {
        errorMessage = exception.getMessage();
    }
    log.warn("[sample-tom]-[database error happen]-{}", errorMessage, exception);
    Message message = Message.builder().errorMsg(errorMessage).build();
    return ResponseEntity.status(HttpStatus.CONFLICT).body(message);
}
 
Example 13
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public void removeMcQueContent(McQueContent mcQueContent) throws McApplicationException {
try {
    mcQueContentDAO.removeMcQueContent(mcQueContent);
} catch (DataAccessException e) {
    throw new McApplicationException(
	    "Exception occured when lams is removing mc question content: " + e.getMessage(), e);
}
   }
 
Example 14
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public List refreshQuestionContent(final Long mcContentId) throws McApplicationException {
try {
    return mcQueContentDAO.refreshQuestionContent(mcContentId);
} catch (DataAccessException e) {
    throw new McApplicationException(
	    "Exception occured when lams is refreshing  mc question content: " + e.getMessage(), e);
}

   }
 
Example 15
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public McQueUsr getMcUserBySession(final Long queUsrId, final Long mcSessionUid) throws McApplicationException {
try {
    return mcUserDAO.getMcUserBySession(queUsrId, mcSessionUid);
} catch (DataAccessException e) {
    throw new McApplicationException("Exception occured when lams is getting mc QueUsr: " + e.getMessage(), e);
}
   }
 
Example 16
Source File: McService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public void updateMcQueUsr(McQueUsr mcQueUsr) throws McApplicationException {
try {
    mcUserDAO.updateMcUser(mcQueUsr);
} catch (DataAccessException e) {
    throw new McApplicationException("Exception occured when lams is updating mc QueUsr: " + e.getMessage(), e);
}
   }
 
Example 17
Source File: SubEquipmentDAOImpl.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves all the subEquipments attached to the indicated equipment
 *
 * @param equipmentId
 *          The id of the equipment for which we want to retrieve its
 *          subEquipments
 * @return List of SubEquipmentCacheObject attached to the indicated equipment
 * @throws SubEquipmentException
 *           An exception is thrown if the execution of the query failed
 */
@Override
public List<SubEquipment> getSubEquipmentsByEquipment(final Long equipmentId) throws SubEquipmentException {
  List<SubEquipment> subEquipments = null;
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("getSubEquipmentsByEquipment() - Retrieving the subEquipments attached to the equipment with id " + equipmentId);
  }
  try {
    subEquipments = subEquipmentMapper.selectSubEquipmentsByEquipment(equipmentId);
  } catch (DataAccessException e) {
    throw new SubEquipmentException(e.getMessage());
  }
  return subEquipments;
}
 
Example 18
Source File: VoteService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
   public List<VoteUsrAttempt> getAttemptsForUserAndQuestionContent(final Long userUid, final Long questionUid) {
try {
    return voteUsrAttemptDAO.getAttemptsForUserAndQuestionContent(userUid, questionUid);
} catch (DataAccessException e) {
    throw new VoteApplicationException(
	    "Exception occured when lams is getting vote voteUsrRespDAO by user id and que content id: "
		    + e.getMessage(),
	    e);
}
   }
 
Example 19
Source File: CustomPersistentRememberMeServices.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional
protected UserDetails processAutoLoginCookie(String[] cookieTokens, HttpServletRequest request, HttpServletResponse response) {

    PersistentToken token = getPersistentToken(cookieTokens);

    // Refresh token if refresh period has been passed
    if (new Date().getTime() - token.getTokenDate().getTime() > tokenRefreshDurationInMilliseconds) {

        // log.info("Refreshing persistent login token for user '{}', series '{}'", token.getUserId(), token.getSeries());
        try {

            // Refreshing: creating a new token to be used for subsequent calls

            token = persistentTokenService.createToken(identityService.createUserQuery().userId(token.getUser()).singleResult(),
                    request.getRemoteAddr(), request.getHeader("User-Agent"));
            addCookie(token, request, response);

        } catch (DataAccessException e) {
            log.error("Failed to update token: ", e);
            throw new RememberMeAuthenticationException("Autologin failed due to data access problem: " + e.getMessage());
        }

    }

    return customUserDetailService.loadByUserId(token.getUser());
}
 
Example 20
Source File: ExceptionProcessor.java    From personal_book_library_web_project with MIT License 5 votes vote down vote up
@ExceptionHandler(DataAccessException.class)
  @ResponseStatus(value = HttpStatus.NOT_FOUND)
  @ResponseBody
  public ServiceExceptionDetails processDataAccessException(HttpServletRequest httpServletRequest, DataAccessException exception) {
      
String detailedErrorMessage = exception.getMessage();
       
      String errorURL = httpServletRequest.getRequestURL().toString();
       
      return new ServiceExceptionDetails("", detailedErrorMessage, errorURL);
  }