Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed May 4, 2016
1 parent 36d8bce commit 2d1ad48
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ public Statement apply(final PreparedStatementExecutorWrapper input) {
});
}

@Override
public void clearRoutedStatements() throws SQLException {
getRoutedPreparedStatements().clear();
}

private void routeIfNeed() throws SQLException {
if (!cachedRoutedPreparedStatements.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,4 @@ public ResultSet getResultSet() throws SQLException {
public Collection<? extends Statement> getRoutedStatements() throws SQLException {
return cachedRoutedStatements.values();
}

@Override
public void clearRoutedStatements() throws SQLException {
cachedRoutedStatements.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

package com.dangdang.ddframe.rdb.sharding.jdbc.adapter;

import com.dangdang.ddframe.rdb.sharding.jdbc.unsupported.AbstractUnsupportedOperationStatement;
import lombok.RequiredArgsConstructor;

import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.Collection;

import com.dangdang.ddframe.rdb.sharding.jdbc.unsupported.AbstractUnsupportedOperationStatement;

import lombok.RequiredArgsConstructor;

/**
* 静态语句对象适配类.
*
Expand Down Expand Up @@ -157,11 +156,4 @@ public final boolean getMoreResults(final int current) throws SQLException {
* @throws SQLException
*/
protected abstract Collection<? extends Statement> getRoutedStatements() throws SQLException;

/**
*  清除路由的静态语句对象集合.
*
* @throws SQLException
*/
public abstract void clearRoutedStatements() throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void assertExecuteQueryWithColumnNames() throws SQLException {
}

@Test
public void assertBatch() throws SQLException {
public void assertAddBatch() throws SQLException {
String sql = "INSERT INTO `t_order`(`order_id`, `user_id`, `status`) VALUES (?,?,?)";
try (
Connection connection = shardingDataSource.getConnection();
Expand All @@ -210,4 +210,19 @@ public void assertBatch() throws SQLException {
}
}
}

@Test(expected = IllegalStateException.class)
public void assertClearBatch() throws SQLException {
String sql = "INSERT INTO `t_order`(`order_id`, `user_id`, `status`) VALUES (?,?,?)";
try (
Connection connection = shardingDataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setInt(1, 3101);
preparedStatement.setInt(2, 11);
preparedStatement.setString(3, "BATCH");
preparedStatement.addBatch();
preparedStatement.clearBatch();
preparedStatement.executeBatch();
}
}
}

0 comments on commit 2d1ad48

Please sign in to comment.