org.hibernate.exception.spi.SQLExceptionConverter Java Examples

The following examples show how to use org.hibernate.exception.spi.SQLExceptionConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GemFireXDDialect.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
        return new SQLExceptionConverter() {
                @Override
                public JDBCException convert(SQLException sqlException,
                                String message, String sql) {
                        final String sqlState = JdbcExceptionHelper
                                        .extractSqlState(sqlException);
                        if (sqlState != null) {
                                if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
                                        return new SQLGrammarException(message, sqlException,
                                                        sql);
                                } else if (DATA_CATEGORIES.contains(sqlState)) {
                                        return new DataException(message, sqlException, sql);
                                } else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
                                        return new LockAcquisitionException(message,
                                                        sqlException, sql);
                                }
                        }
                        return null;
                }
        };
}
 
Example #2
Source File: SQLiteDialect.java    From yeti with MIT License 6 votes vote down vote up
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
    return new SQLExceptionConverter() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final int errorCode = sqlException.getErrorCode();
            if (errorCode == SQLITE_CONSTRAINT) {
                final String constraintName = EXTRACTER.extractConstraintName(sqlException);
                return new ConstraintViolationException(message, sqlException, sql, constraintName);
            } else if (errorCode == SQLITE_TOOBIG || errorCode == SQLITE_MISMATCH) {
                return new DataException(message, sqlException, sql);
            } else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) {
                return new LockAcquisitionException(message, sqlException, sql);
            } else if ((errorCode >= SQLITE_IOERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOTADB) {
                return new JDBCConnectionException(message, sqlException, sql);
            }
            return new GenericJDBCException(message, sqlException, sql);
        }
    };
}
 
Example #3
Source File: GemFireXDDialect.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
        return new SQLExceptionConverter() {
                @Override
                public JDBCException convert(SQLException sqlException,
                                String message, String sql) {
                        final String sqlState = JdbcExceptionHelper
                                        .extractSqlState(sqlException);
                        if (sqlState != null) {
                                if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
                                        return new SQLGrammarException(message, sqlException,
                                                        sql);
                                } else if (DATA_CATEGORIES.contains(sqlState)) {
                                        return new DataException(message, sqlException, sql);
                                } else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
                                        return new LockAcquisitionException(message,
                                                        sqlException, sql);
                                }
                        }
                        return null;
                }
        };
}
 
Example #4
Source File: AbstractCollectionPersister.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected SQLExceptionConverter getSQLExceptionConverter() {
	return getSQLExceptionHelper().getSqlExceptionConverter();
}
 
Example #5
Source File: SessionFactoryDelegatingImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public SQLExceptionConverter getSQLExceptionConverter() {
	return delegate.getSQLExceptionConverter();
}
 
Example #6
Source File: SessionFactoryWrapper.java    From lemon with Apache License 2.0 4 votes vote down vote up
public SQLExceptionConverter getSQLExceptionConverter() {
    return sessionFactoryImplementor.getSQLExceptionConverter();
}
 
Example #7
Source File: DelegatingDialect.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public SQLExceptionConverter buildSQLExceptionConverter() {
    return getInstance().buildSQLExceptionConverter();
}
 
Example #8
Source File: SqlExceptionHelper.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create an exception helper with a specific exception converter.
 *
 * @param sqlExceptionConverter The exception converter to use.
 */
public SqlExceptionHelper(SQLExceptionConverter sqlExceptionConverter, boolean logWarnings) {
	this.sqlExceptionConverter = sqlExceptionConverter;
	this.logWarnings = logWarnings;
}
 
Example #9
Source File: SqlExceptionHelper.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Access the current exception converter being used internally.
 *
 * @return The current exception converter.
 */
public SQLExceptionConverter getSqlExceptionConverter() {
	return sqlExceptionConverter;
}
 
Example #10
Source File: SqlExceptionHelper.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Inject the exception converter to use.
 * <p/>
 * NOTE : <tt>null</tt> is allowed and signifies to use the default.
 *
 * @param sqlExceptionConverter The converter to use.
 */
public void setSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter) {
	this.sqlExceptionConverter = ( sqlExceptionConverter == null ? DEFAULT_CONVERTER : sqlExceptionConverter );
}
 
Example #11
Source File: SessionFactoryImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Retrieves the SQLExceptionConverter in effect for this SessionFactory.
 *
 * @return The SQLExceptionConverter for this SessionFactory.
 *
 * @deprecated since 5.0; use {@link JdbcServices#getSqlExceptionHelper()} ->
 * {@link SqlExceptionHelper#getSqlExceptionConverter()} instead as obtained from {@link #getServiceRegistry()}
 */
@Deprecated
default SQLExceptionConverter getSQLExceptionConverter() {
	return getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().getSqlExceptionConverter();
}
 
Example #12
Source File: Dialect.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Build an instance of the SQLExceptionConverter preferred by this dialect for
 * converting SQLExceptions into Hibernate's JDBCException hierarchy.
 * <p/>
 * The preferred method is to not override this method; if possible,
 * {@link #buildSQLExceptionConversionDelegate()} should be overridden
 * instead.
 *
 * If this method is not overridden, the default SQLExceptionConverter
 * implementation executes 3 SQLException converter delegates:
 * <ol>
 *     <li>a "static" delegate based on the JDBC 4 defined SQLException hierarchy;</li>
 *     <li>the vendor-specific delegate returned by {@link #buildSQLExceptionConversionDelegate()};
 *         (it is strongly recommended that specific Dialect implementations
 *         override {@link #buildSQLExceptionConversionDelegate()})</li>
 *     <li>a delegate that interprets SQLState codes for either X/Open or SQL-2003 codes,
 *         depending on java.sql.DatabaseMetaData#getSQLStateType</li>
 * </ol>
 * <p/>
 * If this method is overridden, it is strongly recommended that the
 * returned {@link SQLExceptionConverter} interpret SQL errors based on
 * vendor-specific error codes rather than the SQLState since the
 * interpretation is more accurate when using vendor-specific ErrorCodes.
 *
 * @return The Dialect's preferred SQLExceptionConverter, or null to
 * indicate that the default {@link SQLExceptionConverter} should be used.
 *
 * @see {@link #buildSQLExceptionConversionDelegate()}
 * @deprecated {@link #buildSQLExceptionConversionDelegate()} should be
 * overridden instead.
 */
@Deprecated
public SQLExceptionConverter buildSQLExceptionConverter() {
	return null;
}