Skip to content

Commit

Permalink
JAVA-1879: Duplicate basic.request options as Statement attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tolbertam authored and olim7t committed Jul 10, 2018
1 parent 2b9d189 commit 6fe9585
Show file tree
Hide file tree
Showing 25 changed files with 1,255 additions and 149 deletions.
1 change: 1 addition & 0 deletions changelog/README.md
Expand Up @@ -4,6 +4,7 @@

### 4.0.0-beta1 (in progress)

- [improvement] JAVA-1879: Duplicate basic.request options as Request/Statement attributes
- [improvement] JAVA-1870: Use sensible defaults in RequestLogger if config options are missing
- [improvement] JAVA-1877: Use a separate reconnection schedule for the control connection
- [improvement] JAVA-1763: Generate a binary tarball as part of the build process
Expand Down
Expand Up @@ -56,6 +56,10 @@ static BatchStatement newInstance(@NonNull BatchType batchType) {
false,
false,
Long.MIN_VALUE,
null,
Integer.MIN_VALUE,
null,
null,
null);
}

Expand All @@ -79,6 +83,10 @@ static BatchStatement newInstance(
false,
false,
Long.MIN_VALUE,
null,
Integer.MIN_VALUE,
null,
null,
null);
}

Expand Down
Expand Up @@ -142,6 +142,10 @@ public BatchStatement build() {
idempotent,
tracing,
timestamp,
pagingState);
pagingState,
pageSize,
consistencyLevel,
serialConsistencyLevel,
timeout);
}
}
Expand Up @@ -130,6 +130,10 @@ public BoundStatement build() {
tracing,
timestamp,
pagingState,
pageSize,
consistencyLevel,
serialConsistencyLevel,
timeout,
codecRegistry,
protocolVersion);
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package com.datastax.oss.driver.api.core.cql;

import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.config.DriverConfigProfile;
import com.datastax.oss.driver.api.core.retry.RetryPolicy;
Expand Down Expand Up @@ -110,4 +111,24 @@ default boolean isTracing() {
*/
@Nullable
Boolean areBoundStatementsIdempotent();

/**
* The page size to use for the bound statements that will be created from the prepared statement.
* If the value is 0 or negative, the default value will be used from the configuration.
*/
int getPageSizeForBoundStatements();

/**
* The consistency level to use for the bound statements that will be created from the prepared
* statement or {@link null} to use the default value from the configuration.
*/
@Nullable
ConsistencyLevel getConsistencyLevelForBoundStatements();

/**
* The serial consistency level to use for the bound statements that will be created from the
* prepared statement or {@code null} to use the default value from the configuration.
*/
@Nullable
ConsistencyLevel getSerialConsistencyLevelForBoundStatements();
}
Expand Up @@ -73,6 +73,10 @@ static SimpleStatement newInstance(@NonNull String cqlQuery) {
null,
false,
Long.MIN_VALUE,
null,
Integer.MIN_VALUE,
null,
null,
null);
}

Expand All @@ -99,6 +103,10 @@ static SimpleStatement newInstance(
null,
false,
Long.MIN_VALUE,
null,
Integer.MIN_VALUE,
null,
null,
null);
}

Expand All @@ -122,6 +130,10 @@ static SimpleStatement newInstance(
null,
false,
Long.MIN_VALUE,
null,
Integer.MIN_VALUE,
null,
null,
null);
}

Expand Down
Expand Up @@ -172,6 +172,10 @@ public SimpleStatement build() {
idempotent,
tracing,
timestamp,
pagingState);
pagingState,
pageSize,
consistencyLevel,
serialConsistencyLevel,
timeout);
}
}
Expand Up @@ -15,8 +15,10 @@
*/
package com.datastax.oss.driver.api.core.cql;

import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigProfile;
import com.datastax.oss.driver.api.core.context.DriverContext;
import com.datastax.oss.driver.api.core.metadata.token.Token;
Expand All @@ -28,6 +30,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.CompletionStage;

Expand Down Expand Up @@ -195,6 +198,17 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
@NonNull
T setTimestamp(long newTimestamp);

/**
* Sets how long to wait for this request to complete. This is a global limit on the duration of a
* session.execute() call, including any retries the driver might do.
*
* @param newTimeout the timeout to use, or {@code null} to use the default value defined in the
* configuration.
* @see DefaultDriverOption#REQUEST_TIMEOUT
*/
@NonNull
T setTimeout(@Nullable Duration newTimeout);

/**
* Returns the paging state to send with the statement, or {@code null} if this statement has no
* paging state.
Expand Down Expand Up @@ -225,6 +239,65 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
@NonNull
T setPagingState(@Nullable ByteBuffer newPagingState);

/**
* Returns the page size to use for the statement.
*
* @return the set page size, otherwise 0 or a negative value to use the default value defined in
* the configuration.
* @see DefaultDriverOption#REQUEST_PAGE_SIZE
*/
int getPageSize();

