From 5f76434c98ab0e45447e947c4489ec644f93439a Mon Sep 17 00:00:00 2001 From: vnugent Date: Tue, 1 Aug 2023 18:39:13 -0400 Subject: Latest updates, build configurations, and native compression --- .../src/ProtectedEntityExtensions.cs | 43 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs') diff --git a/lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs b/lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs index ea8d8cb..ec7b4f5 100644 --- a/lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs +++ b/lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.Data @@ -24,13 +24,13 @@ using System.Linq; using System.Threading; +using System.Transactions; using System.Threading.Tasks; using System.Collections.Generic; using VNLib.Utils; using VNLib.Plugins.Extensions.Data.Abstractions; - namespace VNLib.Plugins.Extensions.Data { public static class ProtectedEntityExtensions @@ -41,11 +41,13 @@ namespace VNLib.Plugins.Extensions.Data /// /// The record to update /// The userid of the record owner + /// A token to cancel the operation /// A task that evaluates to the number of records modified - public static Task UpdateUserRecordAsync(this IDataStore store, TEntity record, string userId) where TEntity : class, IDbModel, IUserEntity + public static Task UpdateUserRecordAsync(this IDataStore store, TEntity record, string userId, CancellationToken cancellation = default) + where TEntity : class, IDbModel, IUserEntity { record.UserId = userId; - return store.UpdateAsync(record); + return store.UpdateAsync(record, cancellation); } /// @@ -54,11 +56,13 @@ namespace VNLib.Plugins.Extensions.Data /// /// The record to update /// The userid of the record owner + /// A token to cancel the operation /// A task that evaluates to the number of records modified - public static Task CreateUserRecordAsync(this IDataStore store, TEntity record, string userId) where TEntity : class, IDbModel, IUserEntity + public static Task CreateUserRecordAsync(this IDataStore store, TEntity record, string userId, CancellationToken cancellation = default) + where TEntity : class, IDbModel, IUserEntity { record.UserId = userId; - return store.CreateAsync(record); + return store.CreateAsync(record, cancellation); } /// @@ -108,10 +112,33 @@ namespace VNLib.Plugins.Extensions.Data /// /// /// The unique id of the user to query record count + /// A token to cancel the operation /// A task that resolves the number of records belonging to the specified user - public static Task GetUserRecordCountAsync(this IDataStore store, string userId) where TEntity : class, IDbModel, IUserEntity + public static Task GetUserRecordCountAsync(this IDataStore store, string userId, CancellationToken cancellation = default) + where TEntity : class, IDbModel, IUserEntity + { + return store.GetCountAsync(userId, cancellation); + } + + /// + /// If the current context instance inherits the interface, + /// attempts to open a transaction with the specified isolation level. + /// + /// + /// The transaction isolation level + /// A token to cancel the operation + /// + internal static Task OpenTransactionAsync(this ITransactionalDbContext tdb, IsolationLevel isolationLevel, CancellationToken cancellationToken = default) { - return store.GetCountAsync(userId); + if(tdb is IConcurrentDbContext ccdb) + { + return ccdb.OpenTransactionAsync(isolationLevel, cancellationToken); + } + else + { + //Just ignore the isolation level + return tdb.OpenTransactionAsync(cancellationToken); + } } } } -- cgit