Java 类org.hibernate.exception.spi.SQLExceptionConversionDelegate 实例源码

项目:lams    文件:SybaseASE157Dialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
            final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
            if("JZ0TO".equals( sqlState ) || "JZ006".equals( sqlState )){
                throw new LockTimeoutException( message, sqlException, sql );
            }
            if ( 515 == errorCode && "ZZZZZ".equals( sqlState ) ) {
                // Attempt to insert NULL value into column; column does not allow nulls.
                final String constraintName = getViolatedConstraintNameExtracter().extractConstraintName( sqlException );
                return new ConstraintViolationException( message, sqlException, sql, constraintName );
            }
            return null;
        }
    };
}
项目:lams    文件:SQLServer2005Dialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
            final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
            if ( "HY008".equals( sqlState ) ) {
                throw new QueryTimeoutException( message, sqlException, sql );
            }
            if (1222 == errorCode ) {
                throw new LockTimeoutException( message, sqlException, sql );
            }
            return null;
        }
    };
}
项目:lams    文件:PostgreSQL81Dialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );

            if ( "40P01".equals( sqlState ) ) {
                // DEADLOCK DETECTED
                return new LockAcquisitionException( message, sqlException, sql );
            }

            if ( "55P03".equals( sqlState ) ) {
                // LOCK NOT AVAILABLE
                return new PessimisticLockException( message, sqlException, sql );
            }

            // returning null allows other delegates to operate
            return null;
        }
    };
}
项目:hibernate4-sqlite-dialect    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        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);
        }
    };
}
项目:vsDiaryWriter    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
            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);
            }

            // returning null allows other delegates to operate
            return null;
        }
    };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
        return new SQLExceptionConversionDelegate() {
                @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;
                }
        };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
        return new SQLExceptionConversionDelegate() {
                @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;
                }
        };
}
项目:spletne-seje    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
            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 null;
        }
    };
}
项目:Introspect-Framework    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
  return new SQLExceptionConversionDelegate() {
    @Override
    public JDBCException convert(SQLException sqlException, String message, String sql) {
      final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
      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);
      }

      // returning null allows other delegates to operate
      return null;
    }
  };
}
项目:lams    文件:StandardSQLExceptionConverter.java   
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
    for ( SQLExceptionConversionDelegate delegate : delegates ) {
        final JDBCException jdbcException = delegate.convert( sqlException, message, sql );
        if ( jdbcException != null ) {
            return jdbcException;
        }
    }
    return new GenericJDBCException( message, sqlException, sql );
}
项目:lams    文件:DB2Dialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
            final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );

            if( -952 == errorCode && "57014".equals( sqlState )){
                throw new LockTimeoutException( message, sqlException, sql );
            }
            return null;
        }
    };
}
项目:sqlite-dialect    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLiteSQLExceptionConversionDelegate();
}
项目:lams    文件:StandardSQLExceptionConverter.java   
public void addDelegate(SQLExceptionConversionDelegate delegate) {
    if ( delegate != null ) {
        this.delegates.add( delegate );
    }
}
项目:lams    文件:MySQLDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );

            if ( "41000".equals( sqlState ) ) {
                return new LockTimeoutException( message, sqlException, sql );
            }

            if ( "40001".equals( sqlState ) ) {
                return new LockAcquisitionException( message, sqlException, sql );
            }

            return null;
        }
    };
}
项目:lams    文件:Oracle8iDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            // interpreting Oracle exceptions is much much more precise based on their specific vendor codes.

            final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );


            // lock timeouts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            if ( errorCode == 30006 ) {
                // ORA-30006: resource busy; acquire with WAIT timeout expired
                throw new LockTimeoutException( message, sqlException, sql );
            }
            else if ( errorCode == 54 ) {
                // ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
                throw new LockTimeoutException( message, sqlException, sql );
            }
            else if ( 4021 == errorCode ) {
                // ORA-04021 timeout occurred while waiting to lock object
                throw new LockTimeoutException( message, sqlException, sql );
            }


            // deadlocks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            if ( 60 == errorCode ) {
                // ORA-00060: deadlock detected while waiting for resource
                return new LockAcquisitionException( message, sqlException, sql );
            }
            else if ( 4020 == errorCode ) {
                // ORA-04020 deadlock detected while trying to lock object
                return new LockAcquisitionException( message, sqlException, sql );
            }


            // query cancelled ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            if ( 1013 == errorCode ) {
                // ORA-01013: user requested cancel of current operation
                throw new QueryTimeoutException(  message, sqlException, sql );
            }


            // data integrity violation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            if ( 1407 == errorCode ) {
                // ORA-01407: cannot update column to NULL
                final String constraintName = getViolatedConstraintNameExtracter().extractConstraintName( sqlException );
                return new ConstraintViolationException( message, sqlException, sql, constraintName );
            }

            return null;
        }
    };
}
项目:lams    文件:Cache71Dialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new CacheSQLExceptionConversionDelegate( this );
}
项目:lams    文件:AbstractHANADialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(final SQLException sqlException, final String message, final String sql) {

            final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );

            if ( errorCode == 131 ) {
                // 131 - Transaction rolled back by lock wait timeout
                return new LockTimeoutException( message, sqlException, sql );
            }

            if ( errorCode == 146 ) {
                // 146 - Resource busy and acquire with NOWAIT specified
                return new LockTimeoutException( message, sqlException, sql );
            }

            if ( errorCode == 132 ) {
                // 132 - Transaction rolled back due to unavailable resource
                return new LockAcquisitionException( message, sqlException, sql );
            }

            if ( errorCode == 133 ) {
                // 133 - Transaction rolled back by detected deadlock
                return new LockAcquisitionException( message, sqlException, sql );
            }

            // 259 - Invalid table name
            // 260 - Invalid column name
            // 261 - Invalid index name
            // 262 - Invalid query name
            // 263 - Invalid alias name
            if ( errorCode == 257 || ( errorCode >= 259 && errorCode <= 263 ) ) {
                throw new SQLGrammarException( message, sqlException, sql );
            }

            // 257 - Cannot insert NULL or update to NULL
            // 301 - Unique constraint violated
            // 461 - foreign key constraint violation
            // 462 - failed on update or delete by foreign key constraint violation
            if ( errorCode == 287 || errorCode == 301 || errorCode == 461 || errorCode == 462 ) {
                final String constraintName = getViolatedConstraintNameExtracter().extractConstraintName(
                        sqlException );

                return new ConstraintViolationException( message, sqlException, sql, constraintName );
            }

            return null;
        }
    };
}
项目:org.fastnate    文件:AllowMissingIdentitySupportDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return this.wrapped.buildSQLExceptionConversionDelegate();
}
项目:lams    文件:Dialect.java   
/**
 * Build an instance of a {@link SQLExceptionConversionDelegate} for
 * interpreting dialect-specific error or SQLState codes.
 * <p/>
 * When {@link #buildSQLExceptionConverter} returns null, the default 
 * {@link SQLExceptionConverter} is used to interpret SQLState and
 * error codes. If this method is overridden to return a non-null value,
 * the default {@link SQLExceptionConverter} will use the returned
 * {@link SQLExceptionConversionDelegate} in addition to the following 
 * standard delegates:
 * <ol>
 *     <li>a "static" delegate based on the JDBC 4 defined SQLException hierarchy;</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/>
 * It is strongly recommended that specific Dialect implementations override this
 * method, since interpretation of a SQL error is much more accurate when based on
 * the a vendor-specific ErrorCode rather than the SQLState.
 * <p/>
 * Specific Dialects may override to return whatever is most appropriate for that vendor.
 *
 * @return The SQLExceptionConversionDelegate for this dialect
 */
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return null;
}