This commit is contained in:
justinsubert 2013-06-21 10:26:43 +01:00 committed by Brett Meyer
parent 4ab3caa789
commit f1439b5601
1 changed files with 28 additions and 0 deletions

View File

@ -23,8 +23,13 @@
*/
package org.hibernate.dialect;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
import org.hibernate.internal.util.JdbcExceptionHelper;
/**
* An SQL dialect for MySQL 5.x specific features.
*
@ -43,4 +48,27 @@ public class MySQL5Dialect extends MySQLDialect {
public boolean supportsColumnCheck() {
return false;
}
public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
return EXTRACTER;
}
private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() {
public String extractConstraintName(SQLException sqle) {
try {
int sqlState = Integer.valueOf( JdbcExceptionHelper.extractSqlState( sqle ) ).intValue();
switch ( sqlState ) {
case 23000:
return extractUsingTemplate( " for key '", "'", sqle.getMessage() );
default:
return null;
}
}
catch (NumberFormatException nfe) {
return null;
}
}
};
}