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:edu.mit.isda.permitservice.dataobjects.GeneralSelection.java

/**
 * retrieves a Criteria Set by selection ID and certificate username.
 *
 * @param   selectionID/*from  w w w . j  a v a2  s.  co  m*/
 * @param   username
 * @return  {@link Category} matching the category code
 * @throws  InvalidInputException   If the category code is NULL or more than 4 characters long
 * @throws  ObjectNotFoundException If no category is found in the database matching the category code
 * @throws  AuthorizationException  in case of hibernate error   
 */
public Collection<Criteria> getCriteriaSet(String selectionID, String userName)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (null == userName)
        throw new InvalidInputException();

    String name = userName.trim().toUpperCase();

    if (name.length() <= 0)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection crits = null;
    try {
        crits = t.findByNamedQuery("GET_CRITERIA", new String[] { name, selectionID });
        t.initialize(crits);
    } catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();
        re.printStackTrace();
        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);
        } else
            throw new AuthorizationException(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (crits == null) {
        throw new AuthorizationException("error retrieving viewable categories");
    }

    return crits;
}

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

/**
 * retrieves a selection list by certificate username.
 *
 * @param   username/*from www .  ja  va 2s .  c  o  m*/
 * @return  {@link Category} matching the category code
 * @throws  InvalidInputException   If the category code is NULL or more than 4 characters long
 * @throws  ObjectNotFoundException If no category is found in the database matching the category code
 * @throws  AuthorizationException  in case of hibernate error   
 */
public Collection<SelectionList> getSelectionList(String userName)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {

    if (null == userName) {
        throw new InvalidInputException();
    }

    String name = userName.trim().toUpperCase();

    if (name.length() <= 0)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection crits = null;
    try {
        crits = t.findByNamedQuery("SELECTION_LIST", new String[] { name, name });
        t.initialize(crits);
    } catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();
        re.printStackTrace();

        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);
            }
        } else {
            throw new AuthorizationException(e.getMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getMessage());

    }
    if (crits == null) {
        throw new AuthorizationException("error retrieving viewable categories");
    }

    return crits;
}

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

/**
* retrieve a set of Authorizations based on a criteria list
*
* @param criteriaXML XML string containing criteria information
* @return a set of {@link Authorization} matching the specified criteria
* @throws  InvalidInputException   If any of the parameters is NULL
* @throws  ObjectNotFoundException If no authorizations is found matching the criteria
* @throws  AuthorizationException  in case of hibernate error   
*///  w  ww .ja v  a  2  s. c om
@SuppressWarnings("unchecked")
public Collection<Authorization> listAuthorizationsByCriteria(String[] criteria)
        throws InvalidInputException, ObjectNotFoundException, PermissionException, AuthorizationException {
    if (criteria == null)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    List alist = new ArrayList();

    Collection authorizations = null;
    for (int i = 0; i < criteria.length; i++) {
        log.debug("Criteria " + i + ":" + criteria[i]);
    }

    try {
        authorizations = t.findByNamedQuery("LISTAUTHSBYCRIT_RAW", criteria);
        //  authorizations = t.findByNamedQuery("LISTAUTHSBYCRIT_SP", obj);
        t.initialize(authorizations);
    }

    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 if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    return authorizations;
}

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

