Example usage for org.springframework.orm ObjectRetrievalFailureException getMessage

List of usage examples for org.springframework.orm ObjectRetrievalFailureException getMessage

Introduction

In this page you can find the example usage for org.springframework.orm ObjectRetrievalFailureException 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:org.openhie.openempi.dao.UniversalDaoTest.java

/**
 * Simple test to verify CRUD works.//from  www .  j a v a  2s .co m
 */
public void testCRUD() {
    User user = new User();
    // set required fields
    user.setUsername("foo");
    user.setPassword("bar");
    user.setFirstName("first");
    user.setLastName("last");
    user.getAddress().setCity("Denver");
    user.getAddress().setPostalCode("80465");
    user.setEmail("foo@bar.com");

    // create
    user = (User) universalDao.save(user);
    flush();
    assertNotNull(user.getId());

    // retrieve
    user = (User) universalDao.get(User.class, user.getId());
    assertNotNull(user);
    assertEquals("last", user.getLastName());

    // update
    user.getAddress().setCountry("USA");
    universalDao.save(user);
    flush();

    user = (User) universalDao.get(User.class, user.getId());
    assertEquals("USA", user.getAddress().getCountry());

    // delete
    universalDao.remove(User.class, user.getId());
    flush();
    try {
        universalDao.get(User.class, user.getId());
        fail("User 'foo' found in database");
    } catch (ObjectRetrievalFailureException e) {
        assertNotNull(e.getMessage());
    } catch (InvalidDataAccessApiUsageException e) { // Spring 2.0 throws this one
        assertNotNull(e.getMessage());
    }
}

From source file:be.bittich.quote.controller.impl.DefaultExceptionHandler.java

@RequestMapping(produces = APPLICATION_JSON)
@ExceptionHandler(ObjectRetrievalFailureException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public @ResponseBody Map<String, Object> handleValidationException(ObjectRetrievalFailureException ex)
        throws IOException {
    Map<String, Object> map = newHashMap();
    map.put("error", "Entity Not Found");
    map.put("cause", ex.getMessage());
    return map;/*from   www. java2  s  . co m*/
}

From source file:net.jkratz.igdb.controller.advice.ErrorController.java

@RequestMapping(produces = "application/json")
@ExceptionHandler(ObjectRetrievalFailureException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public @ResponseBody Map<String, Object> handleObjectRetrievalFailureException(
        ObjectRetrievalFailureException ex) throws IOException {
    logger.error("Object not found", ex);
    Map<String, Object> map = Maps.newHashMap();
    map.put("error", "Entity Not Found");
    map.put("message", ex.getMessage());
    if (ex.getRootCause() != null) {
        map.put("cause", ex.getRootCause().getMessage());
    }/*from w  w w .j  a  v  a2  s  . com*/
    return map;
}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
* retrieves the QualifierType by a qualifier type code . Qualifier type code are maxium 4 characters long
*
* @param   qualifierTypeCode   Qualifier Type code
* @return  {@link QualifierType}  matching the code
* @throws  InvalidInputException   If the qualifier type code is NULL or the qualifier type code is more than 4 characters long
* @throws  ObjectNotFoundException If no qualifier type is found in the database matching the code
* @throws  AuthorizationException  in case of hibernate error   
*//*  ww w.j a va  2 s.  co  m*/
public QualifierType getQualifierType(String qualifierTypeCode)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (qualifierTypeCode == null || qualifierTypeCode.length() > 4)
        throw new InvalidInputException();
    String qualifier_type = qualifierTypeCode.toUpperCase();
    QualifierType qt = null;
    while (qualifier_type.length() < 4) {
        qualifier_type += " ";
    }
    HibernateTemplate t = getHibernateTemplate();
    try {
        qt = (QualifierType) t.load(QualifierType.class, qualifier_type);
    } catch (ObjectRetrievalFailureException e) {
        throw new ObjectNotFoundException(
                "Can not find qualifier type " + qualifierTypeCode + " in the database");
    } catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    return qt;

}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
* retrieves all the Functions associated with a category code such as SAP or ADMN. Category code are maxium 4 characters long
*
* @param   categoryCode  Category Code//from   w ww  . j a v a2s  . c  o  m
* @return  all the {@link Function} associated with the category code
* @throws  InvalidInputException if categoryCode is NULL or if categoryCode is more than 4 characters long
* @throws  ObjectNotFoundException If no function is found 
* @throws  AuthorizationException  in case of hibernate error   
*/
public Set<Function> listFunctionsByCategory(String categoryCode)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (categoryCode == null || categoryCode.length() > 4)
        throw new InvalidInputException();
    String categoryName = categoryCode.toUpperCase();
    Category cat = null;
    Set<Function> functions = null;
    while (categoryName.length() < 4) {
        categoryName += " ";
    }
    HibernateTemplate t = getHibernateTemplate();
    try {
        cat = (Category) t.load(Category.class, categoryName);
        functions = cat.getFunctions();
        t.initialize(functions);
    } catch (ObjectRetrievalFailureException e) {
        throw new ObjectNotFoundException("Can not find category " + categoryCode + " in the database");
    } catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {

            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    return functions;

}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
 * retrieves parents of the specified qualifier Id 
 *
 * @param   id  Qualifier Id//from  w ww  .j  a va 2s.  c o m
 * @return  all the parent {@link Qualifier} of the supplied qualifier Id
 * @throws  InvalidInputException if id is NULL
 * @throws  ObjectNotFoundException If no parents is found 
 * @throws  AuthorizationException  in case of hibernate error   
 */
public Set<Qualifier> listParentsByQualifier(Long id)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (id == null)
        throw new InvalidInputException();
    Qualifier q = null;
    Set<Qualifier> parents = null;
    HibernateTemplate t = getHibernateTemplate();
    try {
        q = (Qualifier) t.load(Qualifier.class, id);
        parents = q.getParents();
        t.initialize(parents);
    } catch (ObjectRetrievalFailureException e) {
        throw new ObjectNotFoundException("Can not find qualifier with id " + id + " in the database");
    } catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    return parents;
}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
 * retrieves all the Qualifiers associated with a qualifier type code such as COST or FUND. Qualifier type are maxium 4 characters long
 *
 * @param   type  Qualifier Type code//from   w  w w.ja  v  a2 s. c o  m
 * @return  all the {@link Qualifier} associated with the qualifier type code
 * @throws  InvalidInputException if qualifier type code is NULL or if the code is more than 4 characters long
 * @throws  ObjectNotFoundException If no Qualifier is found 
 * @throws  AuthorizationException  in case of hibernate error   
 */
public Qualifier getRootQualifierByType(String type)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (type == null)
        throw new InvalidInputException();

    String qualifier_type = type.toUpperCase();
    QualifierType qt = null;
    Set<Qualifier> qualifiers = null;
    while (qualifier_type.length() < 4) {
        qualifier_type += " ";
    }
    HibernateTemplate t = getHibernateTemplate();
    try {
        qt = (QualifierType) t.load(QualifierType.class, qualifier_type);
        qualifiers = qt.getQualifiers();
        t.initialize(qualifiers);
    } catch (ObjectRetrievalFailureException e) {
        throw new InvalidInputException("Can not find qualifier type " + type + " in the database",
                InvalidInputException.InvalidQualifierType);
    } catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();
            throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (qualifiers == null)
        throw new ObjectNotFoundException("Can not find qualifiers for qualifier type " + type);
    Iterator<Qualifier> it = qualifiers.iterator();
    Qualifier ret = null;
    if (it.hasNext())
        ret = it.next();

    return ret;
}