This is an automated email from the ASF dual-hosted git repository.
zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new ed179a4d001 Fix #31372 problem (#31377)
ed179a4d001 is described below
commit ed179a4d0018ac188467c7e534e2e0852f49150e
Author: wmouren <[email protected]>
AuthorDate: Sun May 26 16:24:48 2024 +0800
Fix #31372 problem (#31377)
* Fix #31372 problem
* Fix #31372 problem
* Fix #31372 problem
---
.../mode/repository/standalone/jdbc/JDBCRepository.java | 15 ++++++++++++---
.../repository/standalone/jdbc/JDBCRepositoryTest.java | 2 --
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git
a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
index 7d15cf6c530..8b6fb6a2fa3 100644
---
a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
+++
b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
@@ -122,7 +122,17 @@ public final class JDBCRepository implements
StandalonePersistRepository {
@Override
public boolean isExisted(final String key) {
- return !Strings.isNullOrEmpty(query(key));
+ try (
+ Connection connection = dataSource.getConnection();
+ PreparedStatement preparedStatement =
connection.prepareStatement(repositorySQL.getSelectByKeySQL())) {
+ preparedStatement.setString(1, key);
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ return resultSet.next();
+ }
+ } catch (final SQLException ex) {
+ log.error("Check existence of {} data by key: {} failed",
getType(), key, ex);
+ }
+ return Boolean.FALSE;
}
@Override
@@ -138,8 +148,7 @@ public final class JDBCRepository implements
StandalonePersistRepository {
// Create key level directory recursively.
for (int i = 0; i < paths.length - 1; i++) {
String tempKey = tempPrefix + SEPARATOR + paths[i];
- String tempKeyVal = query(tempKey);
- if (Strings.isNullOrEmpty(tempKeyVal)) {
+ if (!isExisted(tempKey)) {
insert(tempKey, "", parent);
}
tempPrefix = tempKey;
diff --git
a/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java
b/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java
index 3a7d2830205..0e43a0d5bb4 100644
---
a/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java
+++
b/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java
@@ -147,7 +147,6 @@ class JDBCRepositoryTest {
when(mockJdbcConnection.prepareStatement(repositorySQL.getUpdateSQL())).thenReturn(mockPreparedStatementForPersist);
when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
when(mockResultSet.next()).thenReturn(true);
- when(mockResultSet.getString("value")).thenReturn("oldValue");
repository.persist(key, value);
verify(mockPreparedStatement).setString(1, key);
verify(mockPreparedStatementForPersist).setString(eq(1), anyString());
@@ -199,7 +198,6 @@ class JDBCRepositoryTest {
when(mockJdbcConnection.prepareStatement(repositorySQL.getSelectByKeySQL())).thenReturn(mockPreparedStatement);
when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
when(mockResultSet.next()).thenReturn(true);
- when(mockResultSet.getString("value")).thenReturn("oldValue");
when(mockJdbcConnection.prepareStatement(repositorySQL.getUpdateSQL())).thenReturn(mockPreparedStatement);
repository.persist(key, "value");
verify(mockPreparedStatementForPersist, times(0)).executeUpdate();