/**
* Configures how many rows will be retrieved simultaneously in a single network roundtrip (the
* goal being to avoid loading too many results in memory at the same time).
*
* @param newPageSize the page size to use, set to 0 or a negative value to use the default value
* defined in the configuration.
* @see DefaultDriverOption#REQUEST_PAGE_SIZE
*/
@NonNull
T setPageSize(int newPageSize);

/**
* Returns the {@link ConsistencyLevel} to use for the statement.
*
* @return the set consistency, or {@code null} to use the default value defined in the
* configuration.
* @see DefaultDriverOption#REQUEST_CONSISTENCY
*/
@Nullable
ConsistencyLevel getConsistencyLevel();

/**
* Sets the {@link ConsistencyLevel} to use for this statement.
*
* @param newConsistencyLevel the consistency level to use, or null to use the default value
* defined in the configuration.
* @see DefaultDriverOption#REQUEST_CONSISTENCY
*/
T setConsistencyLevel(@Nullable ConsistencyLevel newConsistencyLevel);

/**
* Returns the serial {@link ConsistencyLevel} to use for the statement.
*
* @return the set serial consistency, or {@code null} to use the default value defined in the
* configuration.
* @see DefaultDriverOption#REQUEST_SERIAL_CONSISTENCY
*/
@Nullable
ConsistencyLevel getSerialConsistencyLevel();

/**
* Sets the serial {@link ConsistencyLevel} to use for this statement.
*
* @param newSerialConsistencyLevel the serial consistency level to use, or null to use the
* default value defined in the configuration.
* @see DefaultDriverOption#REQUEST_SERIAL_CONSISTENCY
*/
@NonNull
T setSerialConsistencyLevel(@Nullable ConsistencyLevel newSerialConsistencyLevel);

/**
* Calculates the approximate size in bytes that the statement will have when encoded.
*
Expand Down
Expand Up @@ -15,13 +15,15 @@
*/
package com.datastax.oss.driver.api.core.cql;

import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.config.DriverConfigProfile;
import com.datastax.oss.driver.api.core.metadata.token.Token;
import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.Map;
import net.jcip.annotations.NotThreadSafe;

Expand All @@ -48,6 +50,10 @@ public abstract class StatementBuilder<T extends StatementBuilder<T, S>, S exten
protected boolean tracing;
protected long timestamp = Long.MIN_VALUE;
@Nullable protected ByteBuffer pagingState;
protected int pageSize = Integer.MIN_VALUE;
@Nullable protected ConsistencyLevel consistencyLevel;
@Nullable protected ConsistencyLevel serialConsistencyLevel;
@Nullable protected Duration timeout;

protected StatementBuilder() {
// nothing to do
Expand All @@ -62,6 +68,10 @@ protected StatementBuilder(S template) {
this.tracing = template.isTracing();
this.timestamp = template.getTimestamp();
this.pagingState = template.getPagingState();
this.pageSize = template.getPageSize();
this.consistencyLevel = template.getConsistencyLevel();
this.serialConsistencyLevel = template.getSerialConsistencyLevel();
this.timeout = template.getTimeout();
}

/** @see Statement#setConfigProfileName(String) */
Expand Down Expand Up @@ -155,6 +165,34 @@ public T withPagingState(@Nullable ByteBuffer pagingState) {
return self;
}

/** @see Statement#setPageSize(int) */
@NonNull
public T withPageSize(int pageSize) {
this.pageSize = pageSize;
return self;
}

/** @see Statement#setConsistencyLevel(ConsistencyLevel) */
@NonNull
public T withConsistencyLevel(@Nullable ConsistencyLevel consistencyLevel) {
this.consistencyLevel = consistencyLevel;
return self;
}

/** @see Statement#setSerialConsistencyLevel(ConsistencyLevel) */
@NonNull
public T withSerialConsistencyLevel(@Nullable ConsistencyLevel serialConsistencyLevel) {
this.serialConsistencyLevel = serialConsistencyLevel;
return self;
}

/** @see Statement#setTimeout(Duration) */
@NonNull
public T withTimeout(@Nullable Duration timeout) {
this.timeout = timeout;
return self;
}

@NonNull
protected Map<String, ByteBuffer> buildCustomPayload() {
return (customPayloadBuilder == null)
Expand Down
Expand Up @@ -24,6 +24,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.Map;

/**
Expand Down Expand Up @@ -149,6 +150,17 @@ public interface Request {
@Nullable
Boolean isIdempotent();

/**
* How long to wait for this request to complete. This is a global limit on the duration of a
* session.execute() call, including any retries the driver might do.
*
* @return the set duration, or {@code null} to use the default value defined in the
* configuration.
* @see DefaultDriverOption#REQUEST_TIMEOUT
*/
@Nullable
Duration getTimeout();

/**
* Whether tracing information should be recorded for this request.
*
Expand Down

0 comments on commit 6fe9585

Please sign in to comment.