1
- #nullable enable
2
1
using System ;
3
2
using System . Collections . Generic ;
4
3
using System . Diagnostics . CodeAnalysis ;
5
4
using System . Linq ;
6
- using System . Threading . Tasks ;
7
5
using JasperFx . Core ;
8
6
using JasperFx . Core . Reflection ;
9
7
using Marten . Events ;
10
- using Marten . Events . Aggregation ;
11
- using Marten . Events . Daemon . Internals ;
12
8
using Marten . Exceptions ;
13
9
using Marten . Internal . Operations ;
14
10
using Marten . Internal . Storage ;
@@ -54,7 +50,6 @@ public void EjectAllPendingChanges()
54
50
ChangeTrackers . Clear ( ) ;
55
51
}
56
52
57
-
58
53
public void Store < T > ( IEnumerable < T > entities ) where T : notnull
59
54
{
60
55
Store ( entities ? . ToArray ( ) ! ) ;
@@ -94,6 +89,7 @@ public void UpdateRevision<T>(T entity, int revision) where T : notnull
94
89
{
95
90
r . Revision = revision ;
96
91
}
92
+
97
93
_workTracker . Add ( op ) ;
98
94
}
99
95
@@ -109,6 +105,7 @@ public void TryUpdateRevision<T>(T entity, int revision) where T : notnull
109
105
r . Revision = revision ;
110
106
r . IgnoreConcurrencyViolation = true ;
111
107
}
108
+
112
109
_workTracker . Add ( op ) ;
113
110
}
114
111
@@ -141,7 +138,11 @@ public void Insert<T>(params T[] entities) where T : notnull
141
138
{
142
139
storage . Store ( this , entity ) ;
143
140
var op = storage . Insert ( entity , this , TenantId ) ;
144
- if ( op is IRevisionedOperation r ) r . Revision = 1 ;
141
+ if ( op is IRevisionedOperation r )
142
+ {
143
+ r . Revision = 1 ;
144
+ }
145
+
145
146
_workTracker . Add ( op ) ;
146
147
}
147
148
}
@@ -206,15 +207,17 @@ public void InsertObjects(IEnumerable<object> documents)
206
207
207
208
public void QueueSqlCommand ( string sql , params object [ ] parameterValues )
208
209
{
209
- QueueSqlCommand ( DefaultParameterPlaceholder , sql , parameterValues : parameterValues ) ;
210
+ QueueSqlCommand ( DefaultParameterPlaceholder , sql , parameterValues ) ;
210
211
}
211
212
212
213
public void QueueSqlCommand ( char placeholder , string sql , params object [ ] parameterValues )
213
214
{
214
215
sql = sql . TrimEnd ( ';' ) ;
215
216
if ( sql . Contains ( ';' ) )
217
+ {
216
218
throw new ArgumentOutOfRangeException ( nameof ( sql ) ,
217
219
"You must specify one SQL command at a time because of Marten's usage of command batching. ';' cannot be used as a command separator here." ) ;
220
+ }
218
221
219
222
var operation = new ExecuteSqlStorageOperation ( placeholder , sql , parameterValues ) ;
220
223
QueueOperation ( operation ) ;
@@ -335,7 +338,8 @@ private void store<T>(IEnumerable<T> entities) where T : notnull
335
338
{
336
339
var storage = StorageFor < T > ( ) ;
337
340
338
- if ( Concurrency == ConcurrencyChecks . Disabled && ( storage . UseOptimisticConcurrency || storage . UseNumericRevisions ) )
341
+ if ( Concurrency == ConcurrencyChecks . Disabled &&
342
+ ( storage . UseOptimisticConcurrency || storage . UseNumericRevisions ) )
339
343
{
340
344
foreach ( var entity in entities )
341
345
{
@@ -385,36 +389,6 @@ public void EjectPatchedTypes(IUnitOfWork changes)
385
389
foreach ( var type in patchedTypes ) EjectAllOfType ( type ) ;
386
390
}
387
391
388
- internal interface IObjectHandler
389
- {
390
- void Execute ( IDocumentSession session , IEnumerable < object > objects ) ;
391
- }
392
-
393
- internal class StoreHandler < T > : IObjectHandler where T : notnull
394
- {
395
- public void Execute ( IDocumentSession session , IEnumerable < object > objects )
396
- {
397
- // Delegate to the Store<T>() method
398
- session . Store ( objects . OfType < T > ( ) . ToArray ( ) ) ;
399
- }
400
- }
401
-
402
- internal class InsertHandler < T > : IObjectHandler where T : notnull
403
- {
404
- public void Execute ( IDocumentSession session , IEnumerable < object > objects )
405
- {
406
- session . Insert ( objects . OfType < T > ( ) . ToArray ( ) ) ;
407
- }
408
- }
409
-
410
- internal class DeleteHandler < T > : IObjectHandler where T : notnull
411
- {
412
- public void Execute ( IDocumentSession session , IEnumerable < object > objects )
413
- {
414
- foreach ( var document in objects . OfType < T > ( ) ) session . Delete ( document ) ;
415
- }
416
- }
417
-
418
392
internal void StoreDocumentInItemMap < TDoc , TId > ( TId id , TDoc document ) where TDoc : class where TId : notnull
419
393
{
420
394
if ( ItemMap . ContainsKey ( typeof ( TDoc ) ) )
@@ -429,7 +403,8 @@ internal void StoreDocumentInItemMap<TDoc, TId>(TId id, TDoc document) where TDo
429
403
}
430
404
}
431
405
432
- internal bool TryGetAggregateFromIdentityMap < TDoc , TId > ( TId id , [ NotNullWhen ( true ) ] out TDoc ? document ) where TDoc : notnull where TId : notnull
406
+ internal bool TryGetAggregateFromIdentityMap < TDoc , TId > ( TId id , [ NotNullWhen ( true ) ] out TDoc ? document )
407
+ where TDoc : notnull where TId : notnull
433
408
{
434
409
if ( Options . EventGraph . UseIdentityMapForAggregates )
435
410
{
@@ -449,4 +424,34 @@ internal bool TryGetAggregateFromIdentityMap<TDoc, TId>(TId id, [NotNullWhen(tru
449
424
document = default ;
450
425
return false ;
451
426
}
427
+
428
+ internal interface IObjectHandler
429
+ {
430
+ void Execute ( IDocumentSession session , IEnumerable < object > objects ) ;
431
+ }
432
+
433
+ internal class StoreHandler < T > : IObjectHandler where T : notnull
434
+ {
435
+ public void Execute ( IDocumentSession session , IEnumerable < object > objects )
436
+ {
437
+ // Delegate to the Store<T>() method
438
+ session . Store ( objects . OfType < T > ( ) . ToArray ( ) ) ;
439
+ }
440
+ }
441
+
442
+ internal class InsertHandler < T > : IObjectHandler where T : notnull
443
+ {
444
+ public void Execute ( IDocumentSession session , IEnumerable < object > objects )
445
+ {
446
+ session . Insert ( objects . OfType < T > ( ) . ToArray ( ) ) ;
447
+ }
448
+ }
449
+
450
+ internal class DeleteHandler < T > : IObjectHandler where T : notnull
451
+ {
452
+ public void Execute ( IDocumentSession session , IEnumerable < object > objects )
453
+ {
454
+ foreach ( var document in objects . OfType < T > ( ) ) session . Delete ( document ) ;
455
+ }
456
+ }
452
457
}
0 commit comments