/**
* retrieve a set of people based on a kerberos or last name
*
* @param criteriaXML XML string containing criteria information
* @return a set of {@link Authorization} matching the specified criteria
* @throws  InvalidInputException   If any of the parameters is NULL
* @throws  ObjectNotFoundException If no authorizations is found matching the criteria
* @throws  AuthorizationException  in case of hibernate error   
*///from  www.j  a va 2  s.c  o  m
@SuppressWarnings("unchecked")
public Collection<PersonRaw> listPersonRaw(String name, String search, String sort, String filter1,
        String filter2, String filter3)
        throws InvalidInputException, ObjectNotFoundException, PermissionException, AuthorizationException {
    if (name == null)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    List alist = new ArrayList();
    String last_only = "%";
    String kerb_only = "%";
    String both = "%";
    String mitId = name;

    if (search.equals("kerberos")) {
        kerb_only = name;
    } else if (search.equals("last")) {
        last_only = name;
    } else if (search.equals("both")) {
        both = name;
    }
    if (name.endsWith("%")) {
        mitId = name.substring(0, name.length() - 1).trim();
    } else {
        mitId = name.trim();
    }
    System.out.println("******************* LAST: " + last_only);
    System.out.println("******************* KERB ID: " + kerb_only);
    System.out.println("*******************  BOTH: " + both);
    System.out.println("******************* MIT ID: " + mitId);
    Collection people = null;

    try {
        if (sort.equals("last"))
            people = t.findByNamedQuery("QUICK_PERSON",
                    new String[] { last_only, kerb_only, both, both, mitId, filter1, filter2, filter3 });
        else if (sort.equals("kerberos"))
            people = t.findByNamedQuery("QUICK_PERSON_KERBSORT",
                    new String[] { last_only, kerb_only, both, both, mitId, filter1, filter2, filter3 });
        else if (sort.equals("type"))
            people = t.findByNamedQuery("QUICK_PERSON_TYPESORT",
                    new String[] { last_only, kerb_only, both, both, mitId, filter1, filter2, filter3 });
        else {
            people = t.findByNamedQuery("QUICK_PERSON",
                    new String[] { last_only, kerb_only, both, both, mitId, filter1, filter2, filter3 });
        }
        t.initialize(people);
    }

    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 if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    return people;
}

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

/**
* retrieve a set of Authorizations by a person's kerberosId
*
* @param userName user's kerberos Id//from  www  .  j a  v a2s  .  c  o m
* @param category Authorization Category code, such as "SAP"
* @param isActive if you are only interested in authorizations that are currently active, use Boolean.TRUE, otherwise, use Boolean.FALSE
* @param willExpand if you want to expand the qualifier to get the implicit authorization or not 
* @param proxyUserName  the user who is executing this query
* @return a set of {@link Authorization} matching the specified criteria
* @throws  InvalidInputException   If any of the parameters is NULL
* @throws  ObjectNotFoundException If no authorizations is found matching the criteria
* @throws  AuthorizationException  in case of hibernate error   
*/
@SuppressWarnings("unchecked")
public Set<Authorization> listAuthorizationsByPerson(String userName, String category, Boolean isActive,
        Boolean willExpand, String applicationName, String proxyUserName)
        throws InvalidInputException, ObjectNotFoundException, PermissionException, AuthorizationException {

    if (userName == null || category == null || isActive == null || willExpand == null
            || applicationName == null || proxyUserName == null)
        throw new InvalidInputException();

    String pname = userName.trim().toUpperCase();
    String categoryCode = category.trim().toUpperCase();
    String aname = applicationName.trim().toUpperCase();
    String pUser = proxyUserName.trim().toUpperCase();

    //if (pname.length() <= 0 || categoryCode.length()<=0 || aname.length()<=0 || pUser.length() <=0)
    if (pname.length() <= 0 || aname.length() <= 0 || pUser.length() <= 0)
        throw new InvalidInputException();

    if (categoryCode.length() > 0) {
        while (categoryCode.length() < 4) {
            categoryCode += " ";
        }
    }
    String active = isActive ? "Y" : "N";
    String expand = willExpand ? "Y" : "N";
    HibernateTemplate t = getHibernateTemplate();

    Collection authorizations = null;
    try {
        authorizations = t.findByNamedQuery("LISTAUTHSBYPERSON_SP",
                new String[] { aname, pUser, pname, categoryCode, expand, active });
        t.initialize(authorizations);

    }

    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 if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (authorizations == null)
        throw new AuthorizationException("error retrieving authorizations for user " + userName);

    Set<Authorization> authSet = new HashSet<Authorization>(authorizations);
    return authSet;

}

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

