Example usage for org.springframework.dao DataAccessException getCause

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

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException 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

/**
* Select Criteria Qualifiers for which userName is authorized. 
*
* @param userName user's kerberos Id/*from  w w w.j  a  v a  2 s.c  o m*/
* @param functionName funtion name
* @param qualifierType Qualifer Type
* @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 String getQualifierXMLForCriteriaQuery(String userName, String functionName, String qualifierType)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == userName || ((null == functionName) && (null == qualifierType)))
        throw new InvalidInputException();

    StringBuffer xmlBuff = new StringBuffer();
    Iterator qIt = null;
    Qualifier xmlqual = null;
    String pname = userName.trim().toUpperCase();
    String fname = "";
    String qtype = "";
    if (null != functionName) {
        fname = functionName.trim().toUpperCase();
    }
    if (null != qualifierType) {
        qtype = qualifierType.trim().toUpperCase();
    }
    // String qtype = "ZLEVELS_" + qualifier_type.trim().toUpperCase();

    total_qualifiers = 0;

    if (pname.length() <= 0 || (fname.length() <= 0 && qtype.length() <= 0))
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection<Qualifier> quals = null;

    try {
        if (qtype.length() > 0) {
            quals = t.findByNamedQuery("QUALIFIER_ROOT_LIST", new String[] { qtype });

        } else {
            quals = t.findByNamedQuery("QUALIFIER_LIST_FOR_CRITERIA_LIST", new String[] { fname });
        }
        //System.out.println(t.toString());
        t.initialize(quals);
    }

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

    xmlBuff.append("<qualifiers>");

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

    //Set<PickableQualifier> qualSet = new HashSet<PickableQualifier>(quals);
    //System.out.println(quals.size());
    //System.out.println(qualSet.size());

    //qIt = qualSet.iterator();
    qIt = quals.iterator();

    while (qIt.hasNext()) {
        total_qualifiers++;
        //System.out.println("Total = " + total_qualifiers);
        xmlqual = (Qualifier) qIt.next();
        xmlBuff.append("<qualifier>");
        xmlBuff.append("<qid>");
        xmlBuff.append(xmlqual.getId());
        xmlBuff.append("</qid>");
        xmlBuff.append("<expanded>");
        xmlBuff.append("true");
        xmlBuff.append("</expanded>");
        xmlBuff.append("<qcode>");
        xmlBuff.append(cleanup(xmlqual.getCode(), false));
        xmlBuff.append("</qcode>");
        xmlBuff.append("<qname>");
        xmlBuff.append(cleanup(xmlqual.getName(), false));
        xmlBuff.append("</qname>");
        xmlBuff.append("<hasChild>");
        xmlBuff.append(cleanup(xmlqual.getHasChild().toString(), false));
        xmlBuff.append("</hasChild>");
        // Get children only for non DEPT qualifyers
        if (xmlqual.getHasChild()) {
            xmlBuff.append("<qchildren>");
            xmlBuff.append(getChildrenXML(xmlqual.getId().toString(), 1, 1));
            xmlBuff.append("</qchildren>");
        }
        xmlBuff.append("</qualifier>");
    }

    xmlBuff.append("</qualifiers>");
    //System.out.println("Final Buffer = " + xmlBuff.toString());
    return xmlBuff.toString();
}

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

