File tree 1 file changed +29
-0
lines changed
hibernate-core/src/main/java/org/hibernate/dialect 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 22
22
* Boston, MA 02110-1301 USA
23
23
*/
24
24
package org .hibernate .dialect ;
25
+
26
+ import java .sql .SQLException ;
25
27
import java .sql .Types ;
26
28
29
+ import org .hibernate .exception .spi .TemplatedViolatedConstraintNameExtracter ;
30
+ import org .hibernate .exception .spi .ViolatedConstraintNameExtracter ;
31
+ import org .hibernate .internal .util .JdbcExceptionHelper ;
32
+
27
33
/**
28
34
* An SQL dialect for MySQL 5.x specific features.
29
35
*
@@ -46,4 +52,27 @@ protected void registerVarcharTypes() {
46
52
public boolean supportsColumnCheck () {
47
53
return false ;
48
54
}
55
+
56
+ public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter () {
57
+ return EXTRACTER ;
58
+ }
59
+
60
+ private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter () {
61
+
62
+ public String extractConstraintName (SQLException sqle ) {
63
+ try {
64
+ int sqlState = Integer .valueOf ( JdbcExceptionHelper .extractSqlState ( sqle ) ).intValue ();
65
+ switch ( sqlState ) {
66
+ case 23000 :
67
+ return extractUsingTemplate ( " for key '" , "'" , sqle .getMessage () );
68
+ default :
69
+ return null ;
70
+ }
71
+ }
72
+ catch (NumberFormatException nfe ) {
73
+ return null ;
74
+ }
75
+ }
76
+ };
77
+
49
78
}
You can’t perform that action at this time.
0 commit comments