forked from akkadotnet/akka.net
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Hints.cs
226 lines (194 loc) · 8.56 KB
/
Hints.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
//-----------------------------------------------------------------------
// <copyright file="Hints.cs" company="Akka.NET Project">
// Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2016 Akka.NET project <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Akka.Persistence.Sql.Common.Journal;
namespace Akka.Persistence.Sql.Common.Queries
{
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public interface IHint { }
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static class Hints
{
/// <summary>
/// Returns a hint that expects a reply with events with matching manifest.
/// </summary>
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static IHint Manifest(string manifest)
{
return new WithManifest(manifest);
}
/// <summary>
/// Returns a hint that expects a reply with events from provided set of persistence ids.
/// </summary>
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static IHint PersistenceIds(IEnumerable<string> persistenceIds)
{
return new PersistenceIdRange(persistenceIds);
}
/// <summary>
/// Returns a hint that expects a reply with events, that have timestamp value before provided date.
/// </summary>
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static IHint TimestampBefore(DateTime to)
{
return new TimestampRange(null, to.Ticks);
}
/// <summary>
/// Returns a hint that expects a reply with events, that have timestamp value after or equal provided date.
/// </summary>
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static IHint TimestampAfter(DateTime from)
{
return new TimestampRange(from.Ticks, null);
}
/// <summary>
/// Returns a hint that expects a reply with events, that have timestamp from between provided range of values (left side inclusive).
/// </summary>
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static IHint TimestampBetween(DateTime from, DateTime to)
{
return new TimestampRange(from.Ticks, to.Ticks);
}
/// <summary>
/// Returns a hint that expects a reply with events, that have timestamp value before provided date.
/// </summary>
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static IHint TimestampBefore(long to)
{
return new TimestampRange(null, to);
}
/// <summary>
/// Returns a hint that expects a reply with events, that have timestamp value after or equal provided date.
/// </summary>
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static IHint TimestampAfter(long from)
{
return new TimestampRange(from, null);
}
/// <summary>
/// Returns a hint that expects a reply with events, that have timestamp from between provided range of values (left side inclusive).
/// </summary>
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public static IHint TimestampBetween(long from, long to)
{
return new TimestampRange(from, to);
}
}
/// <summary>
/// Hint for the SQL journal used to filter journal entries returned in the response based on the manifest.
/// </summary>
#if SERIALIZATION
[Serializable]
#endif
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public sealed class WithManifest : IHint, IEquatable<WithManifest>
{
public readonly string Manifest;
public WithManifest(string manifest)
{
if (string.IsNullOrEmpty(manifest)) throw new ArgumentException("Hint expected manifest, but none has been provided", "manifest");
Manifest = manifest;
}
public bool Equals(WithManifest other)
{
return other != null && other.Manifest.Equals(Manifest);
}
public override bool Equals(object obj)
{
return Equals(obj as WithManifest);
}
public override int GetHashCode()
{
return (Manifest != null ? Manifest.GetHashCode() : 0);
}
public override string ToString()
{
return string.Format("WithManifest<manifest: {0}>", Manifest);
}
}
/// <summary>
/// Hint for the SQL journal used to filter journal entries returned in the response based on set of perisistence ids provided.
/// </summary>
#if SERIALIZATION
[Serializable]
#endif
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public sealed class PersistenceIdRange : IHint, IEquatable<PersistenceIdRange>
{
public readonly ISet<string> PersistenceIds;
public PersistenceIdRange(IEnumerable<string> persistenceIds)
{
if (persistenceIds == null) throw new ArgumentException("Hint expected persistence ids, but none has been provided", "persistenceIds");
PersistenceIds = new HashSet<string>(persistenceIds);
}
public bool Equals(PersistenceIdRange other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return other.PersistenceIds.SetEquals(PersistenceIds);
}
public override bool Equals(object obj)
{
return Equals(obj as PersistenceIdRange);
}
public override int GetHashCode()
{
return (PersistenceIds != null ? PersistenceIds.GetHashCode() : 0);
}
public override string ToString()
{
return string.Format("PersistenceIdRange<pids: [{0}]>", string.Join(", ", PersistenceIds));
}
}
/// <summary>
/// Hint for the SQL journal used to filter journal entries returned in the response based on their timestamp range.
/// Desired behavior of timestamp range is <from, to) - left side inclusive, right side exclusive.
/// Timestamp is generated by <see cref="JournalDbEngine.GenerateTimestamp"/> method, which may be overloaded.
/// </summary>
#if SERIALIZATION
[Serializable]
#endif
[Obsolete("Existing SQL persistence query will be obsoleted, once Akka.Persistence.Query will came out")]
public sealed class TimestampRange : IHint, IEquatable<TimestampRange>
{
public readonly long? From;
public readonly long? To;
public TimestampRange(long? @from, long? to)
{
if (!from.HasValue && !to.HasValue)
throw new ArgumentException("TimestampRange hint requires either 'From' or 'To' or both range limiters provided");
if (from.HasValue && to.HasValue && from > to)
throw new ArgumentException("TimestampRange hint requires 'From' date to occur before 'To' date");
From = @from;
To = to;
}
public bool Equals(TimestampRange other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(From, other.From) && Equals(To, other.To);
}
public override bool Equals(object obj)
{
return Equals(obj as TimestampRange);
}
public override int GetHashCode()
{
unchecked
{
return (From.GetHashCode() * 397) ^ To.GetHashCode();
}
}
public override string ToString()
{
return string.Format("TimestampRange<from: {0}, to: {1}>",
From.HasValue ? From.Value.ToString() : "undefined",
To.HasValue ? To.Value.ToString() : "undefined");
}
}
}