-
-
Notifications
You must be signed in to change notification settings - Fork 429
/
IDocumentSession.cs
147 lines (127 loc) · 4.72 KB
/
IDocumentSession.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
#nullable enable
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Marten.Events;
using Marten.Services;
namespace Marten;
/// <summary>
/// Interface for querying a document database and unit of work updates
/// </summary>
public interface IDocumentSession: IDocumentOperations
{
/// <summary>
/// Force this session to start a connection and transaction. This will make the session do consistent reads through the transaction. Is
/// idempotent.
/// </summary>
void BeginTransaction();
/// <summary>
/// Force this session to start a connection and transaction. This will make the session do consistent reads through the transaction. Is
/// idempotent.
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
ValueTask BeginTransactionAsync(CancellationToken token);
/// <summary>
/// List of all the pending changes to this IDocumentSession
/// </summary>
IUnitOfWork PendingChanges { get; }
/// <summary>
/// Access to the event store functionality
/// </summary>
new IEventStore Events { get; }
/// <summary>
/// Override whether or not this session honors optimistic concurrency checks
/// </summary>
ConcurrencyChecks Concurrency { get; }
/// <summary>
/// Writeable list of the listeners for this session
/// </summary>
IList<IDocumentSessionListener> Listeners { get; }
/// <summary>
/// Optional metadata describing the user name or
/// process name for this unit of work
/// </summary>
string? LastModifiedBy { get; set; }
/// <summary>
/// Saves all the pending changes and deletions to the server in a single Postgresql transaction.
/// </summary>
void SaveChanges();
/// <summary>
/// Asynchronously saves all the pending changes and deletions to the server in a single Postgresql transaction
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task SaveChangesAsync(CancellationToken token = default);
/// <summary>
/// Completely remove the document from this session's unit of work tracking and identity map caching
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="document"></param>
void Eject<T>(T document) where T : notnull;
/// <summary>
/// Completely remove all the documents of given type from this session's unit of work tracking and identity map
/// caching
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="type"></param>
void EjectAllOfType(Type type);
/// <summary>
/// Set an optional user defined metadata value by key
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
void SetHeader(string key, object value);
/// <summary>
/// Get an optional user defined metadata value by key
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
object? GetHeader(string key);
/// <summary>
/// Access data from another tenant and apply document or event updates to this
/// IDocumentSession for a separate tenant
/// </summary>
/// <param name="tenantId"></param>
/// <returns></returns>
new ITenantOperations ForTenant(string tenantId);
/// <summary>
/// Remove all queued operations in this unit of work, but will not impact any existing identity map. I.e., all
/// document stores,
/// event appends, etc.
/// </summary>
void EjectAllPendingChanges();
}
public interface ILoadByKeys<TDoc>
{
/// <summary>
/// Supply the document id's to load
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <param name="keys"></param>
/// <returns></returns>
IReadOnlyList<TDoc> ById<TKey>(params TKey[] keys);
/// <summary>
/// Supply the document id's to load asynchronously
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <param name="keys"></param>
/// <returns></returns>
Task<IReadOnlyList<TDoc>> ByIdAsync<TKey>(params TKey[] keys);
/// <summary>
/// Supply the document id's to load
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <param name="keys"></param>
/// <returns></returns>
IReadOnlyList<TDoc> ById<TKey>(IEnumerable<TKey> keys);
/// <summary>
/// Supply the document id's to load asynchronously
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <param name="keys"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IReadOnlyList<TDoc>> ByIdAsync<TKey>(IEnumerable<TKey> keys, CancellationToken token = default);
}