org.hibernate.exception.LockAcquisitionException Java Examples

The following examples show how to use org.hibernate.exception.LockAcquisitionException. 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: SQLiteDialect.java    From md_blockchain with Apache License 2.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 int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException) & 0xFF;
            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;
        }
    };
}
 
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 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 #4
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 #5
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 #6
Source File: GemFireXDDialect.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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;
                }
        };
}
 
Example #7
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 #8
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 #9
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 #10
Source File: GemFireXDDialect.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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;
                }
        };
}
 
Example #11
Source File: SqlReportEntitiesPersisterTest.java    From aw-reporting with Apache License 2.0 5 votes vote down vote up
@Test
public void persistReportEntities_retriesAfterDeadlockThenSucceeds() {
  AccountPerformanceReport report = generateReport(1);

  Mockito.doThrow(new LockAcquisitionException("", null))
      .doNothing()
      .when(session)
      .saveOrUpdate(any());

  sqlEntitiesPersister.persistReportEntities(Arrays.asList(report));

  sequence.verify(session, Mockito.times(2)).saveOrUpdate(report);
}
 
Example #12
Source File: SqlReportEntitiesPersisterTest.java    From aw-reporting with Apache License 2.0 5 votes vote down vote up
@Test
public void persistReportEntities_retriesAfterDeadlockThenFails() {
  AccountPerformanceReport report = generateReport(1);

  Mockito.doThrow(new LockAcquisitionException("", null)).when(session).saveOrUpdate(any());

  try {
    sqlEntitiesPersister.persistReportEntities(Arrays.asList(report));
    fail();
  } catch (LockAcquisitionException ex) {
    // expected
  }

  sequence.verify(session, Mockito.times(20)).saveOrUpdate(report);
}
 
Example #13
Source File: TransactionHelperTest.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testExecuteReadWriteTransactionRetry() {
    PASchedulerProperties.SCHEDULER_DB_TRANSACTION_MAXIMUM_RETRIES.updateProperty("5");

    when(sessionWork.doInTransaction(session)).thenThrow(LockAcquisitionException.class)
                                              .thenThrow(Throwable.class)
                                              .thenReturn(null);

    transactionHelper.executeReadWriteTransaction(sessionWork);

    verify(session, times(3)).beginTransaction();
    verify(sessionWork, times(3)).doInTransaction(session);
    verify(transaction, times(2)).rollback();
    verify(transaction).commit();
}
 
Example #14
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 #15
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 #16
Source File: SQLExceptionTypeDelegate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
	if ( SQLClientInfoException.class.isInstance( sqlException )
			|| SQLInvalidAuthorizationSpecException.class.isInstance( sqlException )
			|| SQLNonTransientConnectionException.class.isInstance( sqlException )
			|| SQLTransientConnectionException.class.isInstance( sqlException ) ) {
		return new JDBCConnectionException( message, sqlException, sql );
	}
	else if ( DataTruncation.class.isInstance( sqlException ) ||
			SQLDataException.class.isInstance( sqlException ) ) {
		throw new DataException( message, sqlException, sql );
	}
	else if ( SQLIntegrityConstraintViolationException.class.isInstance( sqlException ) ) {
		return new ConstraintViolationException(
				message,
				sqlException,
				sql,
				getConversionContext().getViolatedConstraintNameExtracter().extractConstraintName( sqlException )
		);
	}
	else if ( SQLSyntaxErrorException.class.isInstance( sqlException ) ) {
		return new SQLGrammarException( message, sqlException, sql );
	}
	else if ( SQLTimeoutException.class.isInstance( sqlException ) ) {
		return new QueryTimeoutException( message, sqlException, sql );
	}
	else if ( SQLTransactionRollbackException.class.isInstance( sqlException ) ) {
		// Not 100% sure this is completely accurate.  The JavaDocs for SQLTransactionRollbackException state that
		// it indicates sql states starting with '40' and that those usually indicate that:
		//		<quote>
		//			the current statement was automatically rolled back by the database because of deadlock or
		// 			other transaction serialization failures.
		//		</quote>
		return new LockAcquisitionException( message, sqlException, sql );
	}

	return null; // allow other delegates the chance to look
}
 