/**
 * Select Qualifiers for which userName is authorized. 
 *
 * @param userName user's kerberos Id/*  ww  w.  j a  va  2s .c o  m*/
 * @param function_name funtion name
 * @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 String getQualifierXML(String root_id, Boolean rbool, String qualifier_type)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == root_id)
        throw new InvalidInputException();

    StringBuffer xmlBuff = new StringBuffer();
    Iterator qIt = null;
    QualRoot xmlqual = null;
    String root = root_id.trim().toUpperCase();
    String qtype = "ZLEVELS_" + qualifier_type.trim().toUpperCase();

    total_qualifiers = 0;

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

    HibernateTemplate t1 = getHibernateTemplate();
    Collection<LevelCount> lc = null;

    try {
        lc = t1.findByNamedQuery("GET_LEVEL_FOR_QUAL_TYPE", new String[] { qtype, qtype });
        //System.out.println(t1.toString());
        t1.initialize(lc);
    }

    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());
    }

    int val = Integer.parseInt(lc.iterator().next().getValue()) - 1;
    //System.out.println("Level = " + val);

    HibernateTemplate t = getHibernateTemplate();
    Collection<QualRoot> quals = null;
    try {
        quals = t.findByNamedQuery("GET_QUALIFIER_FOR_ROOT", root);
        t.initialize(quals);
    }

    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());
    }
    xmlBuff.append("<qualifiers>");

    if (quals == null)
        throw new AuthorizationException("error retrieving root qualifier with id " + root_id);

    qIt = quals.iterator();
    if (rbool.booleanValue()) {
        while (qIt.hasNext()) {
            total_qualifiers++;
            xmlqual = (QualRoot) qIt.next();
            xmlBuff.append("<qualifier>");
            xmlBuff.append("<qid>");
            xmlBuff.append(xmlqual.getId());
            xmlBuff.append("</qid>");
            xmlBuff.append("<expanded>");
            xmlBuff.append("true");
            xmlBuff.append("</expanded>");
            xmlBuff.append("<qcode>");
            xmlBuff.append(cleanup(xmlqual.getCode(), false));
            xmlBuff.append("</qcode>");
            xmlBuff.append("<qname>");
            xmlBuff.append(cleanup(xmlqual.getName(), false));
            xmlBuff.append("</qname>");
            xmlBuff.append("<hasChild>");
            xmlBuff.append(cleanup(xmlqual.getHasChild().toString(), false));
            xmlBuff.append("</hasChild>");
            if (xmlqual.getHasChild() && total_qualifiers < 500) {
                xmlBuff.append("<qchildren>");
                xmlBuff.append(getChildrenXML(xmlqual.getId().toString(), 1, val));
                xmlBuff.append("</qchildren>");
            }
            xmlBuff.append("</qualifier>");
        }
    } else {
        while (qIt.hasNext()) {
            total_qualifiers++;
            xmlqual = (QualRoot) qIt.next();
            if (xmlqual.getHasChild() && total_qualifiers < 500) {
                xmlBuff.append(getChildrenXML(xmlqual.getId().toString(), 1, 1));
            }
        }
    }

    xmlBuff.append("</qualifiers>");
    return xmlBuff.toString();
}

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

