Skip to content

Commit c0b0ee6

Browse files
committed
Polishing
1 parent 4642c32 commit c0b0ee6

File tree

5 files changed

+40
-39
lines changed

5 files changed

+40
-39
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -95,7 +95,7 @@ public DataAccessException translate(String task, @Nullable String sql, SQLExcep
9595
* is allowed to return {@code null} to indicate that no exception match has
9696
* been found and that fallback translation should kick in.
9797
* @param task readable text describing the task being attempted
98-
* @param sql SQL query or update that caused the problem (if known)
98+
* @param sql the SQL query or update that caused the problem (if known)
9999
* @param ex the offending {@code SQLException}
100100
* @return the DataAccessException, wrapping the {@code SQLException};
101101
* or {@code null} if no exception match found
@@ -114,7 +114,7 @@ public DataAccessException translate(String task, @Nullable String sql, SQLExcep
114114
* @return the message {@code String} to use
115115
*/
116116
protected String buildMessage(String task, @Nullable String sql, SQLException ex) {
117-
return task + "; " + (sql != null ? "SQL [" + sql : "]; " + "") + ex.getMessage();
117+
return task + "; " + (sql != null ? ("SQL [" + sql + "]; ") : "") + ex.getMessage();
118118
}
119119

120120
}

spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
import org.springframework.lang.Nullable;
2727

2828
/**
29-
* Default implementation of the {@link KeyHolder} interface, to be used for
29+
* The standard implementation of the {@link KeyHolder} interface, to be used for
3030
* holding auto-generated keys (as potentially returned by JDBC insert statements).
3131
*
32-
* <p>Create an instance of this class for each insert operation, and pass
33-
* it to the corresponding {@link org.springframework.jdbc.core.JdbcTemplate}
34-
* or {org.springframework.jdbc.object.SqlUpdate} methods.
32+
* <p>Create an instance of this class for each insert operation, and pass it
33+
* to the corresponding {@link org.springframework.jdbc.core.JdbcTemplate} or
34+
* {@link org.springframework.jdbc.object.SqlUpdate} methods.
3535
*
3636
* @author Thomas Risberg
3737
* @author Juergen Hoeller
@@ -92,10 +92,11 @@ public Map<String, Object> getKeys() throws InvalidDataAccessApiUsageException {
9292
if (this.keyList.isEmpty()) {
9393
return null;
9494
}
95-
if (this.keyList.size() > 1)
95+
if (this.keyList.size() > 1) {
9696
throw new InvalidDataAccessApiUsageException(
9797
"The getKeys method should only be used when keys for a single row are returned. " +
9898
"The current key list contains keys for multiple rows: " + this.keyList);
99+
}
99100
return this.keyList.get(0);
100101
}
101102

spring-jdbc/src/main/java/org/springframework/jdbc/support/KeyHolder.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,28 +52,28 @@ public interface KeyHolder {
5252
* multiple entries as well. If this method encounters multiple entries in
5353
* either the map or the list meaning that multiple keys were returned,
5454
* then an InvalidDataAccessApiUsageException is thrown.
55-
* @return the generated key
56-
* @throws InvalidDataAccessApiUsageException if multiple keys are encountered.
55+
* @return the generated key as a number
56+
* @throws InvalidDataAccessApiUsageException if multiple keys are encountered
5757
*/
5858
@Nullable
5959
Number getKey() throws InvalidDataAccessApiUsageException;
6060

6161
/**
62-
* Retrieve the first map of keys. If there are multiple entries in the list
63-
* (meaning that multiple rows had keys returned), then an
64-
* InvalidDataAccessApiUsageException is thrown.
65-
* @return the Map of generated keys
62+
* Retrieve the first map of keys.
63+
* <p>If there are multiple entries in the list (meaning that multiple rows
64+
* had keys returned), then an InvalidDataAccessApiUsageException is thrown.
65+
* @return the Map of generated keys for a single row
6666
* @throws InvalidDataAccessApiUsageException if keys for multiple rows are encountered
6767
*/
6868
@Nullable
6969
Map<String, Object> getKeys() throws InvalidDataAccessApiUsageException;
7070

7171
/**
7272
* Return a reference to the List that contains the keys.
73-
* Can be used for extracting keys for multiple rows (an unusual case),
73+
* <p>Can be used for extracting keys for multiple rows (an unusual case),
7474
* and also for adding new maps of keys.
75-
* @return the List for the generated keys, with each entry being a Map
76-
* of column names and key values
75+
* @return the List for the generated keys, with each entry representing
76+
* an individual row through a Map of column names and key values
7777
*/
7878
List<Map<String, Object>> getKeyList();
7979

spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public SQLErrorCodeSQLExceptionTranslator() {
9090
* Create a SQL error code translator for the given DataSource.
9191
* Invoking this constructor will cause a Connection to be obtained
9292
* from the DataSource to get the meta-data.
93-
* @param dataSource DataSource to use to find meta-data and establish
93+
* @param dataSource the DataSource to use to find meta-data and establish
9494
* which error codes are usable
9595
* @see SQLErrorCodesFactory
9696
*/
@@ -127,7 +127,7 @@ public SQLErrorCodeSQLExceptionTranslator(SQLErrorCodes sec) {
127127
* Set the DataSource for this translator.
128128
* <p>Setting this property will cause a Connection to be obtained from
129129
* the DataSource to get the meta-data.
130-
* @param dataSource DataSource to use to find meta-data and establish
130+
* @param dataSource the DataSource to use to find meta-data and establish
131131
* which error codes are usable
132132
* @see SQLErrorCodesFactory#getErrorCodes(javax.sql.DataSource)
133133
* @see java.sql.DatabaseMetaData#getDatabaseProductName()
@@ -180,9 +180,9 @@ protected DataAccessException doTranslate(String task, @Nullable String sql, SQL
180180
}
181181

182182
// First, try custom translation from overridden method.
183-
DataAccessException dex = customTranslate(task, sql, sqlEx);
184-
if (dex != null) {
185-
return dex;
183+
DataAccessException dae = customTranslate(task, sql, sqlEx);
184+
if (dae != null) {
185+
return dae;
186186
}
187187

188188
// Next, try the custom SQLException translator, if available.
@@ -288,32 +288,32 @@ else if (Arrays.binarySearch(this.sqlErrorCodes.getCannotSerializeTransactionCod
288288
}
289289

290290
/**
291-
* Subclasses can override this method to attempt a custom mapping from SQLException
292-
* to DataAccessException.
291+
* Subclasses can override this method to attempt a custom mapping from
292+
* {@link SQLException} to {@link DataAccessException}.
293293
* @param task readable text describing the task being attempted
294-
* @param sql SQL query or update that caused the problem. May be {@code null}.
294+
* @param sql the SQL query or update that caused the problem (may be {@code null})
295295
* @param sqlEx the offending SQLException
296-
* @return null if no custom translation was possible, otherwise a DataAccessException
297-
* resulting from custom translation. This exception should include the sqlEx parameter
298-
* as a nested root cause. This implementation always returns null, meaning that
299-
* the translator always falls back to the default error codes.
296+
* @return {@code null} if no custom translation applies, otherwise a {@link DataAccessException}
297+
* resulting from custom translation. This exception should include the {@code sqlEx} parameter
298+
* as a nested root cause. This implementation always returns {@code null}, meaning that the
299+
* translator always falls back to the default error codes.
300300
*/
301301
@Nullable
302302
protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlEx) {
303303
return null;
304304
}
305305

306306
/**
307-
* Create a custom DataAccessException, based on a given exception
308-
* class from a CustomSQLErrorCodesTranslation definition.
307+
* Create a custom {@link DataAccessException}, based on a given exception
308+
* class from a {@link CustomSQLErrorCodesTranslation} definition.
309309
* @param task readable text describing the task being attempted
310-
* @param sql SQL query or update that caused the problem. May be {@code null}.
310+
* @param sql the SQL query or update that caused the problem (may be {@code null})
311311
* @param sqlEx the offending SQLException
312312
* @param exceptionClass the exception class to use, as defined in the
313-
* CustomSQLErrorCodesTranslation definition
314-
* @return null if the custom exception could not be created, otherwise
315-
* the resulting DataAccessException. This exception should include the
316-
* sqlEx parameter as a nested root cause.
313+
* {@link CustomSQLErrorCodesTranslation} definition
314+
* @return {@code null} if the custom exception could not be created, otherwise
315+
* the resulting {@link DataAccessException}. This exception should include the
316+
* {@code sqlEx} parameter as a nested root cause.
317317
* @see CustomSQLErrorCodesTranslation#setExceptionClass
318318
*/
319319
@Nullable

spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ public interface SQLExceptionTranslator {
4646
* check (and subsequent cast) is considered reliable when expecting JDBC-based
4747
* access to have happened.
4848
* @param task readable text describing the task being attempted
49-
* @param sql SQL query or update that caused the problem (if known)
49+
* @param sql the SQL query or update that caused the problem (if known)
5050
* @param ex the offending {@code SQLException}
5151
* @return the DataAccessException wrapping the {@code SQLException},
5252
* or {@code null} if no translation could be applied

0 commit comments

Comments
 (0)