Skip to content

Commit 9577603

Browse files
committed
Fix issues.
1 parent 183aafc commit 9577603

File tree

4 files changed

+240
-250
lines changed

4 files changed

+240
-250
lines changed

src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,9 @@ void testQueriesReturningResult() {
268268
pstm.addBatch();
269269
assertThatExceptionOfType(BatchUpdateException.class)
270270
.isThrownBy(pstm::executeBatch)
271-
.satisfies(batchUpdateException -> {
272-
assertNull(batchUpdateException.getUpdateCounts());
273-
assertNull(batchUpdateException.getSQLState());
274-
assertEquals(0, batchUpdateException.getErrorCode());
275-
});
271+
.returns(null, BatchUpdateException::getUpdateCounts)
272+
.returns(null, BatchUpdateException::getSQLState)
273+
.returns(0, BatchUpdateException::getErrorCode);
276274
} catch (SQLException e) {
277275
throw new RuntimeException(e);
278276
}

src/main/java/com/mongodb/hibernate/jdbc/MongoPreparedStatement.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.mongodb.hibernate.internal.type.ObjectIdJdbcType;
2929
import java.math.BigDecimal;
3030
import java.sql.Array;
31+
import java.sql.BatchUpdateException;
3132
import java.sql.Date;
3233
import java.sql.JDBCType;
3334
import java.sql.PreparedStatement;
@@ -233,6 +234,22 @@ public int[] executeBatch() throws SQLException {
233234
}
234235
}
235236

237+
private void checkSupportedBatchCommand(BsonDocument command) throws SQLException {
238+
var commandType = getCommandType(command);
239+
if (commandType == CommandType.AGGREGATE) {
240+
// The method executeBatch throws a BatchUpdateException if any of the commands in the batch attempts to
241+
// return a result set.
242+
throw new BatchUpdateException(
243+
format(
244+
"Commands returning result set are not supported. Received command: %s",
245+
commandType.getCommandName()),
246+
null,
247+
NO_ERROR_CODE,
248+
null);
249+
}
250+
checkSupportedUpdateCommand(commandType);
251+
}
252+
236253
@Override
237254
public void setArray(int parameterIndex, Array x) throws SQLException {
238255
checkClosed();

0 commit comments

Comments
 (0)