Skip to content

Commit

Permalink
Restore IMartenOps.Store and added IMartenOps.StoreMany
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-zahiri committed Dec 4, 2024
1 parent 1bc8b0e commit 0f60048
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions src/Persistence/Wolverine.Marten/IMartenOp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,35 @@ public static class MartenOps
/// <summary>
/// Return a side effect of storing the specified document in Marten
/// </summary>
/// <param name="document"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static StoreDoc<T> Store<T>(T document) where T : notnull
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}

return new StoreDoc<T>(document);
}

/// <summary>
/// Return a side effect of storing many documents of a specific document type in Marten
/// </summary>
/// <param name="documents"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static StoreDoc<T> Store<T>(params T[] documents) where T : notnull
public static StoreManyDocs<T> StoreMany<T>(params T[] documents) where T : notnull
{
if (documents == null)
{
throw new ArgumentNullException(nameof(documents));
}

return new StoreDoc<T>(documents);
return new StoreManyDocs<T>(documents);
}

/// <summary>
Expand Down Expand Up @@ -225,10 +242,25 @@ public void Execute(IDocumentSession session)
}

public class StoreDoc<T> : DocumentOp where T : notnull
{
private readonly T _document;

public StoreDoc(T document) : base(document)
{
_document = document;
}

public override void Execute(IDocumentSession session)
{
session.Store(_document);
}
}

public class StoreManyDocs<T> : DocumentsOp where T : notnull
{
private readonly T[] _documents;

public StoreDoc(params T[] documents) : base(documents)
public StoreManyDocs(T[] documents) : base(documents)
{
_documents = documents;
}
Expand Down Expand Up @@ -285,10 +317,22 @@ public override void Execute(IDocumentSession session)
}

public abstract class DocumentOp : IMartenOp
{
public object Document { get; }

protected DocumentOp(object document)
{
Document = document;
}

public abstract void Execute(IDocumentSession session);
}

public abstract class DocumentsOp : IMartenOp
{
public object[] Documents { get; }

protected DocumentOp(params object[] documents)
protected DocumentsOp(params object[] documents)
{
Documents = documents;
}
Expand Down

0 comments on commit 0f60048

Please sign in to comment.