Skip to content

Commit 4c45f37

Browse files
committed
Polish simple JDBC support classes
1 parent fad70aa commit 4c45f37

File tree

6 files changed

+74
-81
lines changed

6 files changed

+74
-81
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQL
158158
}
159159
catch (SQLException ex) {
160160
if (logger.isWarnEnabled()) {
161-
logger.warn("Error retrieving 'DatabaseMetaData.getGeneratedKeys': " + ex.getMessage());
161+
logger.warn("Error retrieving 'DatabaseMetaData.supportsGetGeneratedKeys': " + ex.getMessage());
162162
}
163163
}
164164
try {
@@ -226,51 +226,33 @@ public void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData,
226226
@Override
227227
@Nullable
228228
public String tableNameToUse(@Nullable String tableName) {
229-
if (tableName == null) {
230-
return null;
231-
}
232-
else if (isStoresUpperCaseIdentifiers()) {
233-
return tableName.toUpperCase();
234-
}
235-
else if (isStoresLowerCaseIdentifiers()) {
236-
return tableName.toLowerCase();
237-
}
238-
else {
239-
return tableName;
240-
}
229+
return identifierNameToUse(tableName);
241230
}
242231

243232
@Override
244233
@Nullable
245234
public String catalogNameToUse(@Nullable String catalogName) {
246-
if (catalogName == null) {
247-
return null;
248-
}
249-
else if (isStoresUpperCaseIdentifiers()) {
250-
return catalogName.toUpperCase();
251-
}
252-
else if (isStoresLowerCaseIdentifiers()) {
253-
return catalogName.toLowerCase();
254-
}
255-
else {
256-
return catalogName;
257-
}
235+
return identifierNameToUse(catalogName);
258236
}
259237

260238
@Override
261239
@Nullable
262240
public String schemaNameToUse(@Nullable String schemaName) {
263-
if (schemaName == null) {
241+
return identifierNameToUse(schemaName);
242+
}
243+
244+
private String identifierNameToUse(String identifierName) {
245+
if (identifierName == null) {
264246
return null;
265247
}
266248
else if (isStoresUpperCaseIdentifiers()) {
267-
return schemaName.toUpperCase();
249+
return identifierName.toUpperCase();
268250
}
269251
else if (isStoresLowerCaseIdentifiers()) {
270-
return schemaName.toLowerCase();
252+
return identifierName.toLowerCase();
271253
}
272254
else {
273-
return schemaName;
255+
return identifierName;
274256
}
275257
}
276258

@@ -290,15 +272,15 @@ public String metaDataSchemaNameToUse(@Nullable String schemaName) {
290272
}
291273

292274
/**
293-
* Provide access to default schema for subclasses.
275+
* Provide access to the default schema for subclasses.
294276
*/
295277
@Nullable
296278
protected String getDefaultSchema() {
297279
return this.userName;
298280
}
299281

300282
/**
301-
* Provide access to version info for subclasses.
283+
* Provide access to the version info for subclasses.
302284
*/
303285
@Nullable
304286
protected String getDatabaseVersion() {

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,35 +349,33 @@ public int[] createInsertTypes() {
349349

350350

351351
/**
352-
* Does this database support the JDBC 3.0 feature of retrieving generated keys:
353-
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
352+
* Does this database support the JDBC 3.0 feature of retrieving generated keys?
353+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
354354
*/
355355
public boolean isGetGeneratedKeysSupported() {
356356
return obtainMetaDataProvider().isGetGeneratedKeysSupported();
357357
}
358358

359359
/**
360-
* Does this database support simple query to retrieve generated keys
361-
* when the JDBC 3.0 feature is not supported:
362-
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
360+
* Does this database support a simple query to retrieve the generated key when
361+
* the JDBC 3.0 feature of retrieving generated keys is not supported?
362+
* @see #isGetGeneratedKeysSupported()
363363
*/
364364
public boolean isGetGeneratedKeysSimulated() {
365365
return obtainMetaDataProvider().isGetGeneratedKeysSimulated();
366366
}
367367

368368
/**
369-
* Does this database support a simple query to retrieve generated keys
370-
* when the JDBC 3.0 feature is not supported:
371-
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
369+
* Get the simple query to retrieve a generated key.
372370
*/
373371
@Nullable
374372
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
375373
return obtainMetaDataProvider().getSimpleQueryForGetGeneratedKey(tableName, keyColumnName);
376374
}
377375

378376
/**
379-
* Is a column name String array for retrieving generated keys supported:
380-
* {@link java.sql.Connection#createStruct(String, Object[])}?
377+
* Is a column name String array for retrieving generated keys supported?
378+
* @see java.sql.Connection#createStruct(String, Object[])
381379
*/
382380
public boolean isGeneratedKeysColumnNameArraySupported() {
383381
return obtainMetaDataProvider().isGeneratedKeysColumnNameArraySupported();

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProvider.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424

2525
/**
2626
* Interface specifying the API to be implemented by a class providing table meta-data.
27-
* This is intended for internal use by the Simple JDBC classes.
27+
*
28+
* <p>This is intended for internal use by the Simple JDBC classes.
2829
*
2930
* @author Thomas Risberg
31+
* @author Sam Brannen
3032
* @since 2.5
3133
*/
3234
public interface TableMetaDataProvider {
@@ -40,7 +42,8 @@ public interface TableMetaDataProvider {
4042

4143
/**
4244
* Initialize using provided database meta-data, table and column information.
43-
* This initialization can be turned off by specifying that column meta-data should not be used.
45+
* <p>This initialization can be turned off by specifying that column meta-data
46+
* should not be used.
4447
* @param databaseMetaData used to retrieve database specific information
4548
* @param catalogName name of catalog to use (or {@code null} if none)
4649
* @param schemaName name of schema name to use (or {@code null} if none)
@@ -52,37 +55,41 @@ void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nulla
5255

5356
/**
5457
* Get the table name formatted based on meta-data information.
55-
* This could include altering the case.
58+
* <p>This could include altering the case.
5659
*/
5760
@Nullable
5861
String tableNameToUse(@Nullable String tableName);
5962

6063
/**
6164
* Get the catalog name formatted based on meta-data information.
62-
* This could include altering the case.
65+
* <p>This could include altering the case.
6366
*/
6467
@Nullable
6568
String catalogNameToUse(@Nullable String catalogName);
6669

6770
/**
6871
* Get the schema name formatted based on meta-data information.
69-
* This could include altering the case.
72+
* <p>This could include altering the case.
7073
*/
7174
@Nullable
7275
String schemaNameToUse(@Nullable String schemaName);
7376

7477
/**
75-
* Provide any modification of the catalog name passed in to match the meta-data currently used.
76-
* The returned value will be used for meta-data lookups.
77-
* This could include altering the case used or providing a base catalog if none is provided.
78+
* Provide any modification of the catalog name passed in to match the meta-data
79+
* currently used.
80+
* <p>The returned value will be used for meta-data lookups.
81+
* <p>This could include altering the case used or providing a base catalog
82+
* if none is provided.
7883
*/
7984
@Nullable
8085
String metaDataCatalogNameToUse(@Nullable String catalogName) ;
8186

8287
/**
83-
* Provide any modification of the schema name passed in to match the meta-data currently used.
84-
* The returned value will be used for meta-data lookups.
85-
* This could include altering the case used or providing a base schema if none is provided.
88+
* Provide any modification of the schema name passed in to match the meta-data
89+
* currently used.
90+
* <p>The returned value will be used for meta-data lookups.
91+
* <p>This could include altering the case used or providing a base schema
92+
* if none is provided.
8693
*/
8794
@Nullable
8895
String metaDataSchemaNameToUse(@Nullable String schemaName) ;
@@ -93,8 +100,8 @@ void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nulla
93100
boolean isTableColumnMetaDataUsed();
94101

95102
/**
96-
* Does this database support the JDBC 3.0 feature of retrieving generated keys:
97-
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
103+
* Does this database support the JDBC 3.0 feature of retrieving generated keys?
104+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
98105
*/
99106
boolean isGetGeneratedKeysSupported();
100107

@@ -112,8 +119,9 @@ void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nulla
112119
String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName);
113120

114121
/**
115-
* Does this database support a column name String array for retrieving generated keys:
116-
* {@link java.sql.Connection#createStruct(String, Object[])}?
122+
* Does this database support a column name String array for retrieving generated
123+
* keys?
124+
* @see java.sql.Connection#createStruct(String, Object[])
117125
*/
118126
boolean isGeneratedKeysColumnNameArraySupported();
119127

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
*
5858
* @author Thomas Risberg
5959
* @author Juergen Hoeller
60+
* @author Sam Brannen
6061
* @since 2.5
6162
*/
6263
public abstract class AbstractJdbcInsert {
@@ -91,15 +92,15 @@ public abstract class AbstractJdbcInsert {
9192

9293
/**
9394
* Constructor to be used when initializing using a {@link DataSource}.
94-
* @param dataSource the DataSource to be used
95+
* @param dataSource the {@code DataSource} to be used
9596
*/
9697
protected AbstractJdbcInsert(DataSource dataSource) {
9798
this.jdbcTemplate = new JdbcTemplate(dataSource);
9899
}
99100

100101
/**
101102
* Constructor to be used when initializing using a {@link JdbcTemplate}.
102-
* @param jdbcTemplate the JdbcTemplate to use
103+
* @param jdbcTemplate the {@code JdbcTemplate} to use
103104
*/
104105
protected AbstractJdbcInsert(JdbcTemplate jdbcTemplate) {
105106
Assert.notNull(jdbcTemplate, "JdbcTemplate must not be null");
@@ -207,15 +208,15 @@ public String[] getGeneratedKeyNames() {
207208

208209
/**
209210
* Specify whether the parameter meta-data for the call should be used.
210-
* The default is {@code true}.
211+
* <p>The default is {@code true}.
211212
*/
212213
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData) {
213214
this.tableMetaDataContext.setAccessTableColumnMetaData(accessTableColumnMetaData);
214215
}
215216

216217
/**
217218
* Specify whether the default for including synonyms should be changed.
218-
* The default is {@code false}.
219+
* <p>The default is {@code false}.
219220
*/
220221
public void setOverrideIncludeSynonymsDefault(boolean override) {
221222
this.tableMetaDataContext.setOverrideIncludeSynonymsDefault(override);

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsert.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,35 @@
2626
import org.springframework.jdbc.support.KeyHolder;
2727

2828
/**
29-
* A SimpleJdbcInsert is a multithreaded, reusable object providing easy (batch) insert
30-
* capabilities for a table. It provides meta-data processing to simplify the code
31-
* needed to construct a basic insert statement. All you need to provide is the name
32-
* of the table and a Map containing the column names and the column values.
29+
* A {@code SimpleJdbcInsert} is a multi-threaded, reusable object providing easy
30+
* (batch) insert capabilities for a table. It provides meta-data processing to
31+
* simplify the code needed to construct a basic insert statement. All you need
32+
* to provide is the name of the table and a {@code Map} containing the column
33+
* names and the column values.
3334
*
34-
* <p>The meta-data processing is based on the DatabaseMetaData provided by the
35-
* JDBC driver. As long as the JDBC driver can provide the names of the columns
35+
* <p>The meta-data processing is based on the {@code DatabaseMetaData} provided
36+
* by the JDBC driver. As long as the JDBC driver can provide the names of the columns
3637
* for a specified table then we can rely on this auto-detection feature. If that
3738
* is not the case, then the column names must be specified explicitly.
3839
*
3940
* <p>The actual (batch) insert is handled using Spring's {@link JdbcTemplate}.
4041
*
4142
* <p>Many of the configuration methods return the current instance of the
42-
* SimpleJdbcInsert to provide the ability to chain multiple ones together
43-
* in a "fluent" interface style.
43+
* {@code SimpleJdbcInsert} to provide the ability to chain multiple ones together
44+
* in a "fluent" API style.
4445
*
4546
* @author Thomas Risberg
4647
* @author Juergen Hoeller
48+
* @author Sam Brannen
4749
* @since 2.5
4850
* @see java.sql.DatabaseMetaData
4951
* @see org.springframework.jdbc.core.JdbcTemplate
5052
*/
5153
public class SimpleJdbcInsert extends AbstractJdbcInsert implements SimpleJdbcInsertOperations {
5254

5355
/**
54-
* Constructor that takes one parameter with the JDBC DataSource to use when creating the
55-
* JdbcTemplate.
56+
* Constructor that accepts the JDBC {@link DataSource} to use when creating
57+
* the {@link JdbcTemplate}.
5658
* @param dataSource the {@code DataSource} to use
5759
* @see org.springframework.jdbc.core.JdbcTemplate#setDataSource
5860
*/
@@ -61,7 +63,7 @@ public SimpleJdbcInsert(DataSource dataSource) {
6163
}
6264

6365
/**
64-
* Alternative Constructor that takes one parameter with the JdbcTemplate to be used.
66+
* Alternative constructor that accepts the {@link JdbcTemplate} to be used.
6567
* @param jdbcTemplate the {@code JdbcTemplate} to use
6668
* @see org.springframework.jdbc.core.JdbcTemplate#setDataSource
6769
*/

0 commit comments

Comments
 (0)