Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ea64d5d

Browse files
minor cleanups to exception SPI package
1 parent cef7452 commit ea64d5d

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed

‎hibernate-core/src/main/java/org/hibernate/exception/ConstraintViolationException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.exception;
6+
67
import java.sql.SQLException;
78

89
import org.hibernate.JDBCException;

‎hibernate-core/src/main/java/org/hibernate/exception/GenericJDBCException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.exception;
6+
67
import java.sql.SQLException;
78

89
import org.hibernate.JDBCException;

‎hibernate-core/src/main/java/org/hibernate/exception/JDBCConnectionException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.exception;
6+
67
import java.sql.SQLException;
78

89
import org.hibernate.JDBCException;

‎hibernate-core/src/main/java/org/hibernate/exception/SQLGrammarException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.exception;
6+
67
import java.sql.SQLException;
78

89
import org.hibernate.JDBCException;

‎hibernate-core/src/main/java/org/hibernate/exception/internal/StandardSQLExceptionConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public StandardSQLExceptionConverter(SQLExceptionConversionDelegate... delegates
3030

3131
@Override
3232
public JDBCException convert(SQLException sqlException, String message, String sql) {
33-
for ( SQLExceptionConversionDelegate delegate : delegates ) {
34-
final JDBCException jdbcException = delegate.convert( sqlException, message, sql );
33+
for ( var delegate : delegates ) {
34+
final var jdbcException = delegate.convert( sqlException, message, sql );
3535
if ( jdbcException != null ) {
3636
return jdbcException;
3737
}

‎hibernate-core/src/main/java/org/hibernate/exception/spi/TemplatedViolatedConstraintNameExtractor.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import java.sql.SQLException;
88
import java.util.function.Function;
99

10-
import org.hibernate.internal.util.NullnessUtil;
1110

1211
import org.checkerframework.checker.nullness.qual.Nullable;
1312

13+
1414
/**
1515
* Extracts a violated database constraint name from an error message
1616
* by matching the error message against a template.
@@ -27,23 +27,18 @@ public TemplatedViolatedConstraintNameExtractor(Function<SQLException,String> ex
2727
}
2828

2929
@Override
30-
public @Nullable String extractConstraintName(SQLException sqle) {
30+
public @Nullable String extractConstraintName(SQLException exception) {
3131
try {
32-
String constraintName = null;
33-
34-
// handle nested exceptions
35-
do {
36-
constraintName = extractConstraintName.apply(sqle);
37-
if (sqle.getNextException() == null
38-
|| sqle.getNextException() == sqle) {
39-
break;
40-
}
41-
else {
42-
sqle = NullnessUtil.castNonNull( sqle.getNextException() );
32+
while (true) {
33+
final String constraintName = extractConstraintName.apply( exception );
34+
final SQLException chained = exception.getNextException();
35+
if ( constraintName != null
36+
|| chained == null
37+
|| chained == exception ) {
38+
return constraintName;
4339
}
44-
} while (constraintName == null);
45-
46-
return constraintName;
40+
exception = chained;
41+
}
4742
}
4843
catch (NumberFormatException nfe) {
4944
return null;
@@ -60,18 +55,15 @@ public TemplatedViolatedConstraintNameExtractor(Function<SQLException,String> ex
6055
* @return The found constraint name, or null.
6156
*/
6257
public static @Nullable String extractUsingTemplate(String templateStart, String templateEnd, String message) {
63-
int templateStartPosition = message.indexOf( templateStart );
58+
finalint templateStartPosition = message.indexOf( templateStart );
6459
if ( templateStartPosition < 0 ) {
6560
return null;
6661
}
67-
68-
int start = templateStartPosition + templateStart.length();
69-
int end = templateEnd.equals("\n") ? -1 : message.indexOf( templateEnd, start );
70-
if ( end < 0 ) {
71-
end = message.length();
62+
else {
63+
final int start = templateStartPosition + templateStart.length();
64+
final int end = templateEnd.equals( "\n" ) ? -1 : message.indexOf( templateEnd, start );
65+
return end < 0 ? message.substring( start ) : message.substring( start, end );
7266
}
73-
74-
return message.substring( start, end );
7567
}
7668

7769
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /