Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore MartenOps.Store and add MartenOps.StoreMany #1157

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading