IAsyncResult invokeQuery(QueryRequest queryRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new QueryRequestMarshaller().Marshall(queryRequest); var unmarshaller = QueryResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// Initiates the asynchronous execution of the Query operation. /// <seealso cref="Amazon.DynamoDB.AmazonDynamoDB.Query"/> /// </summary> /// /// <param name="queryRequest">Container for the necessary parameters to execute the Query operation on AmazonDynamoDB.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndQuery /// operation.</returns> public IAsyncResult BeginQuery(QueryRequest queryRequest, AsyncCallback callback, object state) { return invokeQuery(queryRequest, callback, state, false); }
/// <summary> /// <para>Gets the values of one or more items and its attributes by primary key (composite primary key, only).</para> <para>Narrow the scope of /// the query using comparison operators on the <c>RangeKeyValue</c> of the composite key. Use the <c>ScanIndexForward</c> parameter to get /// results in forward or reverse order by range key.</para> /// </summary> /// /// <param name="queryRequest">Container for the necessary parameters to execute the Query service method on AmazonDynamoDB.</param> /// /// <returns>The response from the Query service method, as returned by AmazonDynamoDB.</returns> /// /// <exception cref="ProvisionedThroughputExceededException"/> /// <exception cref="InternalServerErrorException"/> /// <exception cref="ResourceNotFoundException"/> public QueryResponse Query(QueryRequest queryRequest) { IAsyncResult asyncResult = invokeQuery(queryRequest, null, null, true); return EndQuery(asyncResult); }
/// <summary> /// <para> The Query operation gets the values of one or more items and its attributes by primary key (composite primary key, only). Narrow the /// scope of the query using comparison operators on the RangeKeyValue of the composite key. Use the ScanIndexForward parameter to get results /// in forward or reverse order by range key. </para> /// </summary> /// /// <param name="queryRequest">Container for the necessary parameters to execute the Query service method on AmazonDynamoDB.</param> /// /// <returns>The response from the Query service method, as returned by AmazonDynamoDB.</returns> /// /// <exception cref="ProvisionedThroughputExceededException"/> /// <exception cref="InternalServerErrorException"/> /// <exception cref="ResourceNotFoundException"/> public QueryResponse Query(QueryRequest queryRequest) { IRequest<QueryRequest> request = new QueryRequestMarshaller().Marshall(queryRequest); QueryResponse response = Invoke<QueryRequest, QueryResponse> (request, this.signer, QueryResponseUnmarshaller.GetInstance()); return response; }
private List<Document> GetNextSetHelper(bool isAsync) { List<Document> ret = new List<Document>(); if (!IsDone) { switch (SearchMethod) { case SearchType.Scan: ScanRequest scanReq = new ScanRequest { ExclusiveStartKey = NextKey, Limit = Limit, TableName = TableName }; scanReq.BeforeRequestEvent += isAsync ? new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) : new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync); if (AttributesToGet != null) scanReq.AttributesToGet = AttributesToGet; scanReq.ScanFilter = (ScanFilter)Filter; ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq).ScanResult; foreach (var item in scanResult.Items) { Document doc = Document.FromAttributeMap(item); ret.Add(doc); Matches.Add(doc); } NextKey = scanResult.LastEvaluatedKey; if (NextKey == null) { IsDone = true; } return ret; case SearchType.Query: QueryRequest queryReq = new QueryRequest { ConsistentRead=IsConsistentRead, ExclusiveStartKey=NextKey, HashKeyValue=HashKey, Limit=Limit, ScanIndexForward=!IsBackwardSearch, TableName=TableName, }; if (Filter != null) queryReq.RangeKeyCondition = ((RangeFilter)Filter).Condition; queryReq.BeforeRequestEvent += isAsync ? new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) : new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync); if (AttributesToGet != null) queryReq.AttributesToGet = AttributesToGet; QueryResult queryResult = SourceTable.DDBClient.Query(queryReq).QueryResult; foreach (var item in queryResult.Items) { Document doc = Document.FromAttributeMap(item); ret.Add(doc); Matches.Add(doc); } NextKey = queryResult.LastEvaluatedKey; if (NextKey == null) { IsDone = true; } return ret; default: throw new InvalidOperationException("Unknown Search Method"); } } return ret; }
private int GetCount() { if (IsDone) { return Matches.Count; } else { if (count != -1) { return count; } else { switch (SearchMethod) { case SearchType.Scan: ScanRequest scanReq = new ScanRequest { Count=true, ExclusiveStartKey=NextKey, TableName=TableName, }; scanReq.BeforeRequestEvent += SourceTable.UserAgentRequestEventHandlerSync; scanReq.ScanFilter = (ScanFilter)Filter; ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq).ScanResult; count = Matches.Count + scanResult.Count; return count; case SearchType.Query: QueryRequest queryReq = new QueryRequest { ConsistentRead=IsConsistentRead, Count=true, ExclusiveStartKey=NextKey, HashKeyValue=HashKey, RangeKeyCondition = ((RangeFilter)Filter).Condition, ScanIndexForward=!IsBackwardSearch, TableName=TableName, }; queryReq.BeforeRequestEvent += SourceTable.UserAgentRequestEventHandlerSync; QueryResult queryResult = SourceTable.DDBClient.Query(queryReq).QueryResult; count = Matches.Count + queryResult.Count; return count; default: throw new InvalidOperationException("Unknown Search Method"); } } } }
private int GetCount() { if (IsDone) { return Matches.Count; } else { if (count != -1) { return count; } else { switch (SearchMethod) { case SearchType.Scan: ScanRequest scanReq = new ScanRequest() .WithCount(true) .WithExclusiveStartKey(NextKey) .WithTableName(TableName) .WithBeforeRequestHandler(SourceTable.UserAgentRequestEventHandlerSync) as ScanRequest; scanReq.ScanFilter = (ScanFilter)Filter; ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq).ScanResult; count = Matches.Count + scanResult.Count; return count; case SearchType.Query: QueryRequest queryReq = new QueryRequest() .WithConsistentRead(IsConsistentRead) .WithCount(true) .WithExclusiveStartKey(NextKey) .WithHashKeyValue(HashKey) .WithRangeKeyCondition(((RangeFilter)Filter).Condition) .WithScanIndexForward(!IsBackwardSearch) .WithTableName(TableName) .WithBeforeRequestHandler(SourceTable.UserAgentRequestEventHandlerSync) as QueryRequest; QueryResult queryResult = SourceTable.DDBClient.Query(queryReq).QueryResult; count = Matches.Count + queryResult.Count; return count; default: throw new InvalidOperationException("Unknown Search Method"); } } } }
/// <summary> /// Retrieves the next set (page) of results /// </summary> /// <returns>Next set of Documents matching the search parameters</returns> public List<Document> GetNextSet() { List<Document> ret = new List<Document>(); if (!IsDone) { switch (SearchMethod) { case SearchType.Scan: ScanRequest scanReq = new ScanRequest() .WithExclusiveStartKey(NextKey) .WithLimit(Limit) .WithTableName(TableName) .WithBeforeRequestHandler(SourceTable.UserAgentRequestEventHandler) as ScanRequest; if (AttributesToGet != null) scanReq.AttributesToGet = AttributesToGet; scanReq.ScanFilter = (ScanFilter)Filter; ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq).ScanResult; foreach (var item in scanResult.Items) { Document doc = Document.FromAttributeMap(item); ret.Add(doc); Matches.Add(doc); } NextKey = scanResult.LastEvaluatedKey; if (NextKey == null) { IsDone = true; } return ret; case SearchType.Query: QueryRequest queryReq = new QueryRequest() .WithConsistentRead(IsConsistentRead) .WithExclusiveStartKey(NextKey) .WithHashKeyValue(HashKey) .WithLimit(Limit) .WithRangeKeyCondition(((RangeFilter)Filter).Condition) .WithScanIndexForward(!IsBackwardSearch) .WithTableName(TableName) .WithBeforeRequestHandler(SourceTable.UserAgentRequestEventHandler) as QueryRequest; if (AttributesToGet !=null) queryReq.AttributesToGet = AttributesToGet; QueryResult queryResult = SourceTable.DDBClient.Query(queryReq).QueryResult; foreach (var item in queryResult.Items) { Document doc = Document.FromAttributeMap(item); ret.Add(doc); Matches.Add(doc); } NextKey = queryResult.LastEvaluatedKey; if (NextKey == null) { IsDone = true; } return ret; default: throw new InvalidOperationException("Unknown Search Method"); } } return ret; }