-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc1c801
commit ac939f0
Showing
157 changed files
with
2,994 additions
and
2,389 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...-hibernate-5/src/test/java/io/hypersistence/utils/hibernate/util/DataSourceProxyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...l/logging/InlineQueryLogEntryCreator.java → ...s/logging/InlineQueryLogEntryCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...hibernate-52/src/test/java/io/hypersistence/utils/hibernate/util/DataSourceProxyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...l/logging/InlineQueryLogEntryCreator.java → ...s/logging/InlineQueryLogEntryCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rc/test/java/io/hypersistence/utils/spring/config/AbstractSpringDataJPAConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...hibernate-55/src/test/java/io/hypersistence/utils/hibernate/util/DataSourceProxyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...l/logging/InlineQueryLogEntryCreator.java → ...s/logging/InlineQueryLogEntryCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rc/test/java/io/hypersistence/utils/spring/config/AbstractSpringDataJPAConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tils/hibernate/util/ClassLoaderUtils.java → ...stence/utils/common/ClassLoaderUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
...istence-utils-hibernate-60/src/main/java/io/hypersistence/utils/common/ExceptionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package io.hypersistence.utils.common; | ||
|
||
import jakarta.persistence.LockTimeoutException; | ||
import org.hibernate.PessimisticLockException; | ||
import org.hibernate.exception.LockAcquisitionException; | ||
|
||
import java.sql.SQLTimeoutException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
/** | ||
* @author Vlad Mihalcea | ||
*/ | ||
public interface ExceptionUtil { | ||
|
||
List<Class<? extends Exception>> LOCK_TIMEOUT_EXCEPTIONS = Arrays.asList( | ||
LockAcquisitionException.class, | ||
LockTimeoutException.class, | ||
PessimisticLockException.class, | ||
jakarta.persistence.PessimisticLockException.class, | ||
SQLTimeoutException.class | ||
); | ||
|
||
/** | ||
* Get the root cause of a particular {@code Throwable} | ||
* | ||
* @param t exception | ||
* @return exception root cause | ||
*/ | ||
static <T extends Throwable> T rootCause(Throwable t) { | ||
Throwable cause = t.getCause(); | ||
if (cause != null && cause != t) { | ||
return rootCause(cause); | ||
} | ||
return (T) t; | ||
} | ||
|
||
/** | ||
* Is the given throwable caused by a database lock timeout? | ||
* | ||
* @param e exception | ||
* @return is caused by a database lock timeout | ||
*/ | ||
static boolean isLockTimeout(Throwable e) { | ||
AtomicReference<Throwable> causeHolder = new AtomicReference<>(e); | ||
do { | ||
final Throwable cause = causeHolder.get(); | ||
final String failureMessage = cause.getMessage().toLowerCase(); | ||
if (LOCK_TIMEOUT_EXCEPTIONS.stream().anyMatch(c -> c.isInstance(cause)) || | ||
failureMessage.contains("timeout") || | ||
failureMessage.contains("timed out") || | ||
failureMessage.contains("time out") || | ||
failureMessage.contains("closed connection") || | ||
failureMessage.contains("link failure") || | ||
failureMessage.contains("expired or aborted by a conflict") | ||
) { | ||
return true; | ||
} else { | ||
if (cause.getCause() == null || cause.getCause() == cause) { | ||
break; | ||
} else { | ||
causeHolder.set(cause.getCause()); | ||
} | ||
} | ||
} | ||
while (true); | ||
return false; | ||
} | ||
|
||
/** | ||
* Is the given throwable caused by the following exception type? | ||
* | ||
* @param e exception | ||
* @param exceptionType exception type | ||
* @return is caused by the given exception type | ||
*/ | ||
static boolean isCausedBy(Throwable e, Class<? extends Throwable> exceptionType) { | ||
AtomicReference<Throwable> causeHolder = new AtomicReference<>(e); | ||
do { | ||
final Throwable cause = causeHolder.get(); | ||
if (exceptionType.isInstance(cause)) { | ||
return true; | ||
} else { | ||
if (cause.getCause() == null || cause.getCause() == cause) { | ||
break; | ||
} else { | ||
causeHolder.set(cause.getCause()); | ||
} | ||
} | ||
} | ||
while (true); | ||
return false; | ||
} | ||
|
||
/** | ||
* Is the given throwable caused by a database MVCC anomaly detection? | ||
* | ||
* @param e exception | ||
* @return is caused by a database lock MVCC anomaly detection | ||
*/ | ||
static boolean isMVCCAnomalyDetection(Throwable e) { | ||
AtomicReference<Throwable> causeHolder = new AtomicReference<>(e); | ||
do { | ||
final Throwable cause = causeHolder.get(); | ||
String lowerCaseMessage = cause.getMessage().toLowerCase(); | ||
if ( | ||
cause.getMessage().contains("ORA-08177: can't serialize access for this transaction") //Oracle | ||
|| lowerCaseMessage.contains("could not serialize access due to concurrent update") //PSQLException | ||
|| lowerCaseMessage.contains("ould not serialize access due to read/write dependencies among transactions") //PSQLException | ||
|| lowerCaseMessage.contains("snapshot isolation transaction aborted due to update conflict") //SQLServerException | ||
|| lowerCaseMessage.contains("kconflict") //YugabyteDB | ||
|| lowerCaseMessage.contains("unknown transaction, could be recently aborted") //YugabyteDB | ||
|| lowerCaseMessage.contains("conflicts with higher priority transaction") //YugabyteDB | ||
) { | ||
return true; | ||
} else { | ||
if (cause.getCause() == null || cause.getCause() == cause) { | ||
break; | ||
} else { | ||
causeHolder.set(cause.getCause()); | ||
} | ||
} | ||
} | ||
while (true); | ||
return false; | ||
} | ||
|
||
/** | ||
* Was the given exception caused by a SQL connection close | ||
* | ||
* @param e exception | ||
* @return is caused by a SQL connection close | ||
*/ | ||
static boolean isConnectionClose(Exception e) { | ||
Throwable cause = e; | ||
do { | ||
if (cause.getMessage().toLowerCase().contains("connection is close") | ||
|| cause.getMessage().toLowerCase().contains("closed connection") | ||
|| cause.getMessage().toLowerCase().contains("link failure") | ||
|| cause.getMessage().toLowerCase().contains("closed") | ||
) { | ||
return true; | ||
} else { | ||
if (cause.getCause() == null || cause.getCause() == cause) { | ||
break; | ||
} else { | ||
cause = cause.getCause(); | ||
} | ||
} | ||
} | ||
while (true); | ||
return false; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...stence/utils/hibernate/util/LogUtils.java → .../hypersistence/utils/common/LogUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.