Skip to content

Commit

Permalink
identifiers don't need to be structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuck committed Jun 27, 2024
1 parent ab9fef7 commit cbf135b
Show file tree
Hide file tree
Showing 24 changed files with 46 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DataModel;
using CSharpFunctionalExtensions;
using YuckQi.Data.Handlers.Abstract;
using YuckQi.Data.Handlers.Options;
Expand All @@ -13,7 +8,7 @@

namespace YuckQi.Data.DocumentDb.DynamoDb.Handlers;

public class CreationHandler<TEntity, TIdentifier, TScope> : CreationHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier>, ICreated where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDynamoDBContext?
public class CreationHandler<TEntity, TIdentifier, TScope> : CreationHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier>, ICreated where TIdentifier : IEquatable<TIdentifier> where TScope : IDynamoDBContext?
{
public CreationHandler() : this(null) { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DataModel;
using YuckQi.Data.Handlers.Abstract;
using YuckQi.Domain.Entities.Abstract;
using YuckQi.Extensions.Mapping.Abstractions;

namespace YuckQi.Data.DocumentDb.DynamoDb.Handlers;

public class PhysicalDeletionHandler<TEntity, TIdentifier, TScope> : PhysicalDeletionHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDynamoDBContext?
public class PhysicalDeletionHandler<TEntity, TIdentifier, TScope> : PhysicalDeletionHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IDynamoDBContext?
{
public PhysicalDeletionHandler() : base(null) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace YuckQi.Data.DocumentDb.DynamoDb.Handlers;

public class RetrievalHandler<TEntity, TIdentifier, TScope> : RetrievalHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDynamoDBContext?
public class RetrievalHandler<TEntity, TIdentifier, TScope> : RetrievalHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IDynamoDBContext?
{
public RetrievalHandler(Func<TIdentifier, Primitive> hashKeyValueFactory) : base(hashKeyValueFactory, null) { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DataModel;
using YuckQi.Data.Handlers.Abstract;
using YuckQi.Data.Handlers.Options;
using YuckQi.Domain.Aspects.Abstract;
Expand All @@ -12,7 +7,7 @@

namespace YuckQi.Data.DocumentDb.DynamoDb.Handlers;

public class RevisionHandler<TEntity, TIdentifier, TScope> : RevisionHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier>, IRevised where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDynamoDBContext?
public class RevisionHandler<TEntity, TIdentifier, TScope> : RevisionHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier>, IRevised where TIdentifier : IEquatable<TIdentifier> where TScope : IDynamoDBContext?
{
public RevisionHandler() : this(null) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.4.2</Version>
<Version>6.5.0</Version>
<Description>An implementation of YuckQi.Data for Amazon DynamoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class DocumentModelExtensions

public static String? GetDatabaseName(this Type? type) => type != null ? DatabaseNameByType.GetOrAdd(type, identifier => GetDatabaseAttribute(identifier).Name) : null;

public static TIdentifier GetIdentifier<TDocument, TIdentifier>(this TDocument document) where TIdentifier : struct
public static TIdentifier? GetIdentifier<TDocument, TIdentifier>(this TDocument document)
{
if (document == null)
return default;
Expand All @@ -31,7 +31,7 @@ public static TIdentifier GetIdentifier<TDocument, TIdentifier>(this TDocument d
return default;
}

public static StringFieldDefinition<TDocument, TIdentifier?>? GetIdentifierFieldDefinition<TDocument, TIdentifier>(this Type? type) where TIdentifier : struct
public static StringFieldDefinition<TDocument, TIdentifier?>? GetIdentifierFieldDefinition<TDocument, TIdentifier>(this Type? type)
{
if (type == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

namespace YuckQi.Data.DocumentDb.MongoDb.Handlers;

public class CreationHandler<TEntity, TIdentifier, TScope> : CreationHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier>, ICreated where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IClientSessionHandle?
public class CreationHandler<TEntity, TIdentifier, TScope> : CreationHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier>, ICreated where TIdentifier : IEquatable<TIdentifier> where TScope : IClientSessionHandle?
{
public CreationHandler() : this(null) { }

public CreationHandler(CreationOptions<TIdentifier>? options) : base(options, null) { }
}

public class CreationHandler<TEntity, TIdentifier, TScope, TDocument> : CreationHandlerBase<TEntity, TIdentifier, TScope?> where TEntity : IEntity<TIdentifier>, ICreated where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IClientSessionHandle?
public class CreationHandler<TEntity, TIdentifier, TScope, TDocument> : CreationHandlerBase<TEntity, TIdentifier, TScope?> where TEntity : IEntity<TIdentifier>, ICreated where TIdentifier : IEquatable<TIdentifier> where TScope : IClientSessionHandle?
{
private static readonly Type DocumentType = typeof(TDocument);

Expand Down Expand Up @@ -54,7 +54,7 @@ public override async Task<IEnumerable<TEntity>> Create(IEnumerable<TEntity> ent
return list;
}

protected override Maybe<TIdentifier> DoCreate(TEntity entity, TScope? scope)
protected override Maybe<TIdentifier?> DoCreate(TEntity entity, TScope? scope)
{
if (scope == null)
throw new ArgumentNullException(nameof(scope));
Expand All @@ -68,7 +68,7 @@ protected override Maybe<TIdentifier> DoCreate(TEntity entity, TScope? scope)
return document.GetIdentifier<TDocument, TIdentifier>();
}

protected override async Task<Maybe<TIdentifier>> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken)
protected override async Task<Maybe<TIdentifier?>> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken)
{
if (scope == null)
throw new ArgumentNullException(nameof(scope));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

namespace YuckQi.Data.DocumentDb.MongoDb.Handlers;

public class PhysicalDeletionHandler<TEntity, TIdentifier, TScope> : PhysicalDeletionHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IClientSessionHandle?
public class PhysicalDeletionHandler<TEntity, TIdentifier, TScope> : PhysicalDeletionHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IClientSessionHandle?
{
public PhysicalDeletionHandler() : base(null) { }
}

public class PhysicalDeletionHandler<TEntity, TIdentifier, TScope, TDocument> : PhysicalDeletionHandlerBase<TEntity, TIdentifier, TScope?> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IClientSessionHandle?
public class PhysicalDeletionHandler<TEntity, TIdentifier, TScope, TDocument> : PhysicalDeletionHandlerBase<TEntity, TIdentifier, TScope?> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IClientSessionHandle?
{
private static readonly Type DocumentType = typeof(TDocument);

Expand All @@ -26,7 +26,7 @@ protected override Boolean DoDelete(TEntity entity, TScope? scope)
var collection = database.GetCollection<TDocument>(DocumentType.GetCollectionName());
var document = GetDocument(entity);
var field = DocumentType.GetIdentifierFieldDefinition<TDocument, TIdentifier>();
var identifier = document?.GetIdentifier<TDocument, TIdentifier>();
var identifier = document != null ? document.GetIdentifier<TDocument, TIdentifier>() : default;
var filter = Builders<TDocument>.Filter.Eq(field, identifier);
var result = collection.DeleteOne(scope, filter);

Expand All @@ -42,7 +42,7 @@ protected override async Task<Boolean> DoDelete(TEntity entity, TScope? scope, C
var collection = database.GetCollection<TDocument>(DocumentType.GetCollectionName());
var document = GetDocument(entity);
var field = DocumentType.GetIdentifierFieldDefinition<TDocument, TIdentifier>();
var identifier = document?.GetIdentifier<TDocument, TIdentifier>();
var identifier = document != null ? document.GetIdentifier<TDocument, TIdentifier>() : default;
var filter = Builders<TDocument>.Filter.Eq(field, identifier);
var result = await collection.DeleteOneAsync(scope, filter, cancellationToken: cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace YuckQi.Data.DocumentDb.MongoDb.Handlers;

public class RetrievalHandler<TEntity, TIdentifier, TScope> : RetrievalHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IClientSessionHandle?
public class RetrievalHandler<TEntity, TIdentifier, TScope> : RetrievalHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IClientSessionHandle?
{
public RetrievalHandler() : base(null) { }
}

public class RetrievalHandler<TEntity, TIdentifier, TScope, TDocument> : RetrievalHandlerBase<TEntity, TIdentifier, TScope?> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IClientSessionHandle?
public class RetrievalHandler<TEntity, TIdentifier, TScope, TDocument> : RetrievalHandlerBase<TEntity, TIdentifier, TScope?> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IClientSessionHandle?
{
private static readonly Type DocumentType = typeof(TDocument);

Expand Down
12 changes: 6 additions & 6 deletions src/YuckQi.Data.DocumentDb.MongoDb/Handlers/RevisionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

namespace YuckQi.Data.DocumentDb.MongoDb.Handlers;

public class RevisionHandler<TEntity, TIdentifier, TScope> : RevisionHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier>, IRevised where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IClientSessionHandle?
public class RevisionHandler<TEntity, TIdentifier, TScope> : RevisionHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier>, IRevised where TIdentifier : IEquatable<TIdentifier> where TScope : IClientSessionHandle?
{
public RevisionHandler() : this(null) { }

public RevisionHandler(RevisionOptions? options) : base(options, null) { }
}

public class RevisionHandler<TEntity, TIdentifier, TScope, TDocument> : RevisionHandlerBase<TEntity, TIdentifier, TScope?> where TEntity : IEntity<TIdentifier>, IRevised where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IClientSessionHandle?
public class RevisionHandler<TEntity, TIdentifier, TScope, TDocument> : RevisionHandlerBase<TEntity, TIdentifier, TScope?> where TEntity : IEntity<TIdentifier>, IRevised where TIdentifier : IEquatable<TIdentifier> where TScope : IClientSessionHandle?
{
private static readonly Type DocumentType = typeof(TDocument);

Expand All @@ -36,7 +36,7 @@ public override IEnumerable<TEntity> Revise(IEnumerable<TEntity> entities, TScop

foreach (var document in documents)
{
var identifier = document?.GetIdentifier<TDocument, TIdentifier>();
var identifier = document != null ? document.GetIdentifier<TDocument, TIdentifier>() : default;
var filter = Builders<TDocument>.Filter.Eq(field, identifier);

collection.ReplaceOne(scope, filter, document);
Expand All @@ -58,7 +58,7 @@ public override async Task<IEnumerable<TEntity>> Revise(IEnumerable<TEntity> ent

foreach (var document in documents)
{
var identifier = document?.GetIdentifier<TDocument, TIdentifier>();
var identifier = document != null ? document.GetIdentifier<TDocument, TIdentifier>() : default;
var filter = Builders<TDocument>.Filter.Eq(field, identifier);

await collection.ReplaceOneAsync(scope, filter, document, cancellationToken: cancellationToken);
Expand All @@ -76,7 +76,7 @@ protected override Boolean DoRevise(TEntity entity, TScope? scope)
var collection = database.GetCollection<TDocument>(DocumentType.GetCollectionName());
var field = DocumentType.GetIdentifierFieldDefinition<TDocument, TIdentifier>();
var document = MapToData<TDocument>(entity);
var identifier = document?.GetIdentifier<TDocument, TIdentifier>();
var identifier = document != null ? document.GetIdentifier<TDocument, TIdentifier>() : default;
var filter = Builders<TDocument>.Filter.Eq(field, identifier);
if (document == null)
throw new NullReferenceException();
Expand All @@ -95,7 +95,7 @@ protected override async Task<Boolean> DoRevise(TEntity entity, TScope? scope, C
var collection = database.GetCollection<TDocument>(DocumentType.GetCollectionName());
var field = DocumentType.GetIdentifierFieldDefinition<TDocument, TIdentifier>();
var document = MapToData<TDocument>(entity);
var identifier = document?.GetIdentifier<TDocument, TIdentifier>();
var identifier = document != null ? document.GetIdentifier<TDocument, TIdentifier>() : default;
var filter = Builders<TDocument>.Filter.Eq(field, identifier);
if (document == null)
throw new NullReferenceException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.4.2</Version>
<Version>6.5.0</Version>
<Description>An implementation of YuckQi.Data for MongoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.4.2</Version>
<Version>6.5.0</Version>
<Description>An implementation of YuckQi.Data for a in-memory "database" (ConcurrentDictionary), ideal for rapid development without external dependencies.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
4 changes: 2 additions & 2 deletions src/YuckQi.Data.Sql.Dapper.MySql/Handlers/RetrievalHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace YuckQi.Data.Sql.Dapper.MySql.Handlers;

public class RetrievalHandler<TEntity, TIdentifier, TScope> : RetrievalHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDbTransaction?
public class RetrievalHandler<TEntity, TIdentifier, TScope> : RetrievalHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IDbTransaction?
{
public RetrievalHandler() : this(new SqlGenerator<TEntity>()) { }

Expand All @@ -16,7 +16,7 @@ public RetrievalHandler(ISqlGenerator sqlGenerator) : this(sqlGenerator, DbTypeM
public RetrievalHandler(ISqlGenerator sqlGenerator, IReadOnlyDictionary<Type, DbType> dbTypeMap) : base(sqlGenerator, dbTypeMap, null) { }
}

public class RetrievalHandler<TEntity, TIdentifier, TScope, TRecord> : RetrievalHandlerBase<TEntity, TIdentifier, TScope?, TRecord> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDbTransaction?
public class RetrievalHandler<TEntity, TIdentifier, TScope, TRecord> : RetrievalHandlerBase<TEntity, TIdentifier, TScope?, TRecord> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IDbTransaction?
{
public RetrievalHandler(IMapper mapper) : this(new SqlGenerator<TRecord>(), mapper) { }

Expand Down
4 changes: 2 additions & 2 deletions src/YuckQi.Data.Sql.Dapper.MySql/Handlers/SearchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace YuckQi.Data.Sql.Dapper.MySql.Handlers;

public class SearchHandler<TEntity, TIdentifier, TScope> : SearchHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDbTransaction?
public class SearchHandler<TEntity, TIdentifier, TScope> : SearchHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IDbTransaction?
{
public SearchHandler() : this(new SqlGenerator<TEntity>()) { }

Expand All @@ -16,7 +16,7 @@ public SearchHandler(ISqlGenerator sqlGenerator) : this(sqlGenerator, DbTypeMap.
public SearchHandler(ISqlGenerator sqlGenerator, IReadOnlyDictionary<Type, DbType> dbTypeMap) : base(sqlGenerator, dbTypeMap, null) { }
}

public class SearchHandler<TEntity, TIdentifier, TScope, TRecord> : SearchHandlerBase<TEntity, TIdentifier, TScope?, TRecord> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDbTransaction?
public class SearchHandler<TEntity, TIdentifier, TScope, TRecord> : SearchHandlerBase<TEntity, TIdentifier, TScope?, TRecord> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IDbTransaction?
{
public SearchHandler(IMapper mapper) : this(new SqlGenerator<TRecord>(), mapper) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.4.2</Version>
<Version>6.5.0</Version>
<Description>An implementation of YuckQi.Data for MySQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace YuckQi.Data.Sql.Dapper.Oracle.Handlers;

public class RetrievalHandler<TEntity, TIdentifier, TScope> : RetrievalHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDbTransaction?
public class RetrievalHandler<TEntity, TIdentifier, TScope> : RetrievalHandler<TEntity, TIdentifier, TScope?, TEntity> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IDbTransaction?
{
public RetrievalHandler() : this(new SqlGenerator<TEntity>()) { }

Expand All @@ -16,7 +16,7 @@ public RetrievalHandler(ISqlGenerator sqlGenerator) : this(sqlGenerator, DbTypeM
public RetrievalHandler(ISqlGenerator sqlGenerator, IReadOnlyDictionary<Type, DbType> dbTypeMap) : base(sqlGenerator, dbTypeMap, null) { }
}

public class RetrievalHandler<TEntity, TIdentifier, TScope, TRecord> : RetrievalHandlerBase<TEntity, TIdentifier, TScope?, TRecord> where TEntity : IEntity<TIdentifier> where TIdentifier : struct, IEquatable<TIdentifier> where TScope : IDbTransaction?
public class RetrievalHandler<TEntity, TIdentifier, TScope, TRecord> : RetrievalHandlerBase<TEntity, TIdentifier, TScope?, TRecord> where TEntity : IEntity<TIdentifier> where TIdentifier : IEquatable<TIdentifier> where TScope : IDbTransaction?
{
public RetrievalHandler(IMapper mapper) : this(new SqlGenerator<TRecord>(), mapper) { }

Expand Down
Loading

0 comments on commit cbf135b

Please sign in to comment.