/**
 * Select categories which username is authorized to view. 
 *
 * @param userName user's kerberos Id//from   w  ww. ja v a  2 s.c  o  m
 * @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 Collection<ViewableCategory> getViewableCategory(String userName)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == userName)
        throw new InvalidInputException();

    Iterator vIt = null;
    ViewableCategory cat = null;
    String name = userName.trim().toUpperCase();

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

    HibernateTemplate t = getHibernateTemplate();
    Collection<ViewableCategory> cats = null;
    try {
        cats = t.findByNamedQuery("VIEWABLE_CATEGORY_LIST", name);
        //System.out.println(t.toString());
        t.initialize(cats);
    }

    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 (cats == null)
        throw new AuthorizationException("error retrieving viewable categories");

    return cats;
}

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

public Collection<ViewableFunction> getViewableFunctionByCategory(String category)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == category)
        throw new InvalidInputException();

    Iterator vIt = null;//  ww w .java2  s  . c  o  m
    ViewableFunction func = null;
    String cat = category.trim().toUpperCase();

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

    HibernateTemplate t = getHibernateTemplate();
    Collection<ViewableFunction> funcs = null;
    try {
        funcs = t.findByNamedQuery("ALL_FUNCTIONS_FOR_CAT", cat);
        t.initialize(funcs);
    }

    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 (funcs == null)
        throw new AuthorizationException("error retrieving viewable categories");

    return funcs;
}

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

/**
 * retrieve a set of Authorizations by a person's kerberosId, optinally filtering by function_name and function_id
 *
 * @param userName user's kerberos Id//from   w w w.j  a  va2 s  .c om
 * @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
 * @param function_name a function to filter the results by
 * @param function_id a function id to filter the results by
 * @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<Authorization> getUserAuthorizations(String userName, String category, String function_name,
        String function_id, 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();
    String fname = null;
    String fid = null;

    if (null != function_name) {
        fname = function_name.trim().toUpperCase();
        if (fname.length() <= 0) {
            fname = null;
        }
    }
    if (null != function_id) {
        fid = function_id.trim().toUpperCase();
        if (fid.length() <= 0) {
            fid = null;
        }
    }

    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("GET_USERAUTH_SP",
                new String[] { aname, pUser, pname, categoryCode, expand, active, fname, fid });
        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 a selection list by certificate username.
 *
 * @param   username// w  ww  .j ava  2  s  .  c  o m
 * @param   functionName
 * @param   qualifierCode
 * @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 String getAuthEditPermissions(String userName, String functionName, String qualifierCode)
        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();
    try {
        List resp = t.findByNamedQuery("CAN_CREATE_AUTH", new String[] { name, functionName, qualifierCode });
        //t.initialize(resp);

        if (null != resp && resp.size() > 0) {
            String s = (String) resp.get(0);
            return s;

        }
    }

    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());
    }

    return "N";
}

From source file:org.finra.dm.service.impl.JdbcServiceImpl.java

/**
 * Executes a single statement using the given JDBC template. The given statement will be updated with the result and status.
 * /*from w  w w .  j a v a2 s .  c om*/
 * @param jdbcTemplate JDBC template
 * @param jdbcStatement JDBC statement to execute
 * @param variables
 * @param jdbcStatementIndex
 */
private void executeStatement(JdbcTemplate jdbcTemplate, JdbcStatement jdbcStatement,
        Map<String, Object> variables, int jdbcStatementIndex) {
    // This is the exception to be set as the error message in the response
    Throwable exception = null;
    try {
        String sql = evaluate(jdbcStatement.getSql(), variables, "jdbc statement sql");
        validateSqlStatement(sql, jdbcStatementIndex);

        // Process UPDATE type statements
        if (JdbcStatementType.UPDATE.equals(jdbcStatement.getType())) {
            int result = jdbcDao.update(jdbcTemplate, sql);

            jdbcStatement.setStatus(JdbcStatementStatus.SUCCESS);
            jdbcStatement.setResult(String.valueOf(result));
        }
        // Process QUERY type statements
        else if (JdbcStatementType.QUERY.equals(jdbcStatement.getType())) {
            Integer maxResults = configurationHelper.getProperty(ConfigurationValue.JDBC_RESULT_MAX_ROWS,
                    Integer.class);

            JdbcStatementResultSet jdbcStatementResultSet = jdbcDao.query(jdbcTemplate, sql, maxResults);

            jdbcStatement.setStatus(JdbcStatementStatus.SUCCESS);
            jdbcStatement.setResultSet(jdbcStatementResultSet);
        }
        // Any other statement types are unrecognized. This case should not be possible unless developer error.
        else {
            throw new IllegalStateException(
                    "Unsupported JDBC statement type '" + jdbcStatement.getType() + "'");
        }
    } catch (CannotGetJdbcConnectionException cannotGetJdbcConnectionException) {
        /*
         * When the statement fails to execute due to connection errors. This usually indicates that the connection information which was specified is
         * wrong, or there is a network issue. Either way, it would indicate user error.
         * We get the wrapped exception and throw again as an IllegalArgumentException.
         */
        Throwable causeThrowable = cannotGetJdbcConnectionException.getCause();
        throw new IllegalArgumentException(String.valueOf(causeThrowable).trim(),
                cannotGetJdbcConnectionException);
    } catch (DataAccessException dataAccessException) {
        // DataAccessException's cause is a SQLException which is thrown by driver
        // We will use the SQLException message result
        exception = dataAccessException.getCause();
    }

    // If there was an error
    if (exception != null) {
        // Set status to error and result as message
        jdbcStatement.setStatus(JdbcStatementStatus.ERROR);
        jdbcStatement.setErrorMessage(maskSensitiveInformation(exception, variables));
    }
}

