1111
1212namespace ManagedCode . Database . AzureTables ;
1313
14- public class AzureTablesDatabaseCollection < TItem > : IDatabaseCollection < TableId , TItem >
14+ public class AzureTablesDatabaseCollection < TItem > : BaseDatabaseCollection < TableId , TItem >
1515 where TItem : AzureTablesItem , new ( )
1616{
1717 private readonly TableClient _tableClient ;
@@ -21,16 +21,25 @@ public AzureTablesDatabaseCollection(TableClient tableClient)
2121 _tableClient = tableClient ;
2222 }
2323
24- public ICollectionQueryable < TItem > Query => new AzureTablesCollectionQueryable < TItem > ( _tableClient ) ;
24+ public override ICollectionQueryable < TItem > Query => new AzureTablesCollectionQueryable < TItem > ( _tableClient ) ;
25+
26+ public override void Dispose ( )
27+ {
28+ }
29+
30+ public override ValueTask DisposeAsync ( )
31+ {
32+ return new ValueTask ( Task . CompletedTask ) ;
33+ }
2534
2635 #region Get
2736
28- public async Task < TItem ? > GetAsync ( TableId id , CancellationToken cancellationToken = default )
37+ protected override async Task < TItem ? > GetInternalAsync ( TableId id , CancellationToken cancellationToken = default )
2938 {
3039 try
3140 {
32- var response = await ExceptionCatcher . ExecuteAsync ( _tableClient . GetEntityAsync < TItem > ( id . PartitionKey ,
33- id . RowKey , cancellationToken : cancellationToken ) ) ;
41+ var response = await _tableClient . GetEntityAsync < TItem > ( id . PartitionKey ,
42+ id . RowKey , cancellationToken : cancellationToken ) ;
3443
3544 return response . HasValue ? response . Value : null ;
3645 }
@@ -44,33 +53,25 @@ public AzureTablesDatabaseCollection(TableClient tableClient)
4453
4554 #region Count
4655
47- public async Task < long > CountAsync ( CancellationToken cancellationToken = default )
56+ protected override async Task < long > CountInternalAsync ( CancellationToken cancellationToken = default )
4857 {
4958 var query = _tableClient . QueryAsync < TItem > ( cancellationToken : cancellationToken ) ;
5059 return await query . LongCountAsync ( cancellationToken ) ;
5160 }
5261
5362 #endregion
5463
55- public void Dispose ( )
56- {
57- }
58-
59- public ValueTask DisposeAsync ( )
60- {
61- return new ValueTask ( Task . CompletedTask ) ;
62- }
63-
6464 #region Insert
6565
66- public async Task < TItem ? > InsertAsync ( TItem item , CancellationToken cancellationToken = default )
66+ protected override async Task < TItem > InsertInternalAsync ( TItem item , CancellationToken cancellationToken = default )
6767 {
68- var response = await ExceptionCatcher . ExecuteAsync ( _tableClient . AddEntityAsync ( item , cancellationToken ) ) ;
68+ var response = await _tableClient . AddEntityAsync ( item , cancellationToken ) ;
6969
7070 return response . IsError ? null : item ;
7171 }
7272
73- public async Task < int > InsertAsync ( IEnumerable < TItem > items , CancellationToken cancellationToken = default )
73+ protected override async Task < int > InsertInternalAsync ( IEnumerable < TItem > items ,
74+ CancellationToken cancellationToken = default )
7475 {
7576 var responses = await _tableClient . SubmitTransactionByChunksAsync ( items ,
7677 TableTransactionActionType . Add , cancellationToken ) ;
@@ -82,16 +83,17 @@ public async Task<int> InsertAsync(IEnumerable<TItem> items, CancellationToken c
8283
8384 #region InsertOrUpdate
8485
85- public async Task < TItem ? > InsertOrUpdateAsync ( TItem item , CancellationToken cancellationToken = default )
86+ protected override async Task < TItem > InsertOrUpdateInternalAsync ( TItem item ,
87+ CancellationToken cancellationToken = default )
8688 {
8789 var response =
88- await ExceptionCatcher . ExecuteAsync (
89- _tableClient . UpsertEntityAsync ( item , cancellationToken : cancellationToken ) ) ;
90+ await
91+ _tableClient . UpsertEntityAsync ( item , cancellationToken : cancellationToken ) ;
9092
9193 return response . IsError ? null : item ;
9294 }
9395
94- public async Task < int > InsertOrUpdateAsync ( IEnumerable < TItem > items ,
96+ protected override async Task < int > InsertOrUpdateInternalAsync ( IEnumerable < TItem > items ,
9597 CancellationToken cancellationToken = default )
9698 {
9799 var responses = await _tableClient . SubmitTransactionByChunksAsync ( items ,
@@ -104,17 +106,18 @@ public async Task<int> InsertOrUpdateAsync(IEnumerable<TItem> items,
104106
105107 #region Update
106108
107- public async Task < TItem ? > UpdateAsync ( TItem item , CancellationToken cancellationToken = default )
109+ protected override async Task < TItem > UpdateInternalAsync ( TItem item , CancellationToken cancellationToken = default )
108110 {
109111 if ( item . ETag != ETag . All ) item . ETag = ETag . All ;
110112
111- var response = await ExceptionCatcher . ExecuteAsync ( _tableClient . UpdateEntityAsync ( item , item . ETag ,
112- cancellationToken : cancellationToken ) ) ;
113+ var response = await _tableClient . UpdateEntityAsync ( item , item . ETag ,
114+ cancellationToken : cancellationToken ) ;
113115
114116 return response . IsError ? null : item ;
115117 }
116118
117- public async Task < int > UpdateAsync ( IEnumerable < TItem > items , CancellationToken cancellationToken = default )
119+ protected override async Task < int > UpdateInternalAsync ( IEnumerable < TItem > items ,
120+ CancellationToken cancellationToken = default )
118121 {
119122 var responses = await _tableClient . SubmitTransactionByChunksAsync ( items ,
120123 TableTransactionActionType . UpdateMerge , cancellationToken ) ;
@@ -126,36 +129,38 @@ public async Task<int> UpdateAsync(IEnumerable<TItem> items, CancellationToken c
126129
127130 #region Delete
128131
129- public async Task < bool > DeleteAsync ( TableId id , CancellationToken cancellationToken = default )
132+ protected override async Task < bool > DeleteInternalAsync ( TableId id , CancellationToken cancellationToken = default )
130133 {
131134 var response = await _tableClient
132135 . DeleteEntityAsync ( id . PartitionKey , id . RowKey , ETag . All , cancellationToken ) ;
133136
134137 return response ? . IsError is not true ;
135138 }
136139
137- public async Task < bool > DeleteAsync ( TItem item , CancellationToken cancellationToken = default )
140+ protected override async Task < bool > DeleteInternalAsync ( TItem item , CancellationToken cancellationToken = default )
138141 {
139142 var response = await _tableClient
140143 . DeleteEntityAsync ( item . PartitionKey , item . RowKey , ETag . All , cancellationToken ) ;
141144
142145 return response ? . IsError is not true ;
143146 }
144147
145- public Task < int > DeleteAsync ( IEnumerable < TableId > ids , CancellationToken cancellationToken = default )
148+ protected override Task < int > DeleteInternalAsync ( IEnumerable < TableId > ids ,
149+ CancellationToken cancellationToken = default )
146150 {
147151 throw new NotSupportedException ( ) ;
148152 }
149153
150- public async Task < int > DeleteAsync ( IEnumerable < TItem > items , CancellationToken cancellationToken = default )
154+ protected override async Task < int > DeleteInternalAsync ( IEnumerable < TItem > items ,
155+ CancellationToken cancellationToken = default )
151156 {
152157 var responses = await _tableClient . SubmitTransactionByChunksAsync ( items ,
153158 TableTransactionActionType . Delete , cancellationToken ) ;
154159
155160 return responses . Count ( v => ! v . IsError ) ;
156161 }
157162
158- public async Task < bool > DeleteCollectionAsync ( CancellationToken cancellationToken = default )
163+ protected override async Task < bool > DeleteCollectionInternalAsync ( CancellationToken cancellationToken = default )
159164 {
160165 var response = await _tableClient . DeleteAsync ( cancellationToken ) ;
161166
0 commit comments