Search in sources :

Example 1 with DataException

use of org.hibernate.exception.DataException in project hibernate-orm by hibernate.

the class SQLStateConversionDelegate method convert.

@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
    final String sqlState = JdbcExceptionHelper.extractSqlState(sqlException);
    final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
    if (sqlState != null) {
        String sqlStateClassCode = JdbcExceptionHelper.determineSqlStateClassCode(sqlState);
        if (sqlStateClassCode != null) {
            if (SQL_GRAMMAR_CATEGORIES.contains(sqlStateClassCode)) {
                return new SQLGrammarException(message, sqlException, sql);
            } else if (INTEGRITY_VIOLATION_CATEGORIES.contains(sqlStateClassCode)) {
                final String constraintName = getConversionContext().getViolatedConstraintNameExtracter().extractConstraintName(sqlException);
                return new ConstraintViolationException(message, sqlException, sql, constraintName);
            } else if (CONNECTION_CATEGORIES.contains(sqlStateClassCode)) {
                return new JDBCConnectionException(message, sqlException, sql);
            } else if (DATA_CATEGORIES.contains(sqlStateClassCode)) {
                return new DataException(message, sqlException, sql);
            }
        }
        if ("40001".equals(sqlState)) {
            return new LockAcquisitionException(message, sqlException, sql);
        }
        if ("40XL1".equals(sqlState) || "40XL2".equals(sqlState)) {
            // Derby "A lock could not be obtained within the time requested."
            return new PessimisticLockException(message, sqlException, sql);
        }
        // MySQL Query execution was interrupted
        if ("70100".equals(sqlState) || // Oracle user requested cancel of current operation
        ("72000".equals(sqlState) && errorCode == 1013)) {
            throw new QueryTimeoutException(message, sqlException, sql);
        }
    }
    return null;
}
Also used : DataException(org.hibernate.exception.DataException) QueryTimeoutException(org.hibernate.QueryTimeoutException) JDBCConnectionException(org.hibernate.exception.JDBCConnectionException) SQLGrammarException(org.hibernate.exception.SQLGrammarException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) PessimisticLockException(org.hibernate.PessimisticLockException)

Example 2 with DataException

use of org.hibernate.exception.DataException in project Asqatasun by Asqatasun.

the class CSSJsoupPhlocContentAdapterImpl method adaptExternalCss.

/**
     * Adapt the external css. 
     */
private void adaptExternalCss() {
    for (Element el : externalCssElements) {
        List<CSSMediaQuery> mediaList = getListOfMediaFromAttributeValue(el);
        String resourcePath = el.attr("abs:href");
        getExternalResourceAndAdapt(resourcePath, mediaList);
    }
    Set<Long> relatedCssIdSet = new HashSet<>();
    // At the end of the document we link each external css that are
    // already fetched and that have been encountered in the SSP to the SSP.
    LOGGER.debug("Found " + relatedExternalCssSet.size() + " external css in " + getSSP().getURI());
    for (StylesheetContent cssContent : relatedExternalCssSet) {
        if (cssContent.getAdaptedContent() == null) {
            cssContent.setAdaptedContent(CSS_ON_ERROR);
        }
        LOGGER.debug("Create relation between " + getSSP().getURI() + " and " + cssContent.getURI());
        // to avoid fatal error when persist weird sourceCode
        try {
            // with the current SSP
            if (cssContent.getId() == null) {
                cssContent = (StylesheetContent) getContentDataService().saveOrUpdate(cssContent);
            }
            relatedCssIdSet.add(cssContent.getId());
        } catch (PersistenceException | DataException pe) {
            adaptedContentOnError(cssContent, relatedCssIdSet);
        }
    }
    getContentDataService().saveContentRelationShip(getSSP(), relatedCssIdSet);
}
Also used : CSSMediaQuery(com.phloc.css.decl.CSSMediaQuery) StylesheetContent(org.asqatasun.entity.audit.StylesheetContent) DataException(org.hibernate.exception.DataException) Element(org.jsoup.nodes.Element) PersistenceException(javax.persistence.PersistenceException)

Aggregations

DataException (org.hibernate.exception.DataException)2 CSSMediaQuery (com.phloc.css.decl.CSSMediaQuery)1 PersistenceException (javax.persistence.PersistenceException)1 StylesheetContent (org.asqatasun.entity.audit.StylesheetContent)1 PessimisticLockException (org.hibernate.PessimisticLockException)1 QueryTimeoutException (org.hibernate.QueryTimeoutException)1 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)1 JDBCConnectionException (org.hibernate.exception.JDBCConnectionException)1 LockAcquisitionException (org.hibernate.exception.LockAcquisitionException)1 SQLGrammarException (org.hibernate.exception.SQLGrammarException)1 Element (org.jsoup.nodes.Element)1