Example #17
Source File: AbstractHANADialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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;
		}
	};
}
 
Example #18
Source File: ODataProductSynchronizer.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean synchronize () throws InterruptedException
{
   int retrieved = 0, updated = 0, deleted = 0;

   LOGGER.info("Synchronizer#" + getId () + " started");
   try
   {
      if (this.copyProduct)
      {
         retrieved = getAndCopyNewProduct();
      }
      else
      {
         retrieved = getNewProducts();
      }
      if (Thread.interrupted ())
      {
         throw new InterruptedException ();
      }

      updated = getUpdatedProducts ();
      if (Thread.interrupted ())
      {
         throw new InterruptedException ();
      }

      deleted = getDeletedProducts ();
   }
   catch (LockAcquisitionException | CannotAcquireLockException e)
   {
      throw new InterruptedException (e.getMessage ());
   }
   finally
   {
      // Logs a summary of what it has done this session
      StringBuilder sb = new StringBuilder ("Synchronizer#");
      sb.append (getId ()).append (" done:    ");
      sb.append (retrieved).append (" new Products,    ");
      sb.append (updated).append (" updated Products,    ");
      sb.append (deleted).append (" deleted Products");
      sb.append ("    from ").append (this.client.getServiceRoot ());
      LOGGER.info(sb.toString());

      // Writes the database only if there is a modification
      if (this.dateChanged)
      {
         SYNC_SERVICE.saveSynchronizer (this);
         this.dateChanged = false;
      }
   }

   return retrieved < pageSize && updated < pageSize && deleted < pageSize;
}
 
Example #19
Source File: Oracle8iDialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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;
		}
	};
}
 
Example #20
Source File: SqlReportEntitiesPersister.java    From aw-reporting with Apache License 2.0 4 votes vote down vote up
/**
 * Persists all the given entities into the DB configured in the {@code SessionFactory}. Specify
 * the following system properties backoff.delay
 */
@Override
@Transactional
@Retryable(
    value = {LockAcquisitionException.class},
    maxAttemptsExpression = "#{ @systemProperties['retryBackoff'] ?: 20}",
    backoff =
        @Backoff(
            delayExpression = "#{ @systemProperties['retryDelay'] ?: 100}",
            maxDelayExpression = "#{ @systemProperties['retryMaxDelay'] ?: 50000 }",
            multiplierExpression = "#{ @systemProperties['retryMultiplier'] ?: 1.5}"))
public void persistReportEntities(List<? extends Report> reportEntities) {
  int batchFlush = 0;
  Session session = sessionFactory.getCurrentSession();
  FlushMode previousFlushMode = session.getHibernateFlushMode();
  session.setHibernateFlushMode(FlushMode.MANUAL);

  try {
    for (Report report : reportEntities) {
      report.setRowId();

      session.saveOrUpdate(report);
      batchFlush++;

      if (batchFlush == config.getBatchSize()) {
        session.flush();
        session.clear();
        batchFlush = 0;
      }
    }

    if (batchFlush > 0) {
      session.flush();
      session.clear();
    }
  } catch (NonUniqueObjectException ex) {
    // Github issue 268 & 280
    //   https://github.com/googleads/aw-reporting/issues/268
    //   https://github.com/googleads/aw-reporting/issues/280
    //
    // Currently we allow specifying report definitions which do not include all primary key
    // fields. This leads to cryptic hibernate errors without providing a reasonable
    // resolution strategy.
    //
    // This fix explains where to find the list of primary key fields, but does not address
    // the underlying issue of allowing non-unique rows to be downloaded in the first place.
    //
    // Ideally we would guarantee uniqueness of rows without the user having to specify the
    // PK fields.
    // However, this would be a substantial migration for the AWReporting user base.
    // Instead, we just log a (hopefully) useful error message.
    // Also note that the error message assumes that reportEntities was not empty, because
    // otherwise the exception would not have been thrown.
    logger.error(
        "Duplicate row detected. This is most likely because your report definition does not "
            + "include the primary key fields defined in {}.setRowId(). "
            + "Please add the missing fields and try again.",
        reportEntities.get(0).getClass().getName());
    throw ex;
  } finally {
    session.setHibernateFlushMode(previousFlushMode);
  }
}
 
Example #21
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;
}