Skip to content

Commit 8258325

Browse files
hpoettkerfmbenhassine
authored andcommitted
Refactor deprecated method extractDatabaseMetaData
Issue #3838
1 parent 0ad6803 commit 8258325

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2012 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.batch.item.database.support;
1818

19+
import java.sql.DatabaseMetaData;
1920
import javax.sql.DataSource;
2021

2122
import org.springframework.batch.item.database.PagingQueryProvider;
@@ -41,7 +42,7 @@ public class DerbyPagingQueryProvider extends SqlWindowingPagingQueryProvider {
4142
@Override
4243
public void init(DataSource dataSource) throws Exception {
4344
super.init(dataSource);
44-
String version = JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductVersion").toString();
45+
String version = JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductVersion);
4546
if (!isDerbyVersionSupported(version)) {
4647
throw new InvalidDataAccessResourceUsageException("Apache Derby version " + version + " is not supported by this class, Only version " + MINIMAL_DERBY_VERSION + " or later is supported");
4748
}
@@ -52,8 +53,8 @@ private boolean isDerbyVersionSupported(String version) {
5253
String[] minimalVersionParts = MINIMAL_DERBY_VERSION.split("\\.");
5354
String[] versionParts = version.split("[\\. ]");
5455
for (int i = 0; i < minimalVersionParts.length; i++) {
55-
int minimalVersionPart = Integer.valueOf(minimalVersionParts[i]);
56-
int versionPart = Integer.valueOf(versionParts[i]);
56+
int minimalVersionPart = Integer.parseInt(minimalVersionParts[i]);
57+
int versionPart = Integer.parseInt(versionParts[i]);
5758
if (versionPart < minimalVersionPart) {
5859
return false;
5960
} else if (versionPart > minimalVersionPart) {

spring-batch-infrastructure/src/main/java/org/springframework/batch/support/DatabaseType.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -21,6 +21,7 @@
2121
import org.springframework.util.StringUtils;
2222

2323
import javax.sql.DataSource;
24+
import java.sql.DatabaseMetaData;
2425
import java.util.HashMap;
2526
import java.util.Map;
2627

@@ -99,17 +100,17 @@ public static DatabaseType fromProductName(String productName){
99100
*/
100101
public static DatabaseType fromMetaData(DataSource dataSource) throws MetaDataAccessException {
101102
String databaseProductName =
102-
JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName").toString();
103+
JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductName);
103104
if (StringUtils.hasText(databaseProductName) && databaseProductName.startsWith("DB2")) {
104105
String databaseProductVersion =
105-
JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductVersion").toString();
106+
JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductVersion);
106107
if (databaseProductVersion.startsWith("ARI")) {
107108
databaseProductName = "DB2VSE";
108109
}
109110
else if (databaseProductVersion.startsWith("DSN")) {
110111
databaseProductName = "DB2ZOS";
111112
}
112-
else if (databaseProductName.indexOf("AS") != -1 && (databaseProductVersion.startsWith("QSQ") ||
113+
else if (databaseProductName.contains("AS") && (databaseProductVersion.startsWith("QSQ") ||
113114
databaseProductVersion.substring(databaseProductVersion.indexOf('V')).matches("V\\dR\\d[mM]\\d"))) {
114115
databaseProductName = "DB2AS400";
115116
}

0 commit comments

Comments
 (0)