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
Constructors Constructor Description TemplatedViolatedConstraintNameExtractor(Function<SQLException,String> extractConstraintName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
extractConstraintName(SQLException sqle)
Extract the name of the violated constraint from the givenSQLException
.static String
extractUsingTemplate(String templateStart, String templateEnd, String message)
Extracts the constraint name based on a template of form templateStartconstraintNametemplateEnd.
-
-
-
Constructor Detail
-
TemplatedViolatedConstraintNameExtractor
public TemplatedViolatedConstraintNameExtractor(Function<SQLException,String> extractConstraintName)
-
-
Method Detail
-
extractConstraintName
public String extractConstraintName(SQLException sqle)
Description copied from interface:ViolatedConstraintNameExtractor
Extract the name of the violated constraint from the givenSQLException
.- Specified by:
extractConstraintName
in interfaceViolatedConstraintNameExtractor
- Parameters:
sqle
- The exception that was the result of the constraint violation.- Returns:
- The extracted constraint name.
-
extractUsingTemplate
public static 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.
-
-