本文整理汇总了Java中org.hibernate.exception.LockAcquisitionException类的典型用法代码示例。如果您正苦于以下问题:Java LockAcquisitionException类的具体用法?Java LockAcquisitionException怎么用?Java LockAcquisitionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LockAcquisitionException类属于org.hibernate.exception包,在下文中一共展示了LockAcquisitionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSQLExceptionConversionDelegate
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@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;
}
};
}
示例2: buildSQLExceptionConversionDelegate
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@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;
}
};
}
示例3: buildSQLExceptionConverter
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@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;
}
};
}
示例4: buildSQLExceptionConversionDelegate
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
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;
}
};
}
示例5: buildSQLExceptionConverter
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@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;
}
};
}
示例6: buildSQLExceptionConversionDelegate
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@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;
}
};
}
示例7: buildSQLExceptionConversionDelegate
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@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;
}
};
}
示例8: buildSQLExceptionConverter
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@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);
}
};
}
示例9: isLockingException
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
private static boolean isLockingException(final Throwable t, final boolean recurse) {
if (t instanceof LockingException || t instanceof LockAcquisitionException || t instanceof PessimisticLockException) {
return true;
}
if (t instanceof SQLException) {
final SQLException e = (SQLException) t;
return e.getErrorCode() == ER_LOCK_WAIT_TIMEOUT || ST_LOCK.equals(e.getSQLState());
}
if (recurse) {
for (final Throwable thr : ExceptionUtils.getThrowables(t)) {
if (isLockingException(thr, false)) {
return true;
}
}
}
return false;
}
示例10: convert
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
if (errorCode == SQLITE_CONSTRAINT) {
final String constraintName = EXTRACTER.extractConstraintName(sqlException);
return new ConstraintViolationException(message, sqlException, sql, constraintName);
} else if (errorCode == SQLITE_TOO_BIG || 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_IO_ERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOT_ADB) {
return new JDBCConnectionException(message, sqlException, sql);
}
return new GenericJDBCException(message, sqlException, sql);
}
示例11: returnsLockAcquisitionExceptionForSqliteBusy
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@Test
public void returnsLockAcquisitionExceptionForSqliteBusy() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(5);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
assertTrue(exception instanceof LockAcquisitionException);
assertEquals("message", exception.getMessage());
assertEquals("sql", exception.getSQL());
}
示例12: returnsLockAcquisitionExceptionForSqliteLocked
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@Test
public void returnsLockAcquisitionExceptionForSqliteLocked() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(6);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
assertTrue(exception instanceof LockAcquisitionException);
assertEquals("message", exception.getMessage());
assertEquals("sql", exception.getSQL());
}
示例13: convert
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
@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
}
示例14: isLockingException
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
private static boolean isLockingException(Throwable throwable) {
for (Throwable t = throwable; t != null; t = t.getCause()) {
if (t instanceof StaleStateException || t instanceof LockAcquisitionException) {
return true;
}
}
return false;
}
示例15: lockBatch
import org.hibernate.exception.LockAcquisitionException; //导入依赖的package包/类
/**
* API to get a batch by applying Hibernate level optimistic locking and to set lock owner ino db.
*
* @param identifier long
* @param lockOwner {@link ServerRegistry}
* @throws LockAcquisitionException in case of error
*/
@Transactional
@Override
public void lockBatch(long batchId, ServerRegistry lockOwner) throws LockAcquisitionException {
BatchInstance batchInstance = batchInstanceDao.getBatch(batchId, LockMode.UPGRADE_NOWAIT);
if (batchInstance.getLockOwner() == null) {
batchInstance.setLockOwner(lockOwner);
batchInstanceDao.saveOrUpdate(batchInstance);
} else {
throw new LockAcquisitionException(DataAccessConstant.BATCH_ALREADY_LOCKED, null);
}
}