Example usage for org.hibernate.exception ConstraintViolationException ConstraintViolationException

List of usage examples for org.hibernate.exception ConstraintViolationException ConstraintViolationException

Introduction

In this page you can find the example usage for org.hibernate.exception ConstraintViolationException ConstraintViolationException.

Prototype

public ConstraintViolationException(String message, SQLException root, String sql, String constraintName) 

Source Link

Usage

From source file:com.enigmabridge.hibernate.dialect.SQLiteDialect.java

License:unlicense.org

@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override//from   ww w. j  a  va  2  s .  c o m
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final int errorCode = org.hibernate.internal.util.JdbcExceptionHelper
                    .extractErrorCode(sqlException);
            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);
        }
    };
}