Class QueryOptions
- java.lang.Object
-
- com.datastax.driver.core.QueryOptions
-
public class QueryOptions extends Object
Options related to defaults for individual queries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQueryOptions.CQL4SkipMetadataResolveMethodstatic classQueryOptions.RequestRoutingMethodThe request routing method for queries.
-
Field Summary
Fields Modifier and Type Field Description static ConsistencyLevelDEFAULT_CONSISTENCY_LEVELThe default consistency level for queries:ConsistencyLevel.LOCAL_ONE.static intDEFAULT_FETCH_SIZEThe default fetch size for SELECT queries: 5000.static booleanDEFAULT_IDEMPOTENCEThe default value forgetDefaultIdempotence():false.static QueryOptions.RequestRoutingMethodDEFAULT_LOAD_BALANCING_LWT_REQUEST_ROUTING_METHODstatic intDEFAULT_MAX_PENDING_REFRESH_NODE_LIST_REQUESTSstatic intDEFAULT_MAX_PENDING_REFRESH_NODE_REQUESTSstatic intDEFAULT_MAX_PENDING_REFRESH_SCHEMA_REQUESTSstatic intDEFAULT_REFRESH_NODE_INTERVAL_MILLISstatic intDEFAULT_REFRESH_NODE_LIST_INTERVAL_MILLISstatic intDEFAULT_REFRESH_SCHEMA_INTERVAL_MILLISstatic ConsistencyLevelDEFAULT_SERIAL_CONSISTENCY_LEVELThe default serial consistency level for conditional updates:ConsistencyLevel.SERIAL.
-
Constructor Summary
Constructors Constructor Description QueryOptions()Creates a newQueryOptionsinstance using theDEFAULT_CONSISTENCY_LEVEL,DEFAULT_SERIAL_CONSISTENCY_LEVELandDEFAULT_FETCH_SIZE.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object that)ConsistencyLevelgetConsistencyLevel()The default consistency level used by queries.booleangetDefaultIdempotence()The default idempotence for queries.intgetFetchSize()The default fetch size used by queries.QueryOptions.RequestRoutingMethodgetLoadBalancingLwtRequestRoutingMethod()The default request routing method used by LWT queries.intgetMaxPendingRefreshNodeListRequests()Sets the maximum number of node list refresh requests that the control connection can accumulate before executing them.intgetMaxPendingRefreshNodeRequests()The maximum number of node refresh requests that the control connection can accumulate before executing them.intgetMaxPendingRefreshSchemaRequests()The maximum number of schema refresh requests that the control connection can accumulate before executing them.intgetRefreshNodeIntervalMillis()The default window size in milliseconds used to debounce node refresh requests.intgetRefreshNodeListIntervalMillis()The default window size in milliseconds used to debounce node list refresh requests.intgetRefreshSchemaIntervalMillis()The default window size in milliseconds used to debounce schema refresh requests.ConsistencyLevelgetSerialConsistencyLevel()The default serial consistency level used by queries.QueryOptions.CQL4SkipMetadataResolveMethodgetSkipCQL4MetadataResolveMethod()Skip metadata resolve method .inthashCode()booleanisConsistencySet()booleanisMetadataEnabled()Whether client-side token and schema metadata is enabled.booleanisPrepareOnAllHosts()Returns whether the driver should prepare statements on all hosts in the cluster.booleanisReprepareOnUp()Whether the driver should re-prepare all cached prepared statements on a host when its marks that host back up.booleanisSchemaQueriesPaged()Whether schema queries are using paging.QueryOptionssetAddOriginalContactsToReconnectionPlan(boolean enabled)Whether the driver should use original contact points when reconnecting to a control node.QueryOptionssetConsiderZeroTokenNodesValidPeers(boolean enabled)Recently introduced in Scylla zero-token nodes have null value in "tokens" column in their system.peers rows.QueryOptionssetConsistencyLevel(ConsistencyLevel consistencyLevel)Sets the default consistency level to use for queries.QueryOptionssetDefaultIdempotence(boolean defaultIdempotence)Sets the default idempotence for queries.QueryOptionssetFetchSize(int fetchSize)Sets the default fetch size to use for SELECT queries.QueryOptionssetLoadBalancingLwtRequestRoutingMethod(QueryOptions.RequestRoutingMethod loadBalancingLwtRequestRoutingMethod)Sets the default request routing method to use for LWT queries.QueryOptionssetMaxPendingRefreshNodeListRequests(int maxPendingRefreshNodeListRequests)Sets the maximum number of node list refresh requests that the control connection can accumulate before executing them.QueryOptionssetMaxPendingRefreshNodeRequests(int maxPendingRefreshNodeRequests)Sets the maximum number of node refresh requests that the control connection can accumulate before executing them.QueryOptionssetMaxPendingRefreshSchemaRequests(int maxPendingRefreshSchemaRequests)Sets the maximum number of schema refresh requests that the control connection can accumulate before executing them.QueryOptionssetMetadataEnabled(boolean enabled)Toggle client-side token and schema metadata.QueryOptionssetPrepareOnAllHosts(boolean prepareOnAllHosts)Set whether the driver should prepare statements on all hosts in the cluster.QueryOptionssetRefreshNodeIntervalMillis(int refreshNodeIntervalMillis)Sets the default window size in milliseconds used to debounce node refresh requests.QueryOptionssetRefreshNodeListIntervalMillis(int refreshNodeListIntervalMillis)Sets the default window size in milliseconds used to debounce node list refresh requests.QueryOptionssetRefreshSchemaIntervalMillis(int refreshSchemaIntervalMillis)Sets the default window size in milliseconds used to debounce node list refresh requests.QueryOptionssetReprepareOnUp(boolean reprepareOnUp)Set whether the driver should re-prepare all cached prepared statements on a host when it marks it back up.QueryOptionssetSchemaQueriesPaged(boolean enabled)Toggle schema queries paging.QueryOptionssetSerialConsistencyLevel(ConsistencyLevel serialConsistencyLevel)Sets the default serial consistency level to use for queries.QueryOptionssetSkipCQL4MetadataResolveMethod(QueryOptions.CQL4SkipMetadataResolveMethod method)There is known problem in CQL 4.x when prepared statement invalidation could be voided: more info When it happens metadata on client side does not match data and deserialization can go wrong in many ways To avoid driver can disable skip metadata flag to make server respond with metadata on every query.booleanshouldAddOriginalContactsToReconnectionPlan()booleanshouldConsiderZeroTokenNodesValidPeers()
-
-
-
Field Detail
-
DEFAULT_CONSISTENCY_LEVEL
public static final ConsistencyLevel DEFAULT_CONSISTENCY_LEVEL
The default consistency level for queries:ConsistencyLevel.LOCAL_ONE.
-
DEFAULT_SERIAL_CONSISTENCY_LEVEL
public static final ConsistencyLevel DEFAULT_SERIAL_CONSISTENCY_LEVEL
The default serial consistency level for conditional updates:ConsistencyLevel.SERIAL.
-
DEFAULT_FETCH_SIZE
public static final int DEFAULT_FETCH_SIZE
The default fetch size for SELECT queries: 5000.- See Also:
- Constant Field Values
-
DEFAULT_IDEMPOTENCE
public static final boolean DEFAULT_IDEMPOTENCE
The default value forgetDefaultIdempotence():false.- See Also:
- Constant Field Values
-
DEFAULT_MAX_PENDING_REFRESH_NODE_LIST_REQUESTS
public static final int DEFAULT_MAX_PENDING_REFRESH_NODE_LIST_REQUESTS
- See Also:
- Constant Field Values
-
DEFAULT_MAX_PENDING_REFRESH_NODE_REQUESTS
public static final int DEFAULT_MAX_PENDING_REFRESH_NODE_REQUESTS
- See Also:
- Constant Field Values
-
DEFAULT_MAX_PENDING_REFRESH_SCHEMA_REQUESTS
public static final int DEFAULT_MAX_PENDING_REFRESH_SCHEMA_REQUESTS
- See Also:
- Constant Field Values
-
DEFAULT_REFRESH_NODE_LIST_INTERVAL_MILLIS
public static final int DEFAULT_REFRESH_NODE_LIST_INTERVAL_MILLIS
- See Also:
- Constant Field Values
-
DEFAULT_REFRESH_NODE_INTERVAL_MILLIS
public static final int DEFAULT_REFRESH_NODE_INTERVAL_MILLIS
- See Also:
- Constant Field Values
-
DEFAULT_REFRESH_SCHEMA_INTERVAL_MILLIS
public static final int DEFAULT_REFRESH_SCHEMA_INTERVAL_MILLIS
- See Also:
- Constant Field Values
-
DEFAULT_LOAD_BALANCING_LWT_REQUEST_ROUTING_METHOD
public static final QueryOptions.RequestRoutingMethod DEFAULT_LOAD_BALANCING_LWT_REQUEST_ROUTING_METHOD
-
-
Constructor Detail
-
QueryOptions
public QueryOptions()
Creates a newQueryOptionsinstance using theDEFAULT_CONSISTENCY_LEVEL,DEFAULT_SERIAL_CONSISTENCY_LEVELandDEFAULT_FETCH_SIZE.
-
-
Method Detail
-
setConsistencyLevel
public QueryOptions setConsistencyLevel(ConsistencyLevel consistencyLevel)
Sets the default consistency level to use for queries.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()returnsnull.- Parameters:
consistencyLevel- the new consistency level to set as default. It must not benull: every query needs a consistency level, so a null default would fail any statement that does not set one of its own.- Returns:
- this
QueryOptionsinstance. - Throws:
NullPointerException- ifconsistencyLevelisnull.
-
getConsistencyLevel
public ConsistencyLevel getConsistencyLevel()
The default consistency level used by queries.- Returns:
- the default consistency level used by queries.
-
setSerialConsistencyLevel
public QueryOptions setSerialConsistencyLevel(ConsistencyLevel serialConsistencyLevel)
Sets the default serial consistency level to use for queries.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()returnsnull.- Parameters:
serialConsistencyLevel- the new serial consistency level to set as default.- Returns:
- this
QueryOptionsinstance.
-
getSerialConsistencyLevel
public ConsistencyLevel getSerialConsistencyLevel()
The default serial consistency level used by queries.- Returns:
- the default serial consistency level used by queries.
-
setFetchSize
public QueryOptions setFetchSize(int fetchSize)
Sets the default fetch size to use for SELECT queries.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.- Parameters:
fetchSize- the new fetch size to set as default. It must be strictly positive but you can useInteger.MAX_VALUEto disable paging.- Returns:
- this
QueryOptionsinstance. - Throws:
IllegalArgumentException- iffetchSize <e; 0.UnsupportedFeatureException- if version 1 of the native protocol is in use andfetchSize != Integer.MAX_VALUEas paging is not supported by version 1 of the protocol. SeeCluster.Builder.withProtocolVersion(com.datastax.driver.core.ProtocolVersion)for more details on protocol versions.
-
getFetchSize
public int getFetchSize()
The default fetch size used by queries.- Returns:
- the default fetch size used by queries.
-
setDefaultIdempotence
public QueryOptions setDefaultIdempotence(boolean defaultIdempotence)
Sets the default idempotence for queries.This will be used for statements for which
Statement.isIdempotent()returnsnull.- Parameters:
defaultIdempotence- the new value to set as default idempotence.- Returns:
- this
QueryOptionsinstance.
-
getDefaultIdempotence
public boolean getDefaultIdempotence()
The default idempotence for queries.It defaults to
DEFAULT_IDEMPOTENCE.- Returns:
- the default idempotence for queries.
-
setSkipCQL4MetadataResolveMethod
public QueryOptions setSkipCQL4MetadataResolveMethod(QueryOptions.CQL4SkipMetadataResolveMethod method)
There is known problem in CQL 4.x when prepared statement invalidation could be voided: more info When it happens metadata on client side does not match data and deserialization can go wrong in many ways To avoid driver can disable skip metadata flag to make server respond with metadata on every query. Unfortunately it causes excessive network traffic and CPU overhead on both server and driver side. This option controls how driver resolves skip metadata flag for CQL4 prepared statements. **SMART** - disable flag only for wildcard selects (select * from) and selects that return UDTs, including collections of UDTs and maps that contain UDTs **ENABLED** - flag is always set **DISABLED** - flag is always disabled Default is SMART Required: yes Modifiable at runtime: yes, the new value will be used for requests issued after the change. Overridable in a profile: yes- Parameters:
method- the new value to set as skip metadata resolve method.- Returns:
- this
QueryOptionsinstance.
-
getSkipCQL4MetadataResolveMethod
public QueryOptions.CQL4SkipMetadataResolveMethod getSkipCQL4MetadataResolveMethod()
Skip metadata resolve method .It defaults to
QueryOptions.CQL4SkipMetadataResolveMethod.SMART.- Returns:
- the default idempotence for queries.
-
setPrepareOnAllHosts
public QueryOptions setPrepareOnAllHosts(boolean prepareOnAllHosts)
Set whether the driver should prepare statements on all hosts in the cluster.A statement is normally prepared in two steps:
- prepare the query on a single host in the cluster;
- if that succeeds, prepare on all other hosts.
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).
- Parameters:
prepareOnAllHosts- the new value to set to indicate whether to prepare statements once or on all nodes.- Returns:
- this
QueryOptionsinstance.
-
isPrepareOnAllHosts
public boolean isPrepareOnAllHosts()
Returns whether the driver should prepare statements on all hosts in the cluster.- Returns:
- the value.
- See Also:
setPrepareOnAllHosts(boolean)
-
setReprepareOnUp
public QueryOptions setReprepareOnUp(boolean reprepareOnUp)
Set whether the driver should re-prepare all cached prepared statements on a host when it marks it back up.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).
- Parameters:
reprepareOnUp- whether the driver should re-prepare when marking a node up.- Returns:
- this
QueryOptionsinstance.
-
isReprepareOnUp
public boolean isReprepareOnUp()
Whether the driver should re-prepare all cached prepared statements on a host when its marks that host back up.- Returns:
- the value.
- See Also:
setReprepareOnUp(boolean)
-
setMetadataEnabled
public QueryOptions setMetadataEnabled(boolean enabled)
Toggle client-side token and schema metadata.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:
- most schema- or token-related methods in
Metadatawill return stale or null/empty results (see the javadoc of each method for details); Metadata.newToken(String)andMetadata.newTokenRange(Token, Token)will throw an exception if metadata was disabled before startup;- token-aware routing will not work properly: if metadata was never initialized,
TokenAwarePolicywill 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.
- Parameters:
enabled- whether metadata is enabled.- Returns:
- this
QueryOptionsinstance.
- most schema- or token-related methods in
-
isMetadataEnabled
public boolean isMetadataEnabled()
Whether client-side token and schema metadata is enabled.- Returns:
- the value.
- See Also:
setMetadataEnabled(boolean)
-
setSchemaQueriesPaged
public QueryOptions setSchemaQueriesPaged(boolean enabled)
Toggle schema queries paging.- Parameters:
enabled- whether paging is enabled in schema queries.- Returns:
- this
QueryOptionsinstance.
-
isSchemaQueriesPaged
public boolean isSchemaQueriesPaged()
Whether schema queries are using paging.- Returns:
- the value.
-
setRefreshSchemaIntervalMillis
public QueryOptions setRefreshSchemaIntervalMillis(int refreshSchemaIntervalMillis)
Sets the default window size in milliseconds used to debounce node list refresh requests.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.
- Parameters:
refreshSchemaIntervalMillis- The default window size in milliseconds used to debounce schema refresh requests.
-
getRefreshSchemaIntervalMillis
public int getRefreshSchemaIntervalMillis()
The default window size in milliseconds used to debounce schema refresh requests.- Returns:
- The default window size in milliseconds used to debounce schema refresh requests.
-
setMaxPendingRefreshSchemaRequests
public QueryOptions setMaxPendingRefreshSchemaRequests(int maxPendingRefreshSchemaRequests)
Sets the maximum number of schema refresh requests that the control connection can accumulate before executing them.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.
- Parameters:
maxPendingRefreshSchemaRequests- The maximum number of schema refresh requests that the control connection can accumulate before executing them.
-
getMaxPendingRefreshSchemaRequests
public int getMaxPendingRefreshSchemaRequests()
The maximum number of schema refresh requests that the control connection can accumulate before executing them.- Returns:
- The maximum number of schema refresh requests that the control connection can accumulate before executing them.
-
setRefreshNodeListIntervalMillis
public QueryOptions setRefreshNodeListIntervalMillis(int refreshNodeListIntervalMillis)
Sets the default window size in milliseconds used to debounce node list refresh requests.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.
- Parameters:
refreshNodeListIntervalMillis- The default window size in milliseconds used to debounce node list refresh requests.
-
getRefreshNodeListIntervalMillis
public int getRefreshNodeListIntervalMillis()
The default window size in milliseconds used to debounce node list refresh requests.- Returns:
- The default window size in milliseconds used to debounce node list refresh requests.
-
setMaxPendingRefreshNodeListRequests
public QueryOptions setMaxPendingRefreshNodeListRequests(int maxPendingRefreshNodeListRequests)
Sets the maximum number of node list refresh requests that the control connection can accumulate before executing them.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.
- Parameters:
maxPendingRefreshNodeListRequests- The maximum number of node list refresh requests that the control connection can accumulate before executing them.
-
getMaxPendingRefreshNodeListRequests
public int getMaxPendingRefreshNodeListRequests()
Sets the maximum number of node list refresh requests that the control connection can accumulate before executing them.- Returns:
- The maximum number of node list refresh requests that the control connection can accumulate before executing them.
-
setRefreshNodeIntervalMillis
public QueryOptions setRefreshNodeIntervalMillis(int refreshNodeIntervalMillis)
Sets the default window size in milliseconds used to debounce node refresh requests.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.
- Parameters:
refreshNodeIntervalMillis- The default window size in milliseconds used to debounce node refresh requests.
-
getRefreshNodeIntervalMillis
public int getRefreshNodeIntervalMillis()
The default window size in milliseconds used to debounce node refresh requests.- Returns:
- The default window size in milliseconds used to debounce node refresh requests.
-
setMaxPendingRefreshNodeRequests
public QueryOptions setMaxPendingRefreshNodeRequests(int maxPendingRefreshNodeRequests)
Sets the maximum number of node refresh requests that the control connection can accumulate before executing them.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.
- Parameters:
maxPendingRefreshNodeRequests- The maximum number of node refresh requests that the control connection can accumulate before executing them.
-
getMaxPendingRefreshNodeRequests
public int getMaxPendingRefreshNodeRequests()
The maximum number of node refresh requests that the control connection can accumulate before executing them.- Returns:
- The maximum number of node refresh requests that the control connection can accumulate before executing them.
-
setAddOriginalContactsToReconnectionPlan
public QueryOptions setAddOriginalContactsToReconnectionPlan(boolean enabled)
Whether the driver should use original contact points when reconnecting to a control node. In practice this forces driver to manually add original contact points to the end of the query plan. It is possible that it may introduce duplicates (but under differnet Host class instances) in the query plan. If this is set to false it does not mean that original contact points will be excluded.One use case of this feature is that if the original contact point is defined by hostname and its IP address changes then setting this to
trueallows trying reconnecting to the new IP if all connection was lost.
-
shouldAddOriginalContactsToReconnectionPlan
public boolean shouldAddOriginalContactsToReconnectionPlan()
-
setConsiderZeroTokenNodesValidPeers
public QueryOptions setConsiderZeroTokenNodesValidPeers(boolean enabled)
Recently introduced in Scylla zero-token nodes have null value in "tokens" column in their system.peers rows. By default extended peer check considers such rows as invalid. Enabling this option will exclude this field from the check, and allow such rows from system.peers queries to be used when refreshing metadata.
-
shouldConsiderZeroTokenNodesValidPeers
public boolean shouldConsiderZeroTokenNodesValidPeers()
-
setLoadBalancingLwtRequestRoutingMethod
public QueryOptions setLoadBalancingLwtRequestRoutingMethod(QueryOptions.RequestRoutingMethod loadBalancingLwtRequestRoutingMethod)
Sets the default request routing method to use for LWT queries. Default isQueryOptions.RequestRoutingMethod.PRESERVE_REPLICA_ORDER.- Parameters:
loadBalancingLwtRequestRoutingMethod- the new request routing method.- Returns:
- this
QueryOptionsinstance.
-
getLoadBalancingLwtRequestRoutingMethod
public QueryOptions.RequestRoutingMethod getLoadBalancingLwtRequestRoutingMethod()
The default request routing method used by LWT queries.- Returns:
- the default request routing method used by LWT queries.
-
isConsistencySet
public boolean isConsistencySet()
-
-