Example usage for org.springframework.orm ObjectRetrievalFailureException getCause

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

Introduction

In this page you can find the example usage for org.springframework.orm ObjectRetrievalFailureException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

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

/**
 * retrieves children of the specified qualifier Id 
 *
 * @param   id  Qualifier Id//from   w ww.  j  av a 2 s  .  c  o  m
 * @return  all the children {@link Qualifier} of the supplied qualifier Id
 * @throws  InvalidInputException if id is NULL
 * @throws  ObjectNotFoundException If no children is found 
 * @throws  AuthorizationException  in case of hibernate error   
 */
public Set<Qualifier> listChildrenByQualifier(Long id)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (id == null)
        throw new InvalidInputException();
    Qualifier q = null;
    Set<Qualifier> children = null;
    HibernateTemplate t = getHibernateTemplate();
    try {
        q = (Qualifier) t.load(Qualifier.class, id);
        children = q.getChildren();
        t.initialize(children);
    } 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) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else
                throw new AuthorizationException(errorMessage);
        }
    }

    return children;
}

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   
*//*from   ww  w.j  a  v  a 2 s  . c  o 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  www.  j ava2 s .co  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//  w  w w . j  a va2s. 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//w ww . j a  v a2s . 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;
}