org.hibernate.PessimisticLockException Java Examples

The following examples show how to use org.hibernate.PessimisticLockException. 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: PostgreSQL81Dialect.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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;
		}
	};
}
 
Example #2
Source File: MySQLDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
	return new SQLExceptionConversionDelegate() {
		@Override
		public JDBCException convert(SQLException sqlException, String message, String sql) {
			switch ( sqlException.getErrorCode() ) {
				case 1205: {
					return new PessimisticLockException( message, sqlException, sql );
				}
				case 1207:
				case 1206: {
					return new LockAcquisitionException( message, sqlException, 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;
		}
	};
}
 
Example #3
Source File: SQLStateConversionDelegate.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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;
}