/
IAsyncDatabaseCommands.cs
528 lines (450 loc) · 20.4 KB
/
IAsyncDatabaseCommands.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
//-----------------------------------------------------------------------
// <copyright file="IAsyncDatabaseCommands.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Raven.Abstractions.Commands;
using Raven.Abstractions.Data;
using Raven.Abstractions.Extensions;
using Raven.Abstractions.Indexing;
using Raven.Abstractions.Replication;
using Raven.Abstractions.Util;
using Raven.Client.Changes;
using Raven.Client.Connection.Profiling;
using Raven.Client.Document;
#if SILVERLIGHT
using Raven.Client.Silverlight.Connection;
#elif NETFX_CORE
using Raven.Client.WinRT.Connection;
#endif
using Raven.Database.Data;
using Raven.Json.Linq;
namespace Raven.Client.Connection.Async
{
/// <summary>
/// An async database command operations
/// </summary>
public interface IAsyncDatabaseCommands : IDisposable, IHoldProfilingInformation
{
/// <summary>
/// Gets the operations headers.
/// </summary>
/// <value>The operations headers.</value>
NameValueCollection OperationsHeaders { get; set; }
/// <summary>
/// Admin operations performed against system database, like create/delete database
/// </summary>
IAsyncGlobalAdminDatabaseCommands GlobalAdmin { get; }
/// <summary>
/// Admin operations for current database
/// </summary>
IAsyncAdminDatabaseCommands Admin { get; }
IAsyncInfoDatabaseCommands Info { get; }
/// <summary>
/// Begins an async get operation
/// </summary>
/// <param name="key">The key.</param>
Task<JsonDocument> GetAsync(string key);
/// <summary>
/// Begins an async multi get operation
/// </summary>
Task<MultiLoadResult> GetAsync(string[] keys, string[] includes, string transformer = null, Dictionary<string, RavenJToken> queryInputs = null, bool metadataOnly = false);
/// <summary>
/// Begins an async get operation for documents
/// </summary>
/// <param name="start">Paging start</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="metadataOnly">Load just the document metadata</param>
/// <remarks>
/// This is primarily useful for administration of a database
/// </remarks>
Task<JsonDocument[]> GetDocumentsAsync(int start, int pageSize, bool metadataOnly = false);
/// <summary>
/// Begins the async query.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="query">The query.</param>
/// <param name="includes">The include paths</param>
/// <param name="metadataOnly">Load just the document metadata</param>
/// <param name="indexEntriesOnly"></param>
Task<QueryResult> QueryAsync(string index, IndexQuery query, string[] includes, bool metadataOnly = false, bool indexEntriesOnly = false);
/// <summary>
/// Begins the async batch operation
/// </summary>
/// <param name="commandDatas">The command data.</param>
Task<BatchResult[]> BatchAsync(ICommandData[] commandDatas);
/// <summary>
/// Returns a list of suggestions based on the specified suggestion query.
/// </summary>
/// <param name="index">The index to query for suggestions</param>
/// <param name="suggestionQuery">The suggestion query.</param>
Task<SuggestionQueryResult> SuggestAsync(string index, SuggestionQuery suggestionQuery);
/// <summary>
/// Gets the index names from the server asynchronously
/// </summary>
/// <param name="start">Paging start</param>
/// <param name="pageSize">Size of the page.</param>
Task<string[]> GetIndexNamesAsync(int start, int pageSize);
/// <summary>
/// Gets the indexes from the server asynchronously
/// </summary>
/// <param name="start">Paging start</param>
/// <param name="pageSize">Size of the page.</param>
Task<IndexDefinition[]> GetIndexesAsync(int start, int pageSize);
/// <summary>
/// Gets the transformers from the server asynchronously
/// </summary>
Task<TransformerDefinition[]> GetTransformersAsync(int start, int pageSize);
/// <summary>
/// Resets the specified index asynchronously
/// </summary>
/// <param name="name">The name.</param>
Task ResetIndexAsync(string name);
/// <summary>
/// Gets the index definition for the specified name asynchronously
/// </summary>
/// <param name="name">The name.</param>
Task<IndexDefinition> GetIndexAsync(string name);
/// <summary>
/// Gets the transformer definition for the specified name asynchronously
/// </summary>
/// <param name="name">The name.</param>
Task<TransformerDefinition> GetTransformerAsync(string name);
/// <summary>
/// Puts the index definition for the specified name asynchronously
/// </summary>
/// <param name="name">The name.</param>
/// <param name="indexDef">The index def.</param>
/// <param name="overwrite">Should overwrite index</param>
Task<string> PutIndexAsync(string name, IndexDefinition indexDef, bool overwrite);
/// <summary>
/// Puts the transformer definition for the specified name asynchronously
/// </summary>
Task<string> PutTransformerAsync(string name, TransformerDefinition transformerDefinition);
/// <summary>
/// Deletes the index definition for the specified name asynchronously
/// </summary>
/// <param name="name">The name.</param>
Task DeleteIndexAsync(string name);
/// <summary>
/// Perform a set based deletes using the specified index
/// </summary>
/// <param name="indexName">Name of the index.</param>
/// <param name="queryToDelete">The query to delete.</param>
/// <param name="allowStale">if set to <c>true</c> allow the operation while the index is stale.</param>
Task<Operation> DeleteByIndexAsync(string indexName, IndexQuery queryToDelete, bool allowStale = false);
/// <summary>
/// Deletes the transformer definition for the specified name asynchronously
/// </summary>
/// <param name="name">The name.</param>
Task DeleteTransformerAsync(string name);
/// <summary>
/// Deletes the document for the specified id asynchronously
/// </summary>
/// <param name="id">The id.</param>
Task DeleteDocumentAsync(string id);
/// <summary>
/// Puts the document with the specified key in the database
/// </summary>
/// <param name="key">The key.</param>
/// <param name="etag">The etag.</param>
/// <param name="document">The document.</param>
/// <param name="metadata">The metadata.</param>
Task<PutResult> PutAsync(string key, Etag etag, RavenJObject document, RavenJObject metadata);
/// <summary>
/// Sends a patch request for a specific document
/// </summary>
/// <param name="key">Id of the document to patch</param>
/// <param name="patches">Array of patch requests</param>
/// <param name="etag">Require specific Etag [null to ignore]</param>
Task<RavenJObject> PatchAsync(string key, PatchRequest[] patches, Etag etag);
/// <summary>
/// Sends a patch request for a specific document, ignoring the document's Etag
/// </summary>
/// <param name="key">Id of the document to patch</param>
/// <param name="patches">Array of patch requests</param>
/// <param name="ignoreMissing">true if the patch request should ignore a missing document, false to throw DocumentDoesNotExistException</param>
Task<RavenJObject> PatchAsync(string key, PatchRequest[] patches, bool ignoreMissing);
/// <summary>
/// Sends a patch request for a specific document which may or may not currently exist
/// </summary>
/// <param name="key">Id of the document to patch</param>
/// <param name="patchesToExisting">Array of patch requests to apply to an existing document</param>
/// <param name="patchesToDefault">Array of patch requests to apply to a default document when the document is missing</param>
/// <param name="defaultMetadata">The metadata for the default document when the document is missing</param>
Task<RavenJObject> PatchAsync(string key, PatchRequest[] patchesToExisting, PatchRequest[] patchesToDefault, RavenJObject defaultMetadata);
/// <summary>
/// Sends a patch request for a specific document, ignoring the document's Etag
/// </summary>
/// <param name="key">Id of the document to patch</param>
/// <param name="patch">The patch request to use (using JavaScript)</param>
/// <param name="ignoreMissing">true if the patch request should ignore a missing document, false to throw DocumentDoesNotExistException</param>
Task<RavenJObject> PatchAsync(string key, ScriptedPatchRequest patch, bool ignoreMissing);
/// <summary>
/// Sends a patch request for a specific document
/// </summary>
/// <param name="key">Id of the document to patch</param>
/// <param name="patch">The patch request to use (using JavaScript)</param>
/// <param name="etag">Require specific Etag [null to ignore]</param>
Task<RavenJObject> PatchAsync(string key, ScriptedPatchRequest patch, Etag etag);
/// <summary>
/// Sends a patch request for a specific document which may or may not currently exist
/// </summary>
/// <param name="key">Id of the document to patch</param>
/// <param name="patchExisting">The patch request to use (using JavaScript) to an existing document</param>
/// <param name="patchDefault">The patch request to use (using JavaScript) to a default document when the document is missing</param>
/// <param name="defaultMetadata">The metadata for the default document when the document is missing</param>
Task<RavenJObject> PatchAsync(string key, ScriptedPatchRequest patchExisting, ScriptedPatchRequest patchDefault, RavenJObject defaultMetadata);
/// <summary>
/// Create a http request to the specified relative url on the current database
/// </summary>
HttpJsonRequest CreateRequest(string relativeUrl, string method, bool disableRequestCompression = false);
/// <summary>
/// Create a new instance of <see cref="IAsyncDatabaseCommands"/> that will interacts
/// with the specified database
/// </summary>
IAsyncDatabaseCommands ForDatabase(string database);
/// <summary>
/// Create a new instance of <see cref="IAsyncDatabaseCommands"/> that will interacts
/// with the default database
/// </summary>
IAsyncDatabaseCommands ForSystemDatabase();
/// <summary>
/// Returns a new <see cref="IAsyncDatabaseCommands"/> using the specified credentials
/// </summary>
/// <param name="credentialsForSession">The credentials for session.</param>
IAsyncDatabaseCommands With(ICredentials credentialsForSession);
/// <summary>
/// Retrieve the statistics for the database asynchronously
/// </summary>
Task<DatabaseStatistics> GetStatisticsAsync();
/// <summary>
/// Gets the list of databases from the server asynchronously
/// </summary>
Task<string[]> GetDatabaseNamesAsync(int pageSize, int start = 0);
/// <summary>
/// Puts the attachment with the specified key asynchronously
/// </summary>
/// <param name="key">The key.</param>
/// <param name="etag">The etag.</param>
/// <param name="stream">The data stream.</param>
/// <param name="metadata">The metadata.</param>
Task PutAttachmentAsync(string key, Etag etag, Stream stream, RavenJObject metadata);
/// <summary>
/// Gets the attachment by the specified key asynchronously
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
Task<Attachment> GetAttachmentAsync(string key);
/// <summary>
/// Gets the attachments asynchronously
/// </summary>
/// <returns></returns>
Task<AttachmentInformation[]> GetAttachmentsAsync(Etag startEtag, int batchSize);
/// <summary>
/// Retrieves the attachment metadata with the specified key, not the actual attachmet
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
Task<Attachment> HeadAttachmentAsync(string key);
/// <summary>
/// Deletes the attachment with the specified key asynchronously
/// </summary>
/// <param name="key">The key.</param>
/// <param name="etag">The etag.</param>
Task DeleteAttachmentAsync(string key, Etag etag);
///<summary>
/// Get the possible terms for the specified field in the index asynchronously
/// You can page through the results by use fromValue parameter as the
/// starting point for the next query
///</summary>
///<returns></returns>
Task<string[]> GetTermsAsync(string index, string field, string fromValue, int pageSize);
/// <summary>
/// Disable all caching within the given scope
/// </summary>
IDisposable DisableAllCaching();
/// <summary>
/// Perform a single POST request containing multiple nested GET requests
/// </summary>
Task<GetResponse[]> MultiGetAsync(GetRequest[] requests);
/// <summary>
/// Perform a set based update using the specified index
/// </summary>
/// <param name="indexName">Name of the index.</param>
/// <param name="queryToUpdate">The query to update.</param>
/// <param name="patch">The patch request to use (using JavaScript)</param>
/// <param name="allowStale">if set to <c>true</c> allow the operation while the index is stale.</param>
Task<Operation> UpdateByIndexAsync(string indexName, IndexQuery queryToUpdate, ScriptedPatchRequest patch, bool allowStale = false);
/// <summary>
/// Using the given Index, calculate the facets as per the specified doc with the given start and pageSize
/// </summary>
/// <param name="index">Name of the index</param>
/// <param name="query">Query to build facet results</param>
/// <param name="facetSetupDoc">Name of the FacetSetup document</param>
/// <param name="start">Start index for paging</param>
/// <param name="pageSize">Paging PageSize. If set, overrides Facet.MaxResults</param>
Task<FacetResults> GetFacetsAsync(string index, IndexQuery query, string facetSetupDoc, int start = 0, int? pageSize = null);
/// <summary>
/// Sends a multiple faceted queries in a single request and calculates the facet results for each of them
/// </summary>
/// <param name="facetedQueries">List of queries</param>
Task<FacetResults[]> GetMultiFacetsAsync(FacetQuery[] facetedQueries);
/// <summary>
/// Using the given Index, calculate the facets as per the specified doc with the given start and pageSize
/// </summary>
/// <param name="index">Name of the index</param>
/// <param name="query">Query to build facet results</param>
/// <param name="facets">List of facets</param>
/// <param name="start">Start index for paging</param>
/// <param name="pageSize">Paging PageSize. If set, overrides Facet.MaxResults</param>
Task<FacetResults> GetFacetsAsync(string index, IndexQuery query, List<Facet> facets, int start, int? pageSize);
/// <summary>
/// Gets the Logs
/// </summary>
Task<LogItem[]> GetLogsAsync(bool errorsOnly);
/// <summary>
/// Gets the license Status
/// </summary>
Task<LicensingStatus> GetLicenseStatusAsync();
/// <summary>
/// Gets the build number
/// </summary>
Task<BuildNumber> GetBuildNumberAsync();
/// <summary>
/// Get documents with id of a specific prefix
/// </summary>
Task<JsonDocument[]> StartsWithAsync(string keyPrefix, string matches, int start, int pageSize, RavenPagingInformation pagingInformation = null, bool metadataOnly = false, string exclude = null);
/// <summary>
/// Force the database commands to read directly from the master, unless there has been a failover.
/// </summary>
IDisposable ForceReadFromMaster();
/// <summary>
/// Retrieves the document metadata for the specified document key.
/// </summary>
/// <param name="key">The key.</param>
/// <returns>The document metadata for the specified document, or null if the document does not exist</returns>
Task<JsonDocumentMetadata> HeadAsync(string key);
/// <summary>
/// Queries the specified index in the Raven flavored Lucene query syntax. Will return *all* results, regardless
/// of the number of items that might be returned.
/// </summary>
Task<IAsyncEnumerator<RavenJObject>> StreamQueryAsync(string index, IndexQuery query, Reference<QueryHeaderInformation> queryHeaderInfo);
/// <summary>
/// Streams the documents by etag OR starts with the prefix and match the matches
/// Will return *all* results, regardless of the number of itmes that might be returned.
/// </summary>
Task<IAsyncEnumerator<RavenJObject>> StreamDocsAsync(Etag fromEtag = null, string startsWith = null, string matches = null, int start = 0, int pageSize = int.MaxValue, string exclude = null, RavenPagingInformation pagingInformation = null);
/// <summary>
/// Get the low level bulk insert operation
/// </summary>
ILowLevelBulkInsertOperation GetBulkInsertOperation(BulkInsertOptions options, IDatabaseChanges changes);
Task DeleteAsync(string key, Etag etag);
/// <summary>
/// Get the full URL for the given document key
/// </summary>
string UrlFor(string documentKey);
HttpJsonRequest CreateReplicationAwareRequest(string currentServerUrl, string requestUrl, string method, bool disableRequestCompression = false);
/// <summary>
/// Updates just the attachment with the specified key's metadata
/// </summary>
/// <param name="key">The key.</param>
/// <param name="etag">The etag.</param>
/// <param name="metadata">The metadata.</param>
Task UpdateAttachmentMetadataAsync(string key, Etag etag, RavenJObject metadata);
/// <summary>
/// Gets the attachments starting with the specified prefix
/// </summary>
Task<IAsyncEnumerator<Attachment>> GetAttachmentHeadersStartingWithAsync(string idPrefix, int start, int pageSize);
/// <summary>
/// Commits the specified tx id.
/// </summary>
/// <param name="txId">The tx id.</param>
Task CommitAsync(string txId);
/// <summary>
/// Rollbacks the specified tx id.
/// </summary>
/// <param name="txId">The tx id.</param>
Task RollbackAsync(string txId);
/// <summary>
/// Prepares the transaction on the server.
/// </summary>
/// <param name="txId">The tx id.</param>
Task PrepareTransactionAsync(string txId);
/// <summary>
/// Perform a set based update using the specified index.
/// </summary>
/// <param name="indexName">Name of the index.</param>
/// <param name="queryToUpdate">The query to update.</param>
/// <param name="patchRequests">The patch requests.</param>
/// <param name="allowStale">if set to <c>true</c> allow the operation while the index is stale.</param>
Task<Operation> UpdateByIndexAsync(string indexName, IndexQuery queryToUpdate, PatchRequest[] patchRequests, bool allowStale = false);
/// <summary>
/// Return a list of documents that based on the MoreLikeThisQuery.
/// </summary>
/// <param name="query">The more like this query parameters</param>
/// <returns></returns>
Task<MultiLoadResult> MoreLikeThisAsync(MoreLikeThisQuery query);
/// <summary>
/// Generate the next identity value from the server
/// </summary>
Task<long> NextIdentityForAsync(string name);
}
public interface IAsyncGlobalAdminDatabaseCommands
{
/// <summary>
/// Get admin statistics
/// </summary>
/// <returns></returns>
Task<AdminStatistics> GetStatisticsAsync();
/// <summary>
/// Sends an async command to create a database
/// </summary>
Task CreateDatabaseAsync(DatabaseDocument databaseDocument);
/// <summary>
/// Sends an async command to delete a database
/// </summary>
Task DeleteDatabaseAsync(string databaseName, bool hardDelete = false);
/// <summary>
/// Sends an async command to compact a database. During the compaction the specified database will be offline.
/// </summary>
Task CompactDatabaseAsync(string databaseName);
/// <summary>
/// Begins an async restore operation
/// </summary>
Task StartRestoreAsync(string restoreLocation, string databaseLocation, string databaseName = null, bool defrag = false);
/// <summary>
/// Begins an async backup operation
/// </summary>
Task StartBackupAsync(string backupLocation, DatabaseDocument databaseDocument, string databaseName);
}
public interface IAsyncAdminDatabaseCommands
{
/// <summary>
/// Sends an async command that disables all indexing
/// </summary>
Task StopIndexingAsync();
/// <summary>
/// Sends an async command that enables indexing
/// </summary>
Task StartIndexingAsync();
/// <summary>
/// Get the indexing status
/// </summary>
Task<string> GetIndexingStatusAsync();
}
public interface IAsyncInfoDatabaseCommands
{
/// <summary>
/// Get replication info
/// </summary>
/// <returns></returns>
Task<ReplicationStatistics> GetReplicationInfoAsync();
}
}