Here are the examples of the java api org.hibernate.JDBCException taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
15 Examples
19
Source : SQLiteSQLExceptionConversionDelegateTest.java
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
@Test
public void returnsJDBCConnectionExceptionForSqliteNotAbd() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(26);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
replacedertTrue(exception instanceof JDBCConnectionException);
replacedertEquals("message", exception.getMessage());
replacedertEquals("sql", exception.getSQL());
}
19
Source : SQLiteSQLExceptionConversionDelegateTest.java
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
@Test
public void returnsDataExceptionForSqliteTooBigError() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(18);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
replacedertTrue(exception instanceof DataException);
replacedertEquals("message", exception.getMessage());
replacedertEquals("sql", exception.getSQL());
}
19
Source : SQLiteSQLExceptionConversionDelegateTest.java
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
@Test
public void returnsDataExceptionForSqliteMismatch() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(20);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
replacedertTrue(exception instanceof DataException);
replacedertEquals("message", exception.getMessage());
replacedertEquals("sql", exception.getSQL());
}
19
Source : SQLiteSQLExceptionConversionDelegateTest.java
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
@Test
public void returnsLockAcquisitionExceptionForSqliteLocked() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(6);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
replacedertTrue(exception instanceof LockAcquisitionException);
replacedertEquals("message", exception.getMessage());
replacedertEquals("sql", exception.getSQL());
}
19
Source : SQLiteSQLExceptionConversionDelegateTest.java
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
@Test
public void returnsConstraintViolationException() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(19);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
replacedertTrue(exception instanceof ConstraintViolationException);
replacedertEquals("message", exception.getMessage());
replacedertEquals("sql", exception.getSQL());
}
19
Source : SQLiteSQLExceptionConversionDelegateTest.java
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
@Test
public void returnsLockAcquisitionExceptionForSqliteBusy() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(5);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
replacedertTrue(exception instanceof LockAcquisitionException);
replacedertEquals("message", exception.getMessage());
replacedertEquals("sql", exception.getSQL());
}
19
Source : SQLiteSQLExceptionConversionDelegateTest.java
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
@Test
public void returnsJDBCConnectionExceptionForSqliteCorrupt() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(11);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
replacedertTrue(exception instanceof JDBCConnectionException);
replacedertEquals("message", exception.getMessage());
replacedertEquals("sql", exception.getSQL());
}
19
Source : SQLiteSQLExceptionConversionDelegateTest.java
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
with BSD 3-Clause "New" or "Revised" License
from ZsoltFabok
@Test
public void returnsGenericJDBCExceptionForEverythingElse() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(41);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
replacedertTrue(exception instanceof GenericJDBCException);
replacedertEquals("message", exception.getMessage());
replacedertEquals("sql", exception.getSQL());
}
19
Source : SpringSessionSynchronization.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
private DataAccessException translateException(HibernateException ex) {
if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
JDBCException jdbcEx = (JDBCException) ex;
return this.jdbcExceptionTranslator.translate("Hibernate flushing: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException());
}
return SessionFactoryUtils.convertHibernateAccessException(ex);
}
19
Source : HibernateExceptionTranslator.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Convert the given HibernateException to an appropriate exception from the
* {@code org.springframework.dao} hierarchy.
* <p>Will automatically apply a specified SQLExceptionTranslator to a
* Hibernate JDBCException, else rely on Hibernate's default translation.
* @param ex HibernateException that occured
* @return a corresponding DataAccessException
* @see SessionFactoryUtils#convertHibernateAccessException
* @see #setJdbcExceptionTranslator
*/
protected DataAccessException convertHibernateAccessException(HibernateException ex) {
if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
JDBCException jdbcEx = (JDBCException) ex;
return this.jdbcExceptionTranslator.translate("Hibernate operation: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException());
}
return SessionFactoryUtils.convertHibernateAccessException(ex);
}
18
Source : HibernateExceptionTranslator.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Convert the given HibernateException to an appropriate exception from the
* {@code org.springframework.dao} hierarchy.
* <p>Will automatically apply a specified SQLExceptionTranslator to a
* Hibernate JDBCException, otherwise rely on Hibernate's default translation.
* @param ex the HibernateException that occurred
* @return a corresponding DataAccessException
* @see SessionFactoryUtils#convertHibernateAccessException
*/
protected DataAccessException convertHibernateAccessException(HibernateException ex) {
if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
JDBCException jdbcEx = (JDBCException) ex;
DataAccessException dae = this.jdbcExceptionTranslator.translate("Hibernate operation: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException());
if (dae != null) {
throw dae;
}
}
return SessionFactoryUtils.convertHibernateAccessException(ex);
}
18
Source : HibernateTransactionManager.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Convert the given Hibernate JDBCException to an appropriate exception
* from the {@code org.springframework.dao} hierarchy, using the
* given SQLExceptionTranslator.
* @param ex Hibernate JDBCException that occurred
* @param translator the SQLExceptionTranslator to use
* @return a corresponding DataAccessException
*/
protected DataAccessException convertJdbcAccessException(JDBCException ex, SQLExceptionTranslator translator) {
return translator.translate("Hibernate flushing: " + ex.getMessage(), ex.getSQL(), ex.getSQLException());
}
18
Source : HibernateAccessor.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Convert the given Hibernate JDBCException to an appropriate exception
* from the {@code org.springframework.dao} hierarchy, using the
* given SQLExceptionTranslator.
* @param ex Hibernate JDBCException that occured
* @param translator the SQLExceptionTranslator to use
* @return a corresponding DataAccessException
*/
protected DataAccessException convertJdbcAccessException(JDBCException ex, SQLExceptionTranslator translator) {
return translator.translate("Hibernate operation: " + ex.getMessage(), ex.getSQL(), ex.getSQLException());
}
17
Source : StandardSQLExceptionConverter.java
with GNU General Public License v2.0
from lamsfoundation
with GNU General Public License v2.0
from lamsfoundation
@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);
}
15
Source : HibernateJpaDialect.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Convert the given HibernateException to an appropriate exception
* from the {@code org.springframework.dao} hierarchy.
* @param ex the HibernateException that occurred
* @return the corresponding DataAccessException instance
*/
protected DataAccessException convertHibernateAccessException(HibernateException ex) {
if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
JDBCException jdbcEx = (JDBCException) ex;
DataAccessException dae = this.jdbcExceptionTranslator.translate("Hibernate operation: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException());
if (dae != null) {
throw dae;
}
}
if (ex instanceof JDBCConnectionException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
if (ex instanceof SQLGrammarException) {
SQLGrammarException jdbcEx = (SQLGrammarException) ex;
return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof QueryTimeoutException) {
QueryTimeoutException jdbcEx = (QueryTimeoutException) ex;
return new org.springframework.dao.QueryTimeoutException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof LockAcquisitionException) {
LockAcquisitionException jdbcEx = (LockAcquisitionException) ex;
return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof PessimisticLockException) {
PessimisticLockException jdbcEx = (PessimisticLockException) ex;
return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof ConstraintViolationException) {
ConstraintViolationException jdbcEx = (ConstraintViolationException) ex;
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
}
if (ex instanceof DataException) {
DataException jdbcEx = (DataException) ex;
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
// end of JDBCException subclreplaced handling
if (ex instanceof QueryException) {
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
}
if (ex instanceof NonUniqueResultException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
}
if (ex instanceof NonUniqueObjectException) {
return new DuplicateKeyException(ex.getMessage(), ex);
}
if (ex instanceof PropertyValueException) {
return new DataIntegrityViolationException(ex.getMessage(), ex);
}
if (ex instanceof PersistentObjectException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof TransientObjectException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof ObjectDeletedException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof UnresolvableObjectException) {
UnresolvableObjectException hibEx = (UnresolvableObjectException) ex;
return new ObjectRetrievalFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex.getMessage(), ex);
}
if (ex instanceof WrongClreplacedException) {
WrongClreplacedException hibEx = (WrongClreplacedException) ex;
return new ObjectRetrievalFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex.getMessage(), ex);
}
if (ex instanceof StaleObjectStateException) {
StaleObjectStateException hibEx = (StaleObjectStateException) ex;
return new ObjectOptimisticLockingFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex);
}
if (ex instanceof StaleStateException) {
return new ObjectOptimisticLockingFailureException(ex.getMessage(), ex);
}
if (ex instanceof OptimisticEnreplacedyLockException) {
return new ObjectOptimisticLockingFailureException(ex.getMessage(), ex);
}
if (ex instanceof PessimisticEnreplacedyLockException) {
if (ex.getCause() instanceof LockAcquisitionException) {
return new CannotAcquireLockException(ex.getMessage(), ex.getCause());
}
return new PessimisticLockingFailureException(ex.getMessage(), ex);
}
// fallback
return new JpaSystemException(ex);
}