/**
   * retrieve a set of Authorizations by a person's kerberosId
   *//  ww w.j  a v a2  s.  c  om
   * @param userName user's kerberos Id
   * @param category Authorization Category code, such as "SAP"
   * @param isActive if you are only interested in authorizations that are currently active, use Boolean.TRUE, otherwise, use Boolean.FALSE
   * @param willExpand if you want to expand the qualifier to get the implicit authorization or not 
   * @param proxyUserName  the user who is executing this query
   * @return a set of {@link Authorization} matching the specified criteria
   * @throws  InvalidInputException   If any of the parameters is NULL
   * @throws  ObjectNotFoundException If no authorizations is found matching the criteria
   * @throws  AuthorizationException  in case of hibernate error   
   */
@SuppressWarnings("unchecked")
public Collection<AuthorizationExt> listAuthByPersonExtend1(String userName, String category, Boolean isActive,
        Boolean willExpand, String applicationName, String proxyUserName, String realOrImplied,
        String function_name, String function_id, String function_qualifier_type, String qualifier_code,
        String qualifier_id, String base_qual_code, String base_qual_id, String parent_qual_code,
        String parent_qual_id)
        throws InvalidInputException, ObjectNotFoundException, PermissionException, AuthorizationException {

    if (userName == null || category == null || isActive == null || willExpand == null
            || applicationName == null || proxyUserName == null)
        throw new InvalidInputException();

    String pname = userName.trim().toUpperCase();
    String categoryCode = category.trim().toUpperCase();
    String aname = applicationName.trim().toUpperCase();
    String pUser = proxyUserName.trim().toUpperCase();
    String rori = "B";

    if (null != realOrImplied) {
        rori = realOrImplied.trim().toUpperCase();
    }

    //if (pname.length() <= 0 || categoryCode.length()<=0 || aname.length()<=0 || pUser.length() <=0)
    if (pname.length() <= 0 || aname.length() <= 0 || pUser.length() <= 0)
        throw new InvalidInputException();

    if (categoryCode.length() > 0) {
        while (categoryCode.length() < 4) {
            categoryCode += " ";
        }
    }
    String active = isActive ? "Y" : "N";
    String expand = willExpand ? "Y" : "N";
    HibernateTemplate t = getHibernateTemplate();

    Collection authorizations = null;
    try {
        authorizations = t.findByNamedQuery("LISTAUTHBYPERSON_EXT",
                new String[] { aname, pUser, pname, categoryCode, expand, active, rori, function_name,
                        function_id, function_qualifier_type, qualifier_code, qualifier_id, base_qual_code,
                        base_qual_id, parent_qual_code, parent_qual_id });
        t.initialize(authorizations);
    }

    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 if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (authorizations == null)
        throw new AuthorizationException("error retrieving authorizations for user " + userName);

    return authorizations;
}

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

