提交 48c74f22 编写于 作者: T terrymanu

Merge remote-tracking branch 'origin/1.5.4-SNAPSHOT' into 2.0.0.M1

...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
1. [ISSUE #356](https://github.com/dangdangdotcom/sharding-jdbc/issues/356) 在SQL的Where条件中兼容不是分片列的REGEXP操作符 1. [ISSUE #356](https://github.com/dangdangdotcom/sharding-jdbc/issues/356) 在SQL的Where条件中兼容不是分片列的REGEXP操作符
1. [ISSUE #362](https://github.com/dangdangdotcom/sharding-jdbc/issues/362) 读写分离使用PreparedStatement并未调用setParameter方法导致出错 1. [ISSUE #362](https://github.com/dangdangdotcom/sharding-jdbc/issues/362) 读写分离使用PreparedStatement并未调用setParameter方法导致出错
1. [ISSUE #370](https://github.com/dangdangdotcom/sharding-jdbc/issues/370) 使用原生自增主键调用getGeneratedKeys出错
## 1.5.3 ## 1.5.3
......
...@@ -174,19 +174,9 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta ...@@ -174,19 +174,9 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta
} }
private PreparedStatement generatePreparedStatement(final SQLExecutionUnit sqlExecutionUnit) throws SQLException { private PreparedStatement generatePreparedStatement(final SQLExecutionUnit sqlExecutionUnit) throws SQLException {
Optional<GeneratedKey> generatedKey = getGeneratedKey();
Connection connection = getConnection().getConnection(sqlExecutionUnit.getDataSource(), routeResult.getSqlStatement().getType()); Connection connection = getConnection().getConnection(sqlExecutionUnit.getDataSource(), routeResult.getSqlStatement().getType());
if (returnGeneratedKeys && generatedKey.isPresent()) { return returnGeneratedKeys ? connection.prepareStatement(sqlExecutionUnit.getSql(), RETURN_GENERATED_KEYS)
return connection.prepareStatement(sqlExecutionUnit.getSql(), RETURN_GENERATED_KEYS); : connection.prepareStatement(sqlExecutionUnit.getSql(), resultSetType, resultSetConcurrency, resultSetHoldability);
}
return connection.prepareStatement(sqlExecutionUnit.getSql(), resultSetType, resultSetConcurrency, resultSetHoldability);
}
private Optional<GeneratedKey> getGeneratedKey() {
if (null != routeResult && routeResult.getSqlStatement() instanceof InsertStatement) {
return Optional.fromNullable(((InsertStatement) routeResult.getSqlStatement()).getGeneratedKey());
}
return Optional.absent();
} }
@Override @Override
...@@ -211,28 +201,6 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta ...@@ -211,28 +201,6 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta
} }
} }
@Override
public int[] executeBatch() throws SQLException {
try {
return new BatchPreparedStatementExecutor(getConnection().getShardingContext().getExecutorEngine(),
getConnection().getShardingContext().getDatabaseType(), routeResult.getSqlStatement().getType(), batchStatementUnits, parameterSets).executeBatch();
} finally {
clearBatch();
}
}
@Override
public ResultSet getGeneratedKeys() throws SQLException {
Optional<GeneratedKey> generatedKey = getGeneratedKey();
if (returnGeneratedKeys && generatedKey.isPresent()) {
return new GeneratedKeysResultSet(routeResult.getGeneratedKeys().iterator(), generatedKey.get().getColumn(), this);
}
if (1 == routedStatements.size()) {
return routedStatements.iterator().next().getGeneratedKeys();
}
return new GeneratedKeysResultSet();
}
private List<BatchPreparedStatementUnit> routeBatch() throws SQLException { private List<BatchPreparedStatementUnit> routeBatch() throws SQLException {
List<BatchPreparedStatementUnit> result = new ArrayList<>(); List<BatchPreparedStatementUnit> result = new ArrayList<>();
routeResult = routingEngine.route(getParameters()); routeResult = routingEngine.route(getParameters());
...@@ -260,6 +228,35 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta ...@@ -260,6 +228,35 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta
return result; return result;
} }
@Override
public int[] executeBatch() throws SQLException {
try {
return new BatchPreparedStatementExecutor(getConnection().getShardingContext().getExecutorEngine(),
getConnection().getShardingContext().getDatabaseType(), routeResult.getSqlStatement().getType(), batchStatementUnits, parameterSets).executeBatch();
} finally {
clearBatch();
}
}
@Override
public ResultSet getGeneratedKeys() throws SQLException {
Optional<GeneratedKey> generatedKey = getGeneratedKey();
if (returnGeneratedKeys && generatedKey.isPresent()) {
return new GeneratedKeysResultSet(routeResult.getGeneratedKeys().iterator(), generatedKey.get().getColumn(), this);
}
if (1 == routedStatements.size()) {
return routedStatements.iterator().next().getGeneratedKeys();
}
return new GeneratedKeysResultSet();
}
private Optional<GeneratedKey> getGeneratedKey() {
if (null != routeResult && routeResult.getSqlStatement() instanceof InsertStatement) {
return Optional.fromNullable(((InsertStatement) routeResult.getSqlStatement()).getGeneratedKey());
}
return Optional.absent();
}
@Override @Override
public ResultSet getResultSet() throws SQLException { public ResultSet getResultSet() throws SQLException {
if (null != currentResultSet) { if (null != currentResultSet) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册