Example usage for org.hibernate.internal.util JdbcExceptionHelper extractSqlState

List of usage examples for org.hibernate.internal.util JdbcExceptionHelper extractSqlState

Introduction

In this page you can find the example usage for org.hibernate.internal.util JdbcExceptionHelper extractSqlState.

Prototype

public static String extractSqlState(SQLException sqlException) 

Source Link

Document

For the given SQLException, locates the X/Open-compliant SQLState.

Usage

From source file:com.vmware.sqlfire.hibernate.SQLFireDialect.java

License:Open Source License

public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override/*  w w w.  j  a  v  a2s  . c om*/
        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;
        }
    };
}

From source file:com.vmware.sqlfire.hibernate.v4.v0.SQLFireDialect.java

License:Open Source License

@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
    return new SQLExceptionConverter() {
        @Override//from  w  ww . ja  v  a 2  s .c  o m
        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 new JDBCException(message, sqlException, sql);
        }
    };
}