/**
* retrieve a set of Authorizations by a person's kerberosId
*
* @param userName user's kerberos Id/*w  w w  .jav a2s.com*/
* @param category Authorization Category code, such as "SAP"
* @param isActive if you are only interested in authorizations that are currently active, use Boolean.TRUE, otherwise, use Boolean.FALSE
* @param willExpand if you want to expand the qualifier to get the implicit authorization or not 
* @param proxyUserName  the user who is executing this query
* @return a set of {@link Authorization} matching the specified criteria
* @throws  InvalidInputException   If any of the parameters is NULL
* @throws  ObjectNotFoundException If no authorizations is found matching the criteria
* @throws  AuthorizationException  in case of hibernate error   
*/
@SuppressWarnings("unchecked")
public Collection<AuthorizationRaw> listAuthorizationsByPersonRaw(String userName, String category,
        Boolean isActive, Boolean willExpand, String applicationName, String proxyUserName)
        throws InvalidInputException, ObjectNotFoundException, PermissionException, AuthorizationException {

    if (userName == null || category == null || isActive == null || willExpand == null
            || applicationName == null || proxyUserName == null)
        throw new InvalidInputException();

    String pname = userName.trim().toUpperCase();
    String categoryCode = category.trim().toUpperCase();
    String aname = applicationName.trim().toUpperCase();
    String pUser = proxyUserName.trim().toUpperCase();

    //if (pname.length() <= 0 || categoryCode.length()<=0 || aname.length()<=0 || pUser.length() <=0)
    if (pname.length() <= 0 || aname.length() <= 0 || pUser.length() <= 0)
        throw new InvalidInputException();

    if (categoryCode.length() > 0) {
        while (categoryCode.length() < 4) {
            categoryCode += " ";
        }
    }
    String active = isActive ? "Y" : "N";
    String expand = willExpand ? "Y" : "N";
    HibernateTemplate t = getHibernateTemplate();

    Collection authorizations = null;
    try {
        authorizations = t.findByNamedQuery("LISTAUTHRAW",
                new String[] { aname, pUser, pname, categoryCode, expand, active });
        t.initialize(authorizations);
    }

    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 if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (authorizations == null)
        throw new AuthorizationException("error retrieving authorizations for user " + userName);

    return authorizations;
}

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

/**
 * retrieves all the QualifierTypes in the database
 *
 * @return  all the {@link QualifierType} in the database
 * @throws  ObjectNotFoundException If no QualifierType is found 
 * @throws  AuthorizationException  in case of hibernate error   
 *///from   w  ww . j  a  v a2s.c o m

@SuppressWarnings("unchecked")
public Set<QualifierType> listQualifierTypes() throws ObjectNotFoundException, AuthorizationException {
    List l = null;
    HibernateTemplate t = getHibernateTemplate();
    try {
        l = t.find("from QualifierType c");
    } 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 (l == null)
        throw new ObjectNotFoundException("No Qualifier Type found in database");

    Set<QualifierType> qSet = new HashSet<QualifierType>(l);
    return qSet;

}

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

@SuppressWarnings("unchecked")
public Set<Qualifier> listQualifiersByName(String name, int searchCriteria)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (name == null)
        throw new InvalidInputException();
    if (searchCriteria != AuthorizationManager.BEGINWITH && searchCriteria != AuthorizationManager.CONTAINS
            && searchCriteria != AuthorizationManager.EXACT)
        throw new InvalidInputException();
    List results = null;//  w w  w  . j a  va  2 s .c  o m
    String searchC = Integer.toString(searchCriteria);
    HibernateTemplate t = getHibernateTemplate();
    try {
        results = t.findByNamedQuery("QING_TEST_GETQUALIFIERSBYNAME_SP", new String[] { name, searchC });
    } 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);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (results == null)
        throw new ObjectNotFoundException("no qualifier found in database");

    Set<Qualifier> resultSet = new HashSet<Qualifier>(results);

    return resultSet;

}

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

@SuppressWarnings("unchecked")
public Set<Qualifier> listQualifiersByCode(String code, int searchCriteria)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (code == null)
        throw new InvalidInputException();

    if (searchCriteria != AuthorizationManager.BEGINWITH && searchCriteria != AuthorizationManager.CONTAINS
            && searchCriteria != AuthorizationManager.EXACT)
        throw new InvalidInputException();
    List results = null;/*from w w  w.  j a  va 2s . co m*/
    String searchC = Integer.toString(searchCriteria);
    HibernateTemplate t = getHibernateTemplate();
    try {
        results = t.findByNamedQuery("QING_TEST_GETQUALIFIERSBYCODE_SP", new String[] { code, searchC });
    } 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);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    if (results == null)
        throw new ObjectNotFoundException("no qualifier found in database");

    Set<Qualifier> resultSet = new HashSet<Qualifier>(results);

    return resultSet;
}