Skip to content

Simplify Operations by uniting Sync and Async operations #1776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rozza
Copy link
Member

@rozza rozza commented Jul 24, 2025

Merged Async Read / Write Operations into their sync operations counterparts.

  • AsyncWriteOperation into WriteOperation is a simple merge
  • AsyncReadOperation into ReadOperation requires an additional type parameter This is due to async and sync cursors have different types.

Added extra ReadOperations interfaces to represent:

  • Read operations that return the same type for sync / async
  • Read operations that represent cursors

Removed SyncOperations and AsyncOperations builders which both use the same Operations builder class.

JAVA-5900

@rozza rozza requested a review from Copilot July 24, 2025 10:03
Copilot

This comment was marked as outdated.

@rozza rozza requested a review from Copilot July 24, 2025 14:03
Copilot

This comment was marked as outdated.

…e interface.

Merged Async Read / Write Operations into their sync operations counterparts.

* AsyncWriteOperation into WriteOperation is a simple merge
* AsyncReadOperation into ReadOperation requires an additional type parameter
  This is due to async and sync cursors have different types.

Added extra ReadOperations interfaces to represent:
  * Read operations that return the same type for sync / async
  * Read operations that represent cursors

Removed SyncOperations and AsyncOperations builders which both use the same Operations builder class.

JAVA-4900
@rozza rozza requested a review from Copilot July 24, 2025 14:18
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request unifies synchronous and asynchronous operations in the MongoDB Java driver by merging the previously separate AsyncReadOperation and AsyncWriteOperation interfaces into their sync counterparts. The key changes include adding an additional type parameter to ReadOperation to handle different sync and async return types, introducing new read operation interfaces for better type organization, removing the separate builder classes for sync/async operations, and consolidating all operation interfaces to work with both sync and async execution.

Key Changes

  • Merge AsyncReadOperation and AsyncWriteOperation interfaces into sync ReadOperation and WriteOperation interfaces
  • Add additional type parameter to ReadOperation<T, R> to support different return types for sync and async execution
  • Remove SyncOperations and AsyncOperations builder classes in favor of unified Operations class

Reviewed Changes

Copilot reviewed 79 out of 79 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
driver-core/src/main/com/mongodb/internal/operation/ReadOperation.java Added async execution method and second type parameter for different sync/async return types
driver-core/src/main/com/mongodb/internal/operation/WriteOperation.java Added async execution method to write operations
driver-core/src/main/com/mongodb/internal/operation/Operations.java Unified operations builder class with timeout settings support and public API
driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/ReadOperationCursorAsyncOnly.java New interface for async-only cursor operations with sync method throwing UnsupportedOperationException
driver-sync/src/main/com/mongodb/client/internal/OperationExecutor.java Updated method signatures to use new ReadOperation type parameter

@rozza rozza marked this pull request as ready for review July 24, 2025 15:04
@rozza rozza requested a review from a team as a code owner July 24, 2025 15:04
@rozza rozza requested review from nhachicha and removed request for a team July 24, 2025 15:04
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this class is used directly instead of being wrapped by Sync/AsyncOperations, consider changing the return values of the operation-return methods to be the interface types rather than the concrete types, as was done in AsyncOperations and SyncOperations.

Longer term, it would be nice if all the concrete operation classes were package private, and Operations was the only way to create them, but that's quite a bit more work (especially since the legacy driver doesn't use Operations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants