public class QueryOptions extends Object
Modifier and Type | Field and Description |
---|---|
static ConsistencyLevel |
DEFAULT_CONSISTENCY_LEVEL
The default consistency level for queries:
ConsistencyLevel.LOCAL_ONE . |
static int |
DEFAULT_FETCH_SIZE
The default fetch size for SELECT queries: 5000.
|
static boolean |
DEFAULT_IDEMPOTENCE
The default value for
getDefaultIdempotence() : false . |
static int |
DEFAULT_MAX_PENDING_REFRESH_NODE_LIST_REQUESTS |
static int |
DEFAULT_MAX_PENDING_REFRESH_NODE_REQUESTS |
static int |
DEFAULT_MAX_PENDING_REFRESH_SCHEMA_REQUESTS |
static int |
DEFAULT_REFRESH_NODE_INTERVAL_MILLIS |
static int |
DEFAULT_REFRESH_NODE_LIST_INTERVAL_MILLIS |
static int |
DEFAULT_REFRESH_SCHEMA_INTERVAL_MILLIS |
static ConsistencyLevel |
DEFAULT_SERIAL_CONSISTENCY_LEVEL
The default serial consistency level for conditional updates:
ConsistencyLevel.SERIAL . |
Constructor and Description |
---|
QueryOptions()
Creates a new
QueryOptions instance using the DEFAULT_CONSISTENCY_LEVEL ,
DEFAULT_SERIAL_CONSISTENCY_LEVEL and DEFAULT_FETCH_SIZE . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object that) |
ConsistencyLevel |
getConsistencyLevel()
The default consistency level used by queries.
|
boolean |
getDefaultIdempotence()
The default idempotence for queries.
|
int |
getFetchSize()
The default fetch size used by queries.
|
int |
getMaxPendingRefreshNodeListRequests()
Sets the maximum number of node list refresh requests that the control connection can
accumulate before executing them.
|
int |
getMaxPendingRefreshNodeRequests()
The maximum number of node refresh requests that the control connection can accumulate before
executing them.
|
int |
getMaxPendingRefreshSchemaRequests()
The maximum number of schema refresh requests that the control connection can accumulate before
executing them.
|
int |
getRefreshNodeIntervalMillis()
The default window size in milliseconds used to debounce node refresh requests.
|
int |
getRefreshNodeListIntervalMillis()
The default window size in milliseconds used to debounce node list refresh requests.
|
int |
getRefreshSchemaIntervalMillis()
The default window size in milliseconds used to debounce schema refresh requests.
|
ConsistencyLevel |
getSerialConsistencyLevel()
The default serial consistency level used by queries.
|
int |
hashCode() |
boolean |
isConsistencySet() |
boolean |
isMetadataEnabled()
Whether client-side token and schema metadata is enabled.
|
boolean |
isPrepareOnAllHosts()
Returns whether the driver should prepare statements on all hosts in the cluster.
|
boolean |
isReprepareOnUp()
Whether the driver should re-prepare all cached prepared statements on a host when its marks
that host back up.
|
QueryOptions |
setConsistencyLevel(ConsistencyLevel consistencyLevel)
Sets the default consistency level to use for queries.
|
QueryOptions |
setDefaultIdempotence(boolean defaultIdempotence)
Sets the default idempotence for queries.
|
QueryOptions |
setFetchSize(int fetchSize)
Sets the default fetch size to use for SELECT queries.
|
QueryOptions |
setMaxPendingRefreshNodeListRequests(int maxPendingRefreshNodeListRequests)
Sets the maximum number of node list refresh requests that the control connection can
accumulate before executing them.
|
QueryOptions |
setMaxPendingRefreshNodeRequests(int maxPendingRefreshNodeRequests)
Sets the maximum number of node refresh requests that the control connection can accumulate
before executing them.
|
QueryOptions |
setMaxPendingRefreshSchemaRequests(int maxPendingRefreshSchemaRequests)
Sets the maximum number of schema refresh requests that the control connection can accumulate
before executing them.
|
QueryOptions |
setMetadataEnabled(boolean enabled)
Toggle client-side token and schema metadata.
|
QueryOptions |
setPrepareOnAllHosts(boolean prepareOnAllHosts)
Set whether the driver should prepare statements on all hosts in the cluster.
|
QueryOptions |
setRefreshNodeIntervalMillis(int refreshNodeIntervalMillis)
Sets the default window size in milliseconds used to debounce node refresh requests.
|
QueryOptions |
setRefreshNodeListIntervalMillis(int refreshNodeListIntervalMillis)
Sets the default window size in milliseconds used to debounce node list refresh requests.
|
QueryOptions |
setRefreshSchemaIntervalMillis(int refreshSchemaIntervalMillis)
Sets the default window size in milliseconds used to debounce node list refresh requests.
|
QueryOptions |
setReprepareOnUp(boolean reprepareOnUp)
Set whether the driver should re-prepare all cached prepared statements on a host when it marks
it back up.
|
QueryOptions |
setSerialConsistencyLevel(ConsistencyLevel serialConsistencyLevel)
Sets the default serial consistency level to use for queries.
|
public static final ConsistencyLevel DEFAULT_CONSISTENCY_LEVEL
ConsistencyLevel.LOCAL_ONE
.public static final ConsistencyLevel DEFAULT_SERIAL_CONSISTENCY_LEVEL
ConsistencyLevel.SERIAL
.public static final int DEFAULT_FETCH_SIZE
public static final boolean DEFAULT_IDEMPOTENCE
getDefaultIdempotence()
: false
.public static final int DEFAULT_MAX_PENDING_REFRESH_NODE_LIST_REQUESTS
public static final int DEFAULT_MAX_PENDING_REFRESH_NODE_REQUESTS
public static final int DEFAULT_MAX_PENDING_REFRESH_SCHEMA_REQUESTS
public static final int DEFAULT_REFRESH_NODE_LIST_INTERVAL_MILLIS
public static final int DEFAULT_REFRESH_NODE_INTERVAL_MILLIS
public static final int DEFAULT_REFRESH_SCHEMA_INTERVAL_MILLIS
public QueryOptions()
QueryOptions
instance using the DEFAULT_CONSISTENCY_LEVEL
,
DEFAULT_SERIAL_CONSISTENCY_LEVEL
and DEFAULT_FETCH_SIZE
.public QueryOptions setConsistencyLevel(ConsistencyLevel consistencyLevel)
The consistency level set through this method will be use for queries that don't explicitly
have a consistency level, i.e. when Statement.getConsistencyLevel()
returns null
.
consistencyLevel
- the new consistency level to set as default.QueryOptions
instance.public ConsistencyLevel getConsistencyLevel()
public QueryOptions setSerialConsistencyLevel(ConsistencyLevel serialConsistencyLevel)
The serial consistency level set through this method will be use for queries that don't
explicitly have a serial consistency level, i.e. when Statement.getSerialConsistencyLevel()
returns null
.
serialConsistencyLevel
- the new serial consistency level to set as default.QueryOptions
instance.public ConsistencyLevel getSerialConsistencyLevel()
public QueryOptions setFetchSize(int fetchSize)
The fetch size set through this method will be use for queries that don't explicitly have a
fetch size, i.e. when Statement.getFetchSize()
is less or equal to 0.
fetchSize
- the new fetch size to set as default. It must be strictly positive but you can
use Integer.MAX_VALUE
to disable paging.QueryOptions
instance.IllegalArgumentException
- if fetchSize <e; 0
.UnsupportedFeatureException
- if version 1 of the native protocol is in use and fetchSize != Integer.MAX_VALUE
as paging is not supported by version 1 of the protocol.
See Cluster.Builder.withProtocolVersion(com.datastax.driver.core.ProtocolVersion)
for more details on protocol versions.public int getFetchSize()
public QueryOptions setDefaultIdempotence(boolean defaultIdempotence)
This will be used for statements for which Statement.isIdempotent()
returns null
.
defaultIdempotence
- the new value to set as default idempotence.QueryOptions
instance.public boolean getDefaultIdempotence()
It defaults to DEFAULT_IDEMPOTENCE
.
public QueryOptions setPrepareOnAllHosts(boolean prepareOnAllHosts)
A statement is normally prepared in two steps:
The reason why you might want to disable it is to optimize network usage if you have a large number of clients preparing the same set of statements at startup. If your load balancing policy distributes queries randomly, each client will pick a different host to prepare its statements, and on the whole each host has a good chance of having been hit by at least one client for each statement.
On the other hand, if that assumption turns out to be wrong and one host hasn't prepared a given statement, it needs to be re-prepared on the fly the first time it gets executed; this causes a performance penalty (one extra roundtrip to resend the query to prepare, and another to retry the execution).
prepareOnAllHosts
- the new value to set to indicate whether to prepare statements once or
on all nodes.QueryOptions
instance.public boolean isPrepareOnAllHosts()
setPrepareOnAllHosts(boolean)
public QueryOptions setReprepareOnUp(boolean reprepareOnUp)
This option is enabled by default.
The reason why you might want to disable it is to optimize reconnection time when you believe hosts often get marked down because of temporary network issues, rather than the host really crashing. In that case, the host still has prepared statements in its cache when the driver reconnects, so re-preparing is redundant.
On the other hand, if that assumption turns out to be wrong and the host had really restarted, its prepared statement cache is empty, and statements need to be re-prepared on the fly the first time they get executed; this causes a performance penalty (one extra roundtrip to resend the query to prepare, and another to retry the execution).
reprepareOnUp
- whether the driver should re-prepare when marking a node up.QueryOptions
instance.public boolean isReprepareOnUp()
setReprepareOnUp(boolean)
public QueryOptions setMetadataEnabled(boolean enabled)
This feature is enabled by default. Some applications might wish to disable it in order to eliminate the overhead of querying the metadata and building its client-side representation. However, take note that doing so will have important consequences:
Metadata
will return stale or null/empty
results (see the javadoc of each method for details);
Metadata.newToken(String)
and Metadata.newTokenRange(Token, Token)
will
throw an exception if metadata was disabled before startup;
TokenAwarePolicy
will always delegate to its child
policy. Otherwise, it might not pick the best coordinator (i.e. chose a host that is not
a replica for the statement's routing key). In addition, statements prepared while the
metadata was disabled might also be sent to a non-optimal coordinator, even if metadata
was re-enabled later.
enabled
- whether metadata is enabled.QueryOptions
instance.public boolean isMetadataEnabled()
setMetadataEnabled(boolean)
public QueryOptions setRefreshSchemaIntervalMillis(int refreshSchemaIntervalMillis)
When the control connection receives a new schema refresh request, it puts it on hold and starts a timer, cancelling any previous running timer; when a timer expires, then the pending requests are coalesced and executed as a single request.
refreshSchemaIntervalMillis
- The default window size in milliseconds used to debounce
schema refresh requests.public int getRefreshSchemaIntervalMillis()
public QueryOptions setMaxPendingRefreshSchemaRequests(int maxPendingRefreshSchemaRequests)
When the control connection receives a new schema refresh request, it puts it on hold and starts a timer, cancelling any previous running timer; if the control connection receives too many events, is parameter allows to trigger execution of pending requests, event if the last timer is still running.
maxPendingRefreshSchemaRequests
- The maximum number of schema refresh requests that the
control connection can accumulate before executing them.public int getMaxPendingRefreshSchemaRequests()
public QueryOptions setRefreshNodeListIntervalMillis(int refreshNodeListIntervalMillis)
When the control connection receives a new node list refresh request, it puts it on hold and starts a timer, cancelling any previous running timer; when a timer expires, then the pending requests are coalesced and executed as a single request.
refreshNodeListIntervalMillis
- The default window size in milliseconds used to debounce
node list refresh requests.public int getRefreshNodeListIntervalMillis()
public QueryOptions setMaxPendingRefreshNodeListRequests(int maxPendingRefreshNodeListRequests)
When the control connection receives a new node list refresh request, it puts it on hold and starts a timer, cancelling any previous running timer; if the control connection receives too many events, is parameter allows to trigger execution of pending requests, event if the last timer is still running.
maxPendingRefreshNodeListRequests
- The maximum number of node list refresh requests that
the control connection can accumulate before executing them.public int getMaxPendingRefreshNodeListRequests()
public QueryOptions setRefreshNodeIntervalMillis(int refreshNodeIntervalMillis)
When the control connection receives a new node refresh request, it puts it on hold and starts a timer, cancelling any previous running timer; when a timer expires, then the pending requests are coalesced and executed as a single request.
refreshNodeIntervalMillis
- The default window size in milliseconds used to debounce node
refresh requests.public int getRefreshNodeIntervalMillis()
public QueryOptions setMaxPendingRefreshNodeRequests(int maxPendingRefreshNodeRequests)
When the control connection receives a new node refresh request, it puts it on hold and starts a timer, cancelling any previous running timer; if the control connection receives too many events, is parameter allows to trigger execution of pending requests, event if the last timer is still running.
maxPendingRefreshNodeRequests
- The maximum number of node refresh requests that the
control connection can accumulate before executing them.public int getMaxPendingRefreshNodeRequests()
public boolean isConsistencySet()
Copyright © 2012–2019. All rights reserved.