From source file:org.orcid.api.t2.server.delegator.impl.T2OrcidApiServiceDelegatorImpl.java

/**
 * Creates a new profile and returns the saved representation of it. The
 * response should include the 'location' to retrieve the newly created
 * profile from.//w  w  w.java  2  s.c  o  m
 * 
 * @param orcidMessage
 *            the message to be saved. If the message already contains an
 *            ORCID value a 400 Bad Request
 * @return if the creation was successful, returns a 201 along with the
 *         location of the newly created resource otherwise returns an error
 *         response describing the problem
 */
@Override
@AccessControl(requiredScope = ScopePathType.ORCID_PROFILE_CREATE)
public Response createProfile(UriInfo uriInfo, OrcidMessage orcidMessage) {
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    try {
        setSponsorFromAuthentication(orcidProfile);
        orcidProfile = orcidProfileManager.createOrcidProfileAndNotify(orcidProfile);
        return getCreatedResponse(uriInfo, PROFILE_GET_PATH, orcidProfile);
    } catch (DataAccessException e) {
        if (e.getCause() != null
                && ConstraintViolationException.class.isAssignableFrom(e.getCause().getClass())) {
            throw new OrcidBadRequestException(
                    localeManager.resolveMessage("apiError.badrequest_email_exists.exception"));
        }
        throw new OrcidBadRequestException(
                localeManager.resolveMessage("apiError.badrequest_createorcid.exception"), e);
    }
}

From source file:org.sipfoundry.sipxconfig.cdr.CdrManagerImpl.java

/**
 * Current implementation only dumps at most m_csvLimit CDRs. This limitation is necessary due
 * to limitations of URLConnection used to download exported data to the client system.
 *
 * See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4212479
 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5026745
 *
 * If we had direct access to that connection we could try calling "setChunkedStreamingMode"
 * on it.//from   www .  j  a v  a2 s.c o m
 */
private void dump(CdrsWriter resultReader, Date from, Date to, CdrSearch search, User user, int limit)
        throws IOException {
    PreparedStatementCreator psc = new SelectAll(from, to, search, user, m_tz, limit, 0);
    try {
        resultReader.writeHeader();
        getJdbcTemplate().query(psc, resultReader);
        resultReader.writeFooter();
    } catch (DataAccessException e) {
        // unwrap IOException that might happen during reading DB
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
        throw e;
    }
}

From source file:org.springframework.jdbc.core.JdbcTemplateTests.java

public void testSqlUpdateEncountersSqlException() throws Exception {
    SQLException sex = new SQLException("bad update");
    final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = 4";

    MockControl ctrlStatement = MockControl.createControl(Statement.class);
    Statement mockStatement = (Statement) ctrlStatement.getMock();
    mockStatement.executeUpdate(sql);//from  ww w  .  java 2  s  . c om
    ctrlStatement.setThrowable(sex);
    mockStatement.close();
    ctrlStatement.setVoidCallable();

    mockConnection.createStatement();
    ctrlConnection.setReturnValue(mockStatement);

    ctrlStatement.replay();
    replay();

    JdbcTemplate template = new JdbcTemplate(mockDataSource);
    try {
        template.update(sql);
    } catch (DataAccessException ex) {
        assertTrue("root cause is correct", ex.getCause() == sex);
    }

    ctrlStatement.verify();
}