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 Details

    • TemplatedViolatedConstraintNameExtractor

      public TemplatedViolatedConstraintNameExtractor(Function<SQLException,String> extractConstraintName)
  • Method Details

    • extractConstraintName

      public @Nullable String extractConstraintName(SQLException sqle)
      Description copied from interface: ViolatedConstraintNameExtractor
      Extract the name of the violated constraint from the given SQLException.
      Specified by:
      extractConstraintName in interface ViolatedConstraintNameExtractor
      Parameters:
      sqle - 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.