Top Description Fields Constructors Methods
org.hibernate.exception.spi

public Class TemplatedViolatedConstraintNameExtractor

extends Object
implements ViolatedConstraintNameExtractor
Class Inheritance
All Implemented Interfaces
org.hibernate.exception.spi.ViolatedConstraintNameExtractor
Imports
java.sql.SQLException, java.util.function.Function, org.hibernate.internal.util.NullnessUtil, org.checkerframework.checker.nullness.qual.Nullable

Extracts a violated database constraint name from an error message by matching the error message against a template.
Authors
Steve Ebersole, Brett Meyer

Field Summary

Modifier and TypeField and Description
private final Function<SQLException, String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public @Nullable String
extractConstraintName(SQLException
The exception that was the result of the constraint violation.
sqle
)

Implements org.hibernate.exception.spi.ViolatedConstraintNameExtractor.extractConstraintName.

Extract the name of the violated constraint from the given SQLException.
public static @Nullable String

Returns:

The found constraint name, or null.
extractUsingTemplate
(String
The pattern denoting the start of the constraint name within the message.
templateStart
,
String
The pattern denoting the end of the constraint name within the message.
templateEnd
,
String
The templated error message containing the constraint name.
message
)

Extracts the constraint name based on a template of form templateStartconstraintNametemplateEnd.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

extractConstraintNameback to summary
private final Function<SQLException, String> extractConstraintName

Constructor Detail

TemplatedViolatedConstraintNameExtractorback to summary
public TemplatedViolatedConstraintNameExtractor(Function<SQLException, String> extractConstraintName)

Method Detail

extractConstraintNameback to summary
public @Nullable String extractConstraintName(SQLException sqle)

Implements org.hibernate.exception.spi.ViolatedConstraintNameExtractor.extractConstraintName.

Doc from org.hibernate.exception.spi.ViolatedConstraintNameExtractor.extractConstraintName.

Extract the name of the violated constraint from the given SQLException.

Parameters
sqle:SQLException

The exception that was the result of the constraint violation.

Returns:@Nullable String

The extracted constraint name.

Annotations
@Override
extractUsingTemplateback to summary
public static @Nullable String extractUsingTemplate(String templateStart, String templateEnd, String message)

Extracts the constraint name based on a template of form templateStartconstraintNametemplateEnd.

Parameters
templateStart:String

The pattern denoting the start of the constraint name within the message.

templateEnd:String

The pattern denoting the end of the constraint name within the message.

message:String

The templated error message containing the constraint name.

Returns:@Nullable String

The found constraint name, or null.