/// <inheritdoc /> protected Statement(QueryProtocolOptions queryProtocolOptions) { _pagingState = queryProtocolOptions.PagingState; _values = queryProtocolOptions.Values; _consistency = queryProtocolOptions.Consistency; _pageSize = queryProtocolOptions.PageSize; _serialConsistency = queryProtocolOptions.SerialConsistency; }
public BatchRequest(int protocolVersion, BatchStatement statement, ConsistencyLevel consistency) { ProtocolVersion = protocolVersion; if (ProtocolVersion < 2) { throw new NotSupportedException("Batch request is supported in C* >= 2.0.x"); } var subRequests = new List<IQueryRequest>(); foreach (var q in statement.Queries) { subRequests.Add(q.CreateBatchRequest(ProtocolVersion)); } _type = statement.BatchType; _requests = subRequests; Consistency = consistency; _timestamp = statement.Timestamp; if (statement.IsTracing) { _headerFlags = 0x02; } if (statement.SerialConsistencyLevel != ConsistencyLevel.Any) { if (protocolVersion < 3) { throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above."); } if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial) { throw new RequestInvalidException("Non-serial consistency specified as a serial one."); } _batchFlags |= QueryProtocolOptions.QueryFlags.WithSerialConsistency; _serialConsistency = statement.SerialConsistencyLevel; } if (_timestamp != null) { if (protocolVersion < 3) { throw new NotSupportedException("Timestamp for BATCH request is supported in Cassandra 2.1 or above."); } _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp; } }
public BatchRequest(int protocolVersion, BatchStatement statement, ConsistencyLevel consistency) { if (protocolVersion < 2) { throw new NotSupportedException("Batch request is supported in C* >= 2.0.x"); } _type = statement.BatchType; _requests = statement.Queries .Select(q => q.CreateBatchRequest(protocolVersion)) .ToArray(); Consistency = consistency; _timestamp = statement.Timestamp; if (statement.IsTracing) { _headerFlags = FrameHeader.HeaderFlag.Tracing; } if (statement.SerialConsistencyLevel != ConsistencyLevel.Any) { if (protocolVersion < 3) { throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above."); } if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial) { throw new RequestInvalidException("Non-serial consistency specified as a serial one."); } _batchFlags |= QueryProtocolOptions.QueryFlags.WithSerialConsistency; _serialConsistency = statement.SerialConsistencyLevel; } if (_timestamp != null) { if (protocolVersion < 3) { throw new NotSupportedException("Timestamp for BATCH request is supported in Cassandra 2.1 or above."); } _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp; } }
public new CqlScalar <TEntity> SetConsistencyLevel(ConsistencyLevel?consistencyLevel) { base.SetConsistencyLevel(consistencyLevel); return(this); }
public IExecutionProfileBuilder WithSerialConsistencyLevel(ConsistencyLevel serialConsistencyLevel) { _serialConsistencyLevel = serialConsistencyLevel; return(this); }
private RetryDecision(RetryDecisionType type, ConsistencyLevel? retryCL) { _type = type; _retryCl = retryCL; }
public ICqlCommand WithConsistencyLevel(ConsistencyLevel cl) { _consistencyLevel = cl; return(this); }
/// <inheritdoc /> public IStatement SetConsistencyLevel(ConsistencyLevel? consistency) { _consistency = consistency; return this; }
public IOutput ExecuteQuery(int streamId, byte[] id, string cql, RowSetMetadata metadata, bool isTracing, QueryProtocolOptions queryPrtclOptions, ConsistencyLevel?consistency) { return(EndExecuteQuery(BeginExecuteQuery(streamId, id, cql, metadata, null, null, this, isTracing, queryPrtclOptions, consistency), this)); }
internal static DocumentClient CreateClient(Uri serviceEndpoint, string authKeyOrResourceToken, JsonSerializerSettings serializerSettings = null, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?consistencyLevel = null) { serializerSettings = serializerSettings ?? new JsonSerializerSettings(); serializerSettings.Converters.Add(new JsonClaimConverter()); serializerSettings.Converters.Add(new JsonClaimsPrincipalConverter()); serializerSettings.Converters.Add(new JsonClaimsIdentityConverter()); #if NETSTANDARD2 return(new DocumentClient(serviceEndpoint, authKeyOrResourceToken, serializerSettings, connectionPolicy, consistencyLevel)); #else // DocumentDB SDK only supports setting the JsonSerializerSettings on versions after NetStandard 2.0 JsonConvert.DefaultSettings = () => serializerSettings; return(new DocumentClient(serviceEndpoint, authKeyOrResourceToken, connectionPolicy, consistencyLevel)); #endif }
/// <summary> /// Returns a Direct TCP DocumentClient from a connection. /// </summary> /// <param name="conn">The documentDB connection.</param> /// <param name="policy">The policy.</param> /// <param name="level">The consistency level.></param> /// <returns></returns> public static DocumentClient ToDocumentClient(this DocumentDbConnection conn, ConnectionPolicy policy = null, ConsistencyLevel?level = null) { return(new DocumentClient(conn.Account, conn.AccountKey, policy ?? new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp }, level)); }
/// <summary> /// Sets the default consistency level to use for queries. /// /// The consistency level set through this method will be use for queries /// that don't explicitely have a consistency level. /// </summary> /// <param name="consistencyLevel">the new consistency level to set as default.</param> /// <returns>this QueryOptions instance</returns> public QueryOptions SetConsistencyLevel(ConsistencyLevel consistencyLevel) { _consistency = consistencyLevel; return(this); }
public DocumentClientFactory(Uri endpoint, SecureString authKeyWrite, SecureString authKeyRead, IList <string> preferredLocations, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?consistencyLevel = null) { _endpoint = endpoint ?? throw new ArgumentNullException(nameof(endpoint)); _authKeyWrite = authKeyWrite ?? throw new ArgumentNullException(nameof(authKeyWrite)); _authKeyRead = authKeyRead ?? throw new ArgumentNullException(nameof(authKeyRead)); _connectionPolicy = connectionPolicy ?? new ConnectionPolicy() { ConnectionProtocol = Protocol.Tcp, ConnectionMode = ConnectionMode.Direct }; _consistencyLevel = consistencyLevel ?? ConsistencyLevel.Session; _serializerSettings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }; if (preferredLocations == null | preferredLocations.Count == 0) { throw new InvalidOperationException($"{nameof(preferredLocations)} must have at least one location"); } _preferredLocations = (List <string>)preferredLocations; }
internal MultigetQueryHelper(string commandName, string keyspace, string columnFamily, ConsistencyLevel?consistencyLevel) { this.commandName = commandName; this.keyspace = keyspace; this.columnFamily = columnFamily; this.consistencyLevel = consistencyLevel; }
public static DocumentClient AddDefaultDocumentClientForIdentity(this IServiceCollection services, Uri serviceEndpoint, string authKeyOrResourceToken, JsonSerializerSettings serializerSettings = null, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?consistencyLevel = null, Action <DocumentClient> afterCreation = null) { var documentClient = DocumentClientFactory.CreateClient(serviceEndpoint, authKeyOrResourceToken, serializerSettings, connectionPolicy, consistencyLevel); afterCreation?.Invoke(documentClient); services.AddSingleton <IDocumentClient>(documentClient); return(documentClient); }
/// <summary> /// Creates a Retry retry decision using the provided consistency level. /// </summary> /// <param name="consistency"> the consistency level to use for the retry. /// </param> /// /// <returns>a Retry with consistency level <c>consistency</c> retry /// decision.</returns> public static RetryDecision Retry(ConsistencyLevel?consistency) { return(new RetryDecision(RetryDecisionType.Retry, consistency)); }
/// <summary> /// Creates a decision to retry using the provided consistency level on the same host. /// </summary> /// <param name="consistency"> the consistency level to use for the retry.</param> /// <returns>a Retry with consistency level <c>consistency</c> retry decision.</returns> public static RetryDecision Retry(ConsistencyLevel?consistency) { return(Retry(consistency, true)); }
/// <summary> /// Sets a default consistency level for all <c>BoundStatement</c> created /// from this object. <p> If no consistency level is set through this method, the /// BoundStatement created from this object will use the default consistency /// level (One). </p><p> Changing the default consistency level is not retroactive, /// it only applies to BoundStatement created after the change.</p> /// </summary> /// <param name="consistency"> the default consistency level to set. </param> /// <returns>this <c>PreparedStatement</c> object.</returns> public PreparedStatement SetConsistencyLevel(ConsistencyLevel consistency) { ConsistencyLevel = consistency; return this; }
private RetryDecision(RetryDecisionType type, ConsistencyLevel?retryConsistencyLevel, bool useCurrentHost) { DecisionType = type; RetryConsistencyLevel = retryConsistencyLevel; UseCurrentHost = useCurrentHost; }
public IAsyncResult BeginExecuteQuery(int streamId, byte[] id, string cql, RowSetMetadata metadata, AsyncCallback callback, object state, object owner, bool isTracing, QueryProtocolOptions queryProtocolOptions, ConsistencyLevel?consistency = null) { AsyncResult <IOutput> jar = SetupJob(streamId, callback, state, owner, "EXECUTE"); BeginJob(jar, SetupKeyspace(jar, SetupPreparedQuery(jar, id, cql, () => { Evaluate(new ExecuteRequest(jar.StreamId, id, metadata, isTracing, queryProtocolOptions, consistency), jar.StreamId, frame2 => { AbstractResponse response = FrameParser.Parse(frame2); if (response is ResultResponse) { JobFinished(jar, (response as ResultResponse).Output); } else { _protocolErrorHandlerAction(new ErrorActionParam { AbstractResponse = response, Jar = jar }); } }); }))); return(jar); }
/// <summary> /// Creates a decision to retry using the provided consistency level. /// </summary> /// <param name="consistency"> the consistency level to use for the retry.</param> /// <param name="useCurrentHost">Determines if the retry is made using the current host.</param> /// <returns>a Retry with consistency level <c>consistency</c> retry /// decision.</returns> public static RetryDecision Retry(ConsistencyLevel?consistency, bool useCurrentHost) { return(new RetryDecision(RetryDecisionType.Retry, consistency, useCurrentHost)); }
public new Batch SetConsistencyLevel(ConsistencyLevel?consistencyLevel) { base.SetConsistencyLevel(consistencyLevel); return(this); }
public new CqlCommand SetConsistencyLevel(ConsistencyLevel?consistencyLevel) { base.SetConsistencyLevel(consistencyLevel); return(this); }
/// <inheritdoc /> public IStatement SetConsistencyLevel(ConsistencyLevel?consistency) { ConsistencyLevel = consistency; return(this); }
/// <summary> /// Cloud client provider. /// </summary> /// <param name="serviceEndpoint">The service endpoint URL.</param> /// <param name="permissionFeed">Permission feed list.</param> /// <param name="connectionPolicy">Connection policy.</param> /// <param name="desiredConsistencyLevel">Consistency level.</param> public CloudClient(Uri serviceEndpoint, IList <Permission> permissionFeed, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?desiredConsistencyLevel = default(ConsistencyLevel?)) { _client = new DocumentClient(serviceEndpoint, permissionFeed, connectionPolicy, desiredConsistencyLevel); }
///// <summary> ///// Changes the replication mode to sync for server. ///// </summary> ///// <param name="fabricClient"></param> //internal static void SwitchServerToSyncReplication(COMMONNAMESPACE.IFabricClient fabricClient, string callingComponent) //{ // if (!IsCurrentReplicationModeAsync(fabricClient)["Server"]) // { // return; // } // NamingServiceConfig.NamingServiceConfigurationWriter namingServiceWriter = // new NamingServiceConfig.NamingServiceConfigurationWriter(fabricClient); // NamingServiceConfig.DocumentServiceConfiguration config = new NamingServiceConfig.DocumentServiceConfiguration(); // config.DocumentServiceName = ConfigurationManager.AppSettings["DatabaseAccountId"]; // config.IsServerReplicationAsync = false; // namingServiceWriter.UpdateDatabaseAccountConfigurationAsync(config).Wait(); // Task.Delay(TimeSpan.FromSeconds(ReplicationTests.ConfigurationRefreshIntervalInSec)).Wait(); // TestCommon.ForceRefreshNamingServiceConfigs(callingComponent, FabricServiceType.ServerService).Wait(); //} ///// <summary> ///// Changes the replication mode to async for server. ///// </summary> ///// <param name="fabricClient"></param> //internal static void SwitchServerToAsyncReplication(COMMONNAMESPACE.IFabricClient fabricClient, string callingComponent) //{ // if (IsCurrentReplicationModeAsync(fabricClient)["Server"]) // { // return; // } // NamingServiceConfig.NamingServiceConfigurationWriter namingServiceWriter = // new NamingServiceConfig.NamingServiceConfigurationWriter(fabricClient); // NamingServiceConfig.DocumentServiceConfiguration config = new NamingServiceConfig.DocumentServiceConfiguration(); // config.DocumentServiceName = ConfigurationManager.AppSettings["DatabaseAccountId"]; // config.IsServerReplicationAsync = true; // namingServiceWriter.UpdateDatabaseAccountConfigurationAsync(config).Wait(); // Task.Delay(TimeSpan.FromSeconds(ReplicationTests.ConfigurationRefreshIntervalInSec)).Wait(); // TestCommon.ForceRefreshNamingServiceConfigs(callingComponent, FabricServiceType.ServerService).Wait(); //} #endregion #region Environment Configuration Helpers internal static DocumentClient[] GetClientsLocked(bool useGateway = false, Protocol protocol = Protocol.Tcp, int timeoutInSeconds = 10, ConsistencyLevel?defaultConsistencyLevel = null, AuthorizationTokenType tokenType = AuthorizationTokenType.PrimaryMasterKey) { var toReturn = new DocumentClient[TestCommon.ReplicationFactor]; for (uint i = 0; i < toReturn.Length; i++) { toReturn[i] = TestCommon.CreateClient(useGateway, protocol, timeoutInSeconds, defaultConsistencyLevel, tokenType); toReturn[i].LockClient(i); } return(toReturn); }
/// <summary> /// Cloud client provider. /// </summary> /// <param name="serviceEndpoint">The service endpoint URL.</param> /// <param name="authKey">Authentication key.</param> /// <param name="connectionPolicy">Connection policy.</param> /// <param name="desiredConsistencyLevel">Consistency level.</param> public CloudClient(Uri serviceEndpoint, SecureString authKey, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?desiredConsistencyLevel = default(ConsistencyLevel?)) { _client = new DocumentClient(serviceEndpoint, authKey, connectionPolicy, desiredConsistencyLevel); }
public IExecutionProfileBuilder WithConsistencyLevel(ConsistencyLevel consistencyLevel) { _consistencyLevel = consistencyLevel; return(this); }
/// <summary> /// Cloud client provider. /// </summary> /// <param name="serviceEndpoint">The service endpoint URL.</param> /// <param name="resourceTokens">Resource tokens.</param> /// <param name="connectionPolicy">Connection policy.</param> /// <param name="desiredConsistencyLevel">Consistency level.</param> public CloudClient(Uri serviceEndpoint, IDictionary <string, string> resourceTokens, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?desiredConsistencyLevel = default(ConsistencyLevel?)) { _client = new DocumentClient(serviceEndpoint, resourceTokens, connectionPolicy, desiredConsistencyLevel); }
public new CqlQuerySingleElement <TEntity> SetConsistencyLevel(ConsistencyLevel?consistencyLevel) { base.SetConsistencyLevel(consistencyLevel); return(this); }
public new CqlConditionalCommand <TEntity> SetConsistencyLevel(ConsistencyLevel?consistencyLevel) { base.SetConsistencyLevel(consistencyLevel); return(this); }
private RetryDecision(RetryDecisionType type, ConsistencyLevel?retryCL) { _type = type; _retryCl = retryCL; }
internal MockDocumentClient(Uri serviceEndpoint, IList <ResourceToken> resourceTokens, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?desiredConsistencyLevel = null) : base(serviceEndpoint, resourceTokens, connectionPolicy, desiredConsistencyLevel) { this.Init(); }
internal static IDocumentClient CreateDocumentClient(Uri endpoint, string authKeyOrResourceToken, JsonSerializerSettings jsonSerializerSettings, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?desiredConsistencyLevel = null) { return(new DocumentClient(endpoint, authKeyOrResourceToken, jsonSerializerSettings, connectionPolicy ?? ConnectionPolicy.Default, desiredConsistencyLevel)); }
public IOutput Query(int streamId, string cqlQuery, bool tracingEnabled, QueryProtocolOptions queryPrtclOptions, ConsistencyLevel?consistency = null) { return(EndQuery(BeginQuery(streamId, cqlQuery, null, null, this, tracingEnabled, queryPrtclOptions, consistency), this)); }
/// <summary> /// Sets the serial consistency level for execution of the query. (NOTE: This only applies to queries using lightweight /// transactions -- LWT). /// </summary> public CqlQueryOptions SetSerialConsistencyLevel(ConsistencyLevel consistencyLevel) { _serialConsistencyLevel = consistencyLevel; return(this); }
/// <summary> /// Sets the serial consistency level for execution of the query. (NOTE: This only applies to queries using lightweight /// transactions -- LWT). /// </summary> public CqlQueryOptions SetSerialConsistencyLevel(ConsistencyLevel consistencyLevel) { _serialConsistencyLevel = consistencyLevel; return this; }