Example usage for org.springframework.dao DataAccessException getMessage

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

Introduction

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

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:com.github.carlomicieli.rest.resources.RollingStocksResource.java

@GET
@Path("/era/{era}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getByEra(@PathParam("era") String era) {
    log.info("GET /rollingstocks/era/{}", era);

    try {//from  w w  w.j av a2s .co  m
        Era e = Enum.valueOf(Era.class, era);

        final RollingStockRepresentation[] rollingStocks = createArray(rsService.getAllRollingStocks(e));

        return Response.ok(rollingStocks).cacheControl(getCacheControl()).build();
    } catch (DataAccessException ex) {
        log.error(ex.getMessage());
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.repaskys.services.UrlShortenerServiceImpl.java

public String deleteUrl(String fullUrl) {
    String errorMessage = "";
    try {//from   w  ww.  j  a  v  a  2 s  . c o  m
        urlRepository.delete(urlRepository.findByFullUrl(fullUrl).getId());
    } catch (DataAccessException ex) {
        LOGGER.error("DataAccessException when saving ShortUrl", ex);
        errorMessage = ex.getMessage();
    } catch (TransactionException ex) {
        // when we can't connect to the database, it throws a
        // CannotCreateTransactionException
        LOGGER.error("TransactionException when saving ShortUrl", ex);
        errorMessage = ex.getMessage();
    } catch (RuntimeException ex) {
        // we need the generic catch all, so that the raw exception stack
        // trace doesn't make it all the way back to the user
        LOGGER.error("RuntimeException when saving ShortUrl", ex);
        errorMessage = ex.getMessage();
    }
    return errorMessage;
}

From source file:com.github.carlomicieli.rest.resources.BrandsResource.java

/**
 * Return the list of all brands.//w  w w  .j  ava2  s.c  om
 * <p>
 * <code>GET /brands</code>
 * </p>
 * 
 * @return the list of brands.
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getBrands() {
    log.info("GET /brands");

    try {
        final BrandRepresentation[] brands = createArray(brandService.getAllBrands());

        return Response.ok(brands).cacheControl(getCacheControl()).build();
    } catch (DataAccessException ex) {
        log.error(ex.getMessage());
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.github.carlomicieli.rest.resources.BrandsResource.java

/**
 * Return the list of all brands.//w w w .  j a v a 2s .  com
 * <p>
 * <code>GET /brands/{brandId}</code>
 * </p>
 * 
 * @param brandId the brand unique id.
 * @return the list of brands.
 */
@GET
@Path("/{brandId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getBrand(@PathParam("brandId") long brandId) {
    log.info("GET /brands/{}", brandId);

    try {
        final BrandRepresentation brand = new BrandRepresentation(brandService.getBrand(brandId));
        return Response.ok(brand).tag(brand.tag()).cacheControl(getCacheControl()).build();
    } catch (DataAccessException ex) {
        log.error(ex.getMessage());
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.github.carlomicieli.rest.resources.RailwaysResource.java

/**
 * Returns the list of all railway.//from   w  w w.ja  v a  2s. co m
 * <p>
 * <code>GET /railways</code>
 * </p>
 * 
 * @return the list of brands.
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getRailways() {
    log.info("GET /railways");

    try {
        final RailwayRepresentation[] railways = createArray(railwayService.getAllRailways());

        return Response.ok(railways).cacheControl(getCacheControl()).build();
    } catch (DataAccessException ex) {
        log.error(ex.getMessage());
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.github.carlomicieli.rest.resources.RailwaysResource.java

/**
 * Returns a railway resource.//from  w  w w  .  ja  v  a2  s  . c o  m
 * <p>
 * <code>GET /railways/{railwayId}</code>
 * </p>
 * 
 * @param railwayId the railway unique id.
 * @return the railway resource.
 */
@GET
@Path("/{brandId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getBrand(@PathParam("railwayId") long railwayId) {
    log.info("GET /railways/{}", railwayId);

    try {
        final RailwayRepresentation railway = new RailwayRepresentation(railwayService.getRailway(railwayId));
        return Response.ok(railway).tag(railway.tag()).cacheControl(getCacheControl()).build();
    } catch (DataAccessException ex) {
        log.error(ex.getMessage());
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.repaskys.services.UrlShortenerServiceImpl.java

public String saveUrl(ShortUrl shortUrl) {
    LOGGER.trace("trying to save URL...");
    String errorMessage = "";

    // FIXME these cryptic exception messages will be bubbled up to the user
    try {/*  www.j  a v  a 2 s  .c  om*/
        // insert a new record
        urlRepository.save(shortUrl);

    } catch (DataAccessException ex) {
        LOGGER.error("DataAccessException when saving ShortUrl", ex);
        errorMessage = ex.getMessage();
    } catch (TransactionException ex) {
        // when we can't connect to the database, it throws a
        // CannotCreateTransactionException
        LOGGER.error("TransactionException when saving ShortUrl", ex);
        errorMessage = ex.getMessage();
    } catch (RuntimeException ex) {
        // we need the generic catch all, so that the raw exception stack
        // trace doesn't make it all the way back to the user
        LOGGER.error("RuntimeException when saving ShortUrl", ex);
        errorMessage = ex.getMessage();
    }
    return errorMessage;
}

From source file:es.osoco.grails.plugins.otp.authentication.OneTimePasswordAuthenticationProvider.java

protected final UserDetails retrieveUser(String username, OneTimePasswordAuthenticationToken authentication)
        throws AuthenticationException {
    UserDetails loadedUser;/*  ww  w .  ja va 2 s  .c  o m*/

    try {
        loadedUser = getUserDetailsService().loadUserByUsername(username);
    } catch (DataAccessException repositoryProblem) {
        throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem);
    }

    if (loadedUser == null) {
        throw new AuthenticationServiceException(
                "UserDetailsService returned null, which is an interface contract violation");
    }
    return loadedUser;
}

From source file:org.jenkinsci.plugins.reverse_proxy_auth.auth.ReverseProxyAuthenticationProvider.java

@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
        throws AuthenticationException {
    if (!StringUtils.hasLength(username)) {
        throw new BadCredentialsException(
                messages.getMessage("ReverseProxyAuthenticationProvider.emptyUsername", "Empty Username"));
    }/*from  w w  w .j  av a  2s.c  om*/

    if (logger.isDebugEnabled()) {
        logger.debug("Retrieving user " + username);
    }

    String password = (String) authentication.getCredentials();

    // We do not need this when doing Reverse Proxy Auth
    //Assert.notNull(password, "Null password was supplied in authentication token");

    // if (password.length() == 0) {
    //    logger.debug("Rejecting empty password for user " + username);
    //    throw new BadCredentialsException(messages.getMessage("LdapAuthenticationProvider.emptyPassword",
    //            "Empty Password"));
    //}

    try {
        ReverseProxyUserDetails revProxyU = getAuthenticator().authenticate(username, password);

        return createUserDetails(revProxyU, username, password);

    } catch (DataAccessException ldapAccessFailure) {
        throw new AuthenticationServiceException(ldapAccessFailure.getMessage(), ldapAccessFailure);
    }
}

From source file:com.sfs.whichdoctor.dao.SearchIndexDAOImpl.java

/**
 * Delete the search index value.//from   www.j av a  2s .c  om
 *
 * @param guid the guid
 * @param indextype the indextype
 *
 * @return true, if successful
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final boolean delete(final int guid, final String indextype) throws WhichDoctorDaoException {

    boolean success = false;

    try {
        this.getJdbcTemplateWriter().update(this.getSQL().getValue("searchindex/delete"),
                new Object[] { guid, indextype });

        success = true;

    } catch (DataAccessException de) {
        dataLogger.error("Error deleting index: " + de.getMessage());
    }
    return success;
}