Skip to content

Commit c38ab8b

Browse files
committed
audit calls to convert()
ideally, such calls should always pass the SQL statement as a separate argument
1 parent be1d75e commit c38ab8b

17 files changed

+71
-78
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,8 @@ public Clob mergeClob(Clob original, Clob target, SharedSessionContractImplement
19481948
throw new HibernateException( "Unable to copy stream content", e );
19491949
}
19501950
catch (SQLException e ) {
1951-
throw session.getFactory().getJdbcServices().getSqlExceptionHelper().convert( e, "unable to merge CLOB data" );
1951+
throw session.getFactory().getJdbcServices().getSqlExceptionHelper()
1952+
.convert( e, "unable to merge CLOB data" );
19521953
}
19531954
}
19541955
else {
@@ -1971,7 +1972,8 @@ public NClob mergeNClob(NClob original, NClob target, SharedSessionContractImple
19711972
throw new HibernateException( "Unable to copy stream content", e );
19721973
}
19731974
catch (SQLException e ) {
1974-
throw session.getFactory().getJdbcServices().getSqlExceptionHelper().convert( e, "unable to merge NCLOB data" );
1975+
throw session.getFactory().getJdbcServices().getSqlExceptionHelper()
1976+
.convert( e, "unable to merge NCLOB data" );
19751977
}
19761978
}
19771979
else {
@@ -1997,7 +1999,8 @@ public Blob mergeBlob(Blob original, Blob target, SharedSessionContractImplement
19971999
: lobCreator.createBlob( original.getBinaryStream(), original.length() );
19982000
}
19992001
catch (SQLException e) {
2000-
throw jdbcServices.getSqlExceptionHelper().convert( e, "unable to merge BLOB data" );
2002+
throw jdbcServices.getSqlExceptionHelper()
2003+
.convert( e, "unable to merge BLOB data" );
20012004
}
20022005
}
20032006

@@ -2014,7 +2017,8 @@ public Clob mergeClob(Clob original, Clob target, SharedSessionContractImplement
20142017
: lobCreator.createClob( original.getCharacterStream(), original.length() );
20152018
}
20162019
catch (SQLException e) {
2017-
throw jdbcServices.getSqlExceptionHelper().convert( e, "unable to merge CLOB data" );
2020+
throw jdbcServices.getSqlExceptionHelper()
2021+
.convert( e, "unable to merge CLOB data" );
20182022
}
20192023
}
20202024

@@ -2031,7 +2035,8 @@ public NClob mergeNClob(NClob original, NClob target, SharedSessionContractImple
20312035
: lobCreator.createNClob( original.getCharacterStream(), original.length() );
20322036
}
20332037
catch (SQLException e) {
2034-
throw jdbcServices.getSqlExceptionHelper().convert( e, "unable to merge NCLOB data" );
2038+
throw jdbcServices.getSqlExceptionHelper()
2039+
.convert( e, "unable to merge NCLOB data" );
20352040
}
20362041
}
20372042
};

hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/FallbackRefCursorSupport.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public void registerRefCursorParameter(CallableStatement statement, int position
2727
jdbcServices.getDialect().registerResultSetOutParameter( statement, position );
2828
}
2929
catch (SQLException e) {
30-
throw jdbcServices.getSqlExceptionHelper().convert( e, "Error asking dialect to register ref cursor parameter [" + position + "]" );
30+
throw jdbcServices.getSqlExceptionHelper()
31+
.convert( e, "Error asking dialect to register ref cursor parameter [" + position + "]" );
3132
}
3233
}
3334

@@ -37,7 +38,8 @@ public void registerRefCursorParameter(CallableStatement statement, String name)
3738
jdbcServices.getDialect().registerResultSetOutParameter( statement, name );
3839
}
3940
catch (SQLException e) {
40-
throw jdbcServices.getSqlExceptionHelper().convert( e, "Error asking dialect to register ref cursor parameter [" + name + "]" );
41+
throw jdbcServices.getSqlExceptionHelper()
42+
.convert( e, "Error asking dialect to register ref cursor parameter [" + name + "]" );
4143
}
4244
}
4345

hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public void registerRefCursorParameter(CallableStatement statement, int position
3636
statement.registerOutParameter( position, refCursorTypeCode() );
3737
}
3838
catch (SQLException e) {
39-
throw jdbcServices.getSqlExceptionHelper().convert( e, "Error registering REF_CURSOR parameter [" + position + "]" );
39+
throw jdbcServices.getSqlExceptionHelper()
40+
.convert( e, "Error registering REF_CURSOR parameter [" + position + "]" );
4041
}
4142
}
4243

@@ -46,7 +47,8 @@ public void registerRefCursorParameter(CallableStatement statement, String name)
4647
statement.registerOutParameter( name, refCursorTypeCode() );
4748
}
4849
catch (SQLException e) {
49-
throw jdbcServices.getSqlExceptionHelper().convert( e, "Error registering REF_CURSOR parameter [" + name + "]" );
50+
throw jdbcServices.getSqlExceptionHelper()
51+
.convert( e, "Error registering REF_CURSOR parameter [" + name + "]" );
5052
}
5153
}
5254

hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Statement createStatement() {
7171
return statement;
7272
}
7373
catch ( SQLException e ) {
74-
throw sqlExceptionHelper().convert( e, "could not create statement" );
74+
throw sqlExceptionHelper().convert( e, "Could not create statement" );
7575
}
7676
}
7777

hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcIsolationDelegate.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ public <T> T delegateWork(WorkExecutorVisitable<T> work, boolean transacted) thr
8686
if ( e instanceof HibernateException ) {
8787
throw (HibernateException) e;
8888
}
89-
else if ( e instanceof SQLException ) {
90-
throw sqlExceptionHelper().convert( (SQLException) e, "error performing isolated work" );
89+
else if ( e instanceof SQLException sqle ) {
90+
throw sqlExceptionHelper().convert( sqle, "Error performing isolated work" );
9191
}
9292
else {
93-
throw new HibernateException( "error performing isolated work", e );
93+
throw new HibernateException( "Error performing isolated work", e );
9494
}
9595
}
9696
finally {
@@ -111,7 +111,7 @@ else if ( e instanceof SQLException ) {
111111
}
112112
}
113113
catch ( SQLException sqle ) {
114-
throw sqlExceptionHelper().convert( sqle, "unable to obtain isolated JDBC connection" );
114+
throw sqlExceptionHelper().convert( sqle, "Unable to obtain isolated JDBC connection" );
115115
}
116116
}
117117

hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/DdlTransactionIsolatorJtaImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public Connection getIsolatedConnection(boolean autocommit) {
7272
jdbcConnection = jdbcContext.getJdbcConnectionAccess().obtainConnection();
7373
}
7474
catch (SQLException e) {
75-
throw jdbcContext.getSqlExceptionHelper().convert( e, "Unable to open JDBC Connection for DDL execution" );
75+
throw jdbcContext.getSqlExceptionHelper()
76+
.convert( e, "Unable to open JDBC Connection for DDL execution" );
7677
}
7778

7879
try {
@@ -81,7 +82,8 @@ public Connection getIsolatedConnection(boolean autocommit) {
8182
}
8283
}
8384
catch (SQLException e) {
84-
throw jdbcContext.getSqlExceptionHelper().convert( e, "Unable to set JDBC Connection for DDL execution to autocommit" );
85+
throw jdbcContext.getSqlExceptionHelper()
86+
.convert( e, "Unable to set JDBC Connection for DDL execution to autocommit" );
8587
}
8688
}
8789
return jdbcConnection;
@@ -94,7 +96,8 @@ public void release() {
9496
jdbcContext.getJdbcConnectionAccess().releaseConnection( jdbcConnection );
9597
}
9698
catch (SQLException e) {
97-
throw jdbcContext.getSqlExceptionHelper().convert( e, "Unable to release JDBC Connection used for DDL execution" );
99+
throw jdbcContext.getSqlExceptionHelper()
100+
.convert( e, "Unable to release JDBC Connection used for DDL execution" );
98101
}
99102
}
100103

hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterExtractorImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ public T extractValue(
5252
return ormType.extract( callableStatement, parameterPosition, session );
5353
}
5454
catch (SQLException e) {
55-
throw session.getJdbcServices().getSqlExceptionHelper().convert(
56-
e,
57-
"Unable to extract OUT/INOUT parameter value"
58-
);
55+
throw session.getJdbcServices().getSqlExceptionHelper()
56+
.convert( e, "Unable to extract OUT/INOUT parameter value" );
5957
}
6058
}
6159
}

hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterRegistrationImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ private void registerOutputParameter(
113113
sqlTypeDescriptor.registerOutParameter( callableStatement, jdbcParameterPositionStart );
114114
}
115115
catch (SQLException e) {
116-
throw session.getJdbcServices().getSqlExceptionHelper().convert(
117-
e,
118-
"Unable to register CallableStatement out parameter"
119-
);
116+
throw session.getJdbcServices().getSqlExceptionHelper()
117+
.convert( e, "Unable to register CallableStatement OUT parameter" );
120118
}
121119
}
122120
}

hibernate-core/src/main/java/org/hibernate/sql/exec/internal/StandardJdbcMutationExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private static int handleException(
9999
JdbcOperationQueryMutation jdbcMutation, SQLException sqle, JdbcServices jdbcServices, String finalSql) {
100100
final JDBCException exception =
101101
jdbcServices.getSqlExceptionHelper()
102-
.convert( sqle, "JDBC exception executing SQL [" + finalSql + "]" );
102+
.convert( sqle, "JDBC exception executing SQL", finalSql );
103103
if ( exception instanceof ConstraintViolationException constraintViolationException
104104
&& jdbcMutation instanceof JdbcOperationQueryInsert jdbcInsert ) {
105105
if ( constraintViolationException.getKind() == ConstraintViolationException.ConstraintKind.UNIQUE ) {

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/AbstractResultSetAccess.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ protected ResultSetMetaData getMetaData() {
3434
resultSetMetaData = getResultSet().getMetaData();
3535
}
3636
catch (SQLException e) {
37-
throw persistenceContext.getJdbcServices().getSqlExceptionHelper().convert(
38-
e,
39-
"Unable to access ResultSetMetaData"
40-
);
37+
throw persistenceContext.getJdbcServices().getSqlExceptionHelper()
38+
.convert( e, "Unable to access ResultSetMetaData" );
4139
}
4240
}
4341

@@ -50,10 +48,8 @@ public int getColumnCount() {
5048
return getMetaData().getColumnCount();
5149
}
5250
catch (SQLException e) {
53-
throw getFactory().getJdbcServices().getJdbcEnvironment().getSqlExceptionHelper().convert(
54-
e,
55-
"Unable to access ResultSet column count"
56-
);
51+
throw getFactory().getJdbcServices().getJdbcEnvironment().getSqlExceptionHelper()
52+
.convert( e, "Unable to access ResultSet column count" );
5753
}
5854
}
5955

@@ -65,10 +61,8 @@ public int resolveColumnPosition(String columnName) {
6561
);
6662
}
6763
catch (SQLException e) {
68-
throw getFactory().getJdbcServices().getJdbcEnvironment().getSqlExceptionHelper().convert(
69-
e,
70-
"Unable to find column position by name: " + columnName
71-
);
64+
throw getFactory().getJdbcServices().getJdbcEnvironment().getSqlExceptionHelper()
65+
.convert( e, "Unable to find column position by name: " + columnName );
7266
}
7367
}
7468

@@ -80,10 +74,8 @@ public String resolveColumnName(int position) {
8074
.extractColumnAlias( getMetaData(), position );
8175
}
8276
catch (SQLException e) {
83-
throw getFactory().getJdbcServices().getJdbcEnvironment().getSqlExceptionHelper().convert(
84-
e,
85-
"Unable to find column name by position"
86-
);
77+
throw getFactory().getJdbcServices().getJdbcEnvironment().getSqlExceptionHelper()
78+
.convert( e, "Unable to find column name by position" );
8779
}
8880
}
8981
}

0 commit comments

Comments
 (0)