Package org.hibernate.exception.spi
Class TemplatedViolatedConstraintNameExtractor
java.lang.Object
org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor
- All Implemented Interfaces:
ViolatedConstraintNameExtractor
public class TemplatedViolatedConstraintNameExtractor
extends Object
implements ViolatedConstraintNameExtractor
Extracts a violated database constraint name from an error message
by matching the error message against a template.
-
Constructor Summary
ConstructorsConstructorDescriptionTemplatedViolatedConstraintNameExtractor
(Function<SQLException, String> extractConstraintName) -
Method Summary
Modifier and TypeMethodDescription@Nullable String
extractConstraintName
(SQLException exception) Extract the name of the violated constraint from the givenSQLException
.static @Nullable String
extractUsingTemplate
(String templateStart, String templateEnd, String message) Extracts the constraint name based on a template of form templateStartconstraintNametemplateEnd.
-
Constructor Details
-
TemplatedViolatedConstraintNameExtractor
public TemplatedViolatedConstraintNameExtractor(Function<SQLException, String> extractConstraintName)
-
-
Method Details
-
extractConstraintName
Description copied from interface:ViolatedConstraintNameExtractor
Extract the name of the violated constraint from the givenSQLException
.- Specified by:
extractConstraintName
in interfaceViolatedConstraintNameExtractor
- Parameters:
exception
- The exception that was the result of the constraint violation.- Returns:
- The extracted constraint name.
-
extractUsingTemplate
public static @Nullable String extractUsingTemplate(String templateStart, String templateEnd, String message) Extracts the constraint name based on a template of form templateStartconstraintNametemplateEnd.- Parameters:
templateStart
- The pattern denoting the start of the constraint name within the message.templateEnd
- The pattern denoting the end of the constraint name within the message.message
- The templated error message containing the constraint name.- Returns:
- The found constraint name, or null.
-