提交 5ec810e4 编写于 作者: T terrymanu

refactor resultSetHoldability for ShardingStatement and ShardingPreparedStatement

上级 0325634d
......@@ -179,9 +179,6 @@ public final class ShardingPreparedStatement extends AbstractPreparedStatementAd
if (isReturnGeneratedKeys() && generatedKey.isPresent()) {
return new BackendPreparedStatementWrapper(conn.prepareStatement(shardingSql, Statement.RETURN_GENERATED_KEYS), shardingSql);
}
if (0 != getResultSetHoldability()) {
return new BackendPreparedStatementWrapper(conn.prepareStatement(shardingSql, getResultSetType(), getResultSetConcurrency(), getResultSetHoldability()), shardingSql);
}
return new BackendPreparedStatementWrapper(conn.prepareStatement(shardingSql, getResultSetType(), getResultSetConcurrency()), shardingSql);
return new BackendPreparedStatementWrapper(conn.prepareStatement(shardingSql, getResultSetType(), getResultSetConcurrency(), getResultSetHoldability()), shardingSql);
}
}
......@@ -258,13 +258,7 @@ public class ShardingStatement extends AbstractStatementAdapter {
}
protected BackendStatementWrapper generateStatement(final Connection connection, final String sql) throws SQLException {
Statement result;
if (0 == resultSetHoldability) {
result = connection.createStatement(resultSetType, resultSetConcurrency);
} else {
result = connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
}
return new BackendStatementWrapper(result);
return new BackendStatementWrapper(connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
}
@Override
......
......@@ -175,19 +175,6 @@ public final class ShardingPreparedStatementTest extends AbstractShardingDataBas
}
}
@Test
public void assertExecuteQueryWithResultSetHoldabilityIsZero() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = ?";
try (
Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, 0)) {
preparedStatement.setString(1, "init");
ResultSet resultSet = preparedStatement.executeQuery();
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
}
}
@Test
public void assertExecuteQueryWithAutoGeneratedKeys() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = ?";
......
......@@ -98,18 +98,6 @@ public final class ShardingStatementTest extends AbstractShardingDataBasesOnlyDB
}
}
@Test
public void assertExecuteQueryWithResultSetHoldabilityIsZero() throws SQLException {
String sql = "SELECT COUNT(*) AS `orders_count` FROM `t_order` WHERE `status` = 'init'";
try (
Connection connection = shardingDataSource.getConnection();
Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, 0);
ResultSet resultSet = stmt.executeQuery(sql)) {
assertTrue(resultSet.next());
assertThat(resultSet.getLong(1), is(40L));
}
}
@Test
public void assertExecuteUpdateWithAutoGeneratedKeys() throws SQLException {
String sql = "DELETE FROM `t_order` WHERE `status` = 'init'";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册