Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### 4.4.0 (in progress)

- [bug] JAVA-2556: Make ExecutionInfo compatible with any Request type
- [new feature] JAVA-2532: Add BoundStatement ReturnType for insert, update, and delete DAO methods
- [improvement] JAVA-2107: Add XML formatting plugin
- [bug] JAVA-2527: Allow AllNodesFailedException to accept more than one error per node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.retry.RetryDecision;
import com.datastax.oss.driver.api.core.servererrors.CoordinatorException;
import com.datastax.oss.driver.api.core.session.Request;
import com.datastax.oss.driver.api.core.session.Session;
import com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy;
import com.datastax.oss.driver.internal.core.util.concurrent.BlockingOperation;
Expand All @@ -45,8 +46,20 @@
*/
public interface ExecutionInfo {

/** The statement that was executed. */
/** @return The {@link Request} that was executed. */
@NonNull
default Request getRequest() {
return getStatement();
}

/**
* @return The {@link Request} that was executed, if it can be cast to {@link Statement}.
* @deprecated Use {@link #getRequest()} instead.
* @throws ClassCastException If the request that was executed cannot be cast to {@link
* Statement}.
*/
@NonNull
@Deprecated
Statement<?> getStatement();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public static AsyncResultSet toResultSet(
InternalDriverContext context) {
if (result instanceof Rows) {
Rows rows = (Rows) result;
Statement<?> statement = executionInfo.getStatement();
Statement<?> statement = (Statement<?>) executionInfo.getRequest();
ColumnDefinitions columnDefinitions = getResultDefinitions(rows, statement, context);
return new DefaultAsyncResultSet(
columnDefinitions, executionInfo, rows.getData(), session, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public CompletionStage<AsyncResultSet> fetchNextPage() throws IllegalStateExcept
throw new IllegalStateException(
"No next page. Use #hasMorePages before calling this method to avoid this error.");
}
Statement<?> statement = executionInfo.getStatement();
Statement<?> statement = (Statement<?>) executionInfo.getRequest();
LOG.trace("Fetching next page for {}", statement);
Statement<?> nextStatement = statement.copy(nextState);
return session.executeAsync(nextStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.datastax.oss.driver.api.core.cql.QueryTrace;
import com.datastax.oss.driver.api.core.cql.Statement;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.session.Request;
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
import com.datastax.oss.driver.internal.core.session.DefaultSession;
import com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures;
Expand All @@ -37,7 +38,7 @@
@Immutable
public class DefaultExecutionInfo implements ExecutionInfo {

private final Statement<?> statement;
private final Request request;
private final Node coordinator;
private final int speculativeExecutionCount;
private final int successfulExecutionIndex;
Expand All @@ -54,7 +55,7 @@ public class DefaultExecutionInfo implements ExecutionInfo {
private final DriverExecutionProfile executionProfile;

public DefaultExecutionInfo(
Statement<?> statement,
Request request,
Node coordinator,
int speculativeExecutionCount,
int successfulExecutionIndex,
Expand All @@ -65,7 +66,8 @@ public DefaultExecutionInfo(
DefaultSession session,
InternalDriverContext context,
DriverExecutionProfile executionProfile) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Semi-nit: is there a reason not to make this the lone constructor? Any existing usages of the Statement constructor will transparently work here (given the inheritance hierarchy)... and it avoids a mostly artificial bifurcation between the current two constructors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think you have a valid point here. I kept the old constructor thinking backwards compatibility, but in hindsight, this is an internal class and backwards compatibility isn't a requirement here. So I will remove the deprecated constructor as you suggested. Thanks!

this.statement = statement;

this.request = request;
this.coordinator = coordinator;
this.speculativeExecutionCount = speculativeExecutionCount;
this.successfulExecutionIndex = successfulExecutionIndex;
Expand All @@ -86,8 +88,15 @@ public DefaultExecutionInfo(

@NonNull
@Override
@Deprecated
public Statement<?> getStatement() {
return statement;
return (Statement<?>) request;
}

@NonNull
@Override
public Request getRequest() {
return request;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void should_share_iteration_progress_with_wrapped_result_set() {

private ExecutionInfo mockExecutionInfo() {
ExecutionInfo executionInfo = mock(ExecutionInfo.class);
when(executionInfo.getStatement()).thenAnswer(invocation -> statement);
when(executionInfo.getRequest()).thenAnswer(invocation -> statement);
return executionInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class DefaultAsyncResultSetTest {
public void setup() {
MockitoAnnotations.initMocks(this);

when(executionInfo.getStatement()).thenAnswer(invocation -> statement);
when(executionInfo.getRequest()).thenAnswer(invocation -> statement);
when(context.getCodecRegistry()).thenReturn(CodecRegistry.DEFAULT);
when(context.getProtocolVersion()).thenReturn(DefaultProtocolVersion.DEFAULT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public void should_expose_execution_info_on_exceptions() {
assertThat(info).isNotNull();
assertThat(info.getCoordinator().getEndPoint().resolve())
.isEqualTo(SIMULACRON_RULE.cluster().node(1).inetSocketAddress());
assertThat(((SimpleStatement) info.getStatement()).getQuery())
.isEqualTo(QUERY_STRING);
assertThat(((SimpleStatement) info.getRequest()).getQuery()).isEqualTo(QUERY_STRING);

// specex disabled => the initial execution completed the response
assertThat(info.getSpeculativeExecutionCount()).isEqualTo(0);
Expand Down