You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/10/16 09:03:55 UTC
[shardingsphere] branch master updated: Modify
PreparedStatement.setFetchSize() (#7808)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 dd3d317 Modify PreparedStatement.setFetchSize() (#7808)
dd3d317 is described below
commit dd3d317ce5881f03e600172c87f0a216c5e48c22
Author: 邱鹿 Lucas <lu...@163.com>
AuthorDate: Fri Oct 16 17:03:25 2020 +0800
Modify PreparedStatement.setFetchSize() (#7808)
Co-authored-by: qiulu3 <Lucas209910>
---
.../shardingsphere/scaling/mysql/MySQLJdbcDumper.java | 10 +++++-----
.../scaling/mysql/MySQLJdbcDumperTest.java | 17 ++++++++++-------
.../scaling/postgresql/PostgreSQLJdbcDumper.java | 2 +-
.../scaling/postgresql/PostgreSQLJdbcDumperTest.java | 2 +-
4 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/shardingsphere-scaling/shardingsphere-scaling-mysql/src/main/java/org/apache/shardingsphere/scaling/mysql/MySQLJdbcDumper.java b/shardingsphere-scaling/shardingsphere-scaling-mysql/src/main/java/org/apache/shardingsphere/scaling/mysql/MySQLJdbcDumper.java
index 71a5b04..2a79f2c 100755
--- a/shardingsphere-scaling/shardingsphere-scaling-mysql/src/main/java/org/apache/shardingsphere/scaling/mysql/MySQLJdbcDumper.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-mysql/src/main/java/org/apache/shardingsphere/scaling/mysql/MySQLJdbcDumper.java
@@ -54,9 +54,9 @@ public final class MySQLJdbcDumper extends AbstractJDBCDumper {
return formatMySQLParams(parameters);
}
- private String formatMySQLParams(final Map<String, String> params) {
+ private String formatMySQLParams(final Map<String, String> parameters) {
StringBuilder result = new StringBuilder();
- for (Entry<String, String> entry : params.entrySet()) {
+ for (Entry<String, String> entry : parameters.entrySet()) {
result.append(entry.getKey());
if (null != entry.getValue()) {
result.append("=").append(entry.getValue());
@@ -81,9 +81,9 @@ public final class MySQLJdbcDumper extends AbstractJDBCDumper {
}
@Override
- protected PreparedStatement createPreparedStatement(final Connection conn, final String sql) throws SQLException {
- PreparedStatement result = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
- result.setFetchSize(100);
+ protected PreparedStatement createPreparedStatement(final Connection connection, final String sql) throws SQLException {
+ PreparedStatement result = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+ result.setFetchSize(Integer.MIN_VALUE);
return result;
}
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-mysql/src/test/java/org/apache/shardingsphere/scaling/mysql/MySQLJdbcDumperTest.java b/shardingsphere-scaling/shardingsphere-scaling-mysql/src/test/java/org/apache/shardingsphere/scaling/mysql/MySQLJdbcDumperTest.java
index a91f3dd..0666e44 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-mysql/src/test/java/org/apache/shardingsphere/scaling/mysql/MySQLJdbcDumperTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-mysql/src/test/java/org/apache/shardingsphere/scaling/mysql/MySQLJdbcDumperTest.java
@@ -24,6 +24,9 @@ import org.apache.shardingsphere.scaling.core.config.JDBCScalingDataSourceConfig
import org.apache.shardingsphere.scaling.core.datasource.DataSourceManager;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -34,18 +37,20 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public final class MySQLJdbcDumperTest {
private DataSourceManager dataSourceManager;
private MySQLJdbcDumper mySQLJdbcDumper;
+ @Mock
+ private Connection connection;
+
@Before
public void setUp() {
dataSourceManager = new DataSourceManager();
@@ -92,10 +97,8 @@ public final class MySQLJdbcDumperTest {
@Test
public void assertCreatePreparedStatement() throws SQLException {
- DataSource dataSource = dataSourceManager.getDataSource(mockDumperConfiguration().getDataSourceConfiguration());
- try (Connection connection = dataSource.getConnection();
- PreparedStatement preparedStatement = mySQLJdbcDumper.createPreparedStatement(connection, "SELECT * FROM t_order")) {
- assertThat(preparedStatement.getFetchSize(), is(100));
- }
+ when(connection.prepareStatement("", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)).thenReturn(mock(PreparedStatement.class));
+ PreparedStatement preparedStatement = mySQLJdbcDumper.createPreparedStatement(connection, "");
+ verify(preparedStatement).setFetchSize(Integer.MIN_VALUE);
}
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/PostgreSQLJdbcDumper.java b/shardingsphere-scaling/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/PostgreSQLJdbcDumper.java
index 9520882..5a29dc7 100755
--- a/shardingsphere-scaling/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/PostgreSQLJdbcDumper.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-postgresql/src/main/java/org/apache/shardingsphere/scaling/postgresql/PostgreSQLJdbcDumper.java
@@ -38,7 +38,7 @@ public final class PostgreSQLJdbcDumper extends AbstractJDBCDumper {
@Override
protected PreparedStatement createPreparedStatement(final Connection connection, final String sql) throws SQLException {
PreparedStatement result = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
- result.setFetchSize(100);
+ result.setFetchSize(1);
return result;
}
}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/PostgreSQLJdbcDumperTest.java b/shardingsphere-scaling/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/PostgreSQLJdbcDumperTest.java
index 1186344..767739f 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/PostgreSQLJdbcDumperTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-postgresql/src/test/java/org/apache/shardingsphere/scaling/postgresql/PostgreSQLJdbcDumperTest.java
@@ -70,7 +70,7 @@ public final class PostgreSQLJdbcDumperTest {
DataSource dataSource = dataSourceManager.getDataSource(mockDumperConfiguration().getDataSourceConfiguration());
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = postgreSQLJdbcDumper.createPreparedStatement(connection, "SELECT * FROM t_order")) {
- assertThat(preparedStatement.getFetchSize(), is(100));
+ assertThat(preparedStatement.getFetchSize(), is(1));
}
}