Skip to content

Instantly share code, notes, and snippets.

@jeremydmiller
Created August 4, 2021 14:35
Show Gist options
  • Save jeremydmiller/4b7fceb536b018806486f538ef7338a3 to your computer and use it in GitHub Desktop.
Save jeremydmiller/4b7fceb536b018806486f538ef7338a3 to your computer and use it in GitHub Desktop.
Generated code for Marten Document Storage
using Marten.AsyncDaemon.Testing;
using Marten.AsyncDaemon.Testing.TestingSupport;
using Marten.Internal;
using Marten.Internal.CompiledQueries;
using Marten.Internal.Storage;
using Marten.Linq;
using Marten.Linq.QueryHandlers;
using Marten.Schema;
using Marten.Schema.Arguments;
using Marten.Testing.Documents;
using Marten.Testing.Events.Aggregation;
using Marten.Testing.Linq.Compiled;
using Npgsql;
using System;
using System.Collections.Generic;
using Weasel.Core;
using Weasel.Postgresql;
namespace Marten.Generated
{
// START: UpsertDistanceOperation
public class UpsertDistanceOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.Distance, System.Guid>
{
private readonly Marten.AsyncDaemon.Testing.Distance _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpsertDistanceOperation(Marten.AsyncDaemon.Testing.Distance document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_upsert_distance(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
}
public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
// Nothing
return System.Threading.Tasks.Task.CompletedTask;
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Upsert;
}
}
// END: UpsertDistanceOperation
// START: InsertDistanceOperation
public class InsertDistanceOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.Distance, System.Guid>
{
private readonly Marten.AsyncDaemon.Testing.Distance _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public InsertDistanceOperation(Marten.AsyncDaemon.Testing.Distance document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_insert_distance(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
}
public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
// Nothing
return System.Threading.Tasks.Task.CompletedTask;
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Insert;
}
}
// END: InsertDistanceOperation
// START: UpdateDistanceOperation
public class UpdateDistanceOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.Distance, System.Guid>
{
private readonly Marten.AsyncDaemon.Testing.Distance _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpdateDistanceOperation(Marten.AsyncDaemon.Testing.Distance document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_update_distance(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
postprocessUpdate(reader, exceptions);
}
public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
await postprocessUpdateAsync(reader, exceptions, token);
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Update;
}
}
// END: UpdateDistanceOperation
// START: QueryOnlyDistanceSelector
public class QueryOnlyDistanceSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.Distance>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public QueryOnlyDistanceSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.Distance Resolve(System.Data.Common.DbDataReader reader)
{
Marten.AsyncDaemon.Testing.Distance document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Distance>(reader, 0);
return document;
}
public System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.Distance> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
Marten.AsyncDaemon.Testing.Distance document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Distance>(reader, 0);
return System.Threading.Tasks.Task.FromResult(document);
}
}
// END: QueryOnlyDistanceSelector
// START: LightweightDistanceSelector
public class LightweightDistanceSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions<Marten.AsyncDaemon.Testing.Distance, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.Distance>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public LightweightDistanceSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.Distance Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
Marten.AsyncDaemon.Testing.Distance document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Distance>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.Distance> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
Marten.AsyncDaemon.Testing.Distance document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Distance>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
}
// END: LightweightDistanceSelector
// START: IdentityMapDistanceSelector
public class IdentityMapDistanceSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap<Marten.AsyncDaemon.Testing.Distance, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.Distance>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public IdentityMapDistanceSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.Distance Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.AsyncDaemon.Testing.Distance document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Distance>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.Distance> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.AsyncDaemon.Testing.Distance document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Distance>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
}
// END: IdentityMapDistanceSelector
// START: DirtyTrackingDistanceSelector
public class DirtyTrackingDistanceSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking<Marten.AsyncDaemon.Testing.Distance, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.Distance>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public DirtyTrackingDistanceSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.Distance Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.AsyncDaemon.Testing.Distance document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Distance>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.Distance> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.AsyncDaemon.Testing.Distance document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Distance>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
}
// END: DirtyTrackingDistanceSelector
// START: QueryOnlyDistanceDocumentStorage
public class QueryOnlyDistanceDocumentStorage : Marten.Internal.Storage.QueryOnlyDocumentStorage<Marten.AsyncDaemon.Testing.Distance, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public QueryOnlyDistanceDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.AsyncDaemon.Testing.Distance document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.AsyncDaemon.Testing.Distance document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.QueryOnlyDistanceSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: QueryOnlyDistanceDocumentStorage
// START: LightweightDistanceDocumentStorage
public class LightweightDistanceDocumentStorage : Marten.Internal.Storage.LightweightDocumentStorage<Marten.AsyncDaemon.Testing.Distance, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public LightweightDistanceDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.AsyncDaemon.Testing.Distance document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.AsyncDaemon.Testing.Distance document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.LightweightDistanceSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: LightweightDistanceDocumentStorage
// START: IdentityMapDistanceDocumentStorage
public class IdentityMapDistanceDocumentStorage : Marten.Internal.Storage.IdentityMapDocumentStorage<Marten.AsyncDaemon.Testing.Distance, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public IdentityMapDistanceDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.AsyncDaemon.Testing.Distance document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.AsyncDaemon.Testing.Distance document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.IdentityMapDistanceSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: IdentityMapDistanceDocumentStorage
// START: DirtyTrackingDistanceDocumentStorage
public class DirtyTrackingDistanceDocumentStorage : Marten.Internal.Storage.DirtyCheckedDocumentStorage<Marten.AsyncDaemon.Testing.Distance, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public DirtyTrackingDistanceDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.AsyncDaemon.Testing.Distance document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertDistanceOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Distance, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.Distance document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.AsyncDaemon.Testing.Distance document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.DirtyTrackingDistanceSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: DirtyTrackingDistanceDocumentStorage
// START: DistanceBulkLoader
public class DistanceBulkLoader : Marten.Internal.CodeGeneration.BulkLoader<Marten.AsyncDaemon.Testing.Distance, System.Guid>
{
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.Distance, System.Guid> _storage;
public DistanceBulkLoader(Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.Distance, System.Guid> storage) : base(storage)
{
_storage = storage;
}
public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.AsyncDaemon.Testing.Distance document, Marten.Storage.ITenant tenant, Marten.ISerializer serializer)
{
writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar);
writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid);
writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid);
writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb);
}
public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.AsyncDaemon.Testing.Distance document, Marten.Storage.ITenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation)
{
await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation);
await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation);
await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation);
await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation);
}
public override string MainLoaderSql()
{
return "COPY cli.mt_doc_distance(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string TempLoaderSql()
{
return "COPY mt_doc_distance_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string CreateTempTableForCopying()
{
return "create temporary table mt_doc_distance_temp as select * from cli.mt_doc_distance limit 0";
}
public override string CopyNewDocumentsFromTempTable()
{
return "insert into cli.mt_doc_distance (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_distance_temp.\"id\", mt_doc_distance_temp.\"data\", mt_doc_distance_temp.\"mt_version\", mt_doc_distance_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_distance_temp left join cli.mt_doc_distance on mt_doc_distance_temp.id = cli.mt_doc_distance.id where cli.mt_doc_distance.id is null)";
}
public override string OverwriteDuplicatesFromTempTable()
{
return "update cli.mt_doc_distance target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_distance_temp source WHERE source.id = target.id";
}
}
// END: DistanceBulkLoader
// START: UpsertDayOperation
public class UpsertDayOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.AsyncDaemon.Testing.Day _document;
private readonly int _id;
private readonly System.Collections.Generic.Dictionary<int, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpsertDayOperation(Marten.AsyncDaemon.Testing.Day document, int id, System.Collections.Generic.Dictionary<int, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_upsert_day(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Integer;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
}
public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
// Nothing
return System.Threading.Tasks.Task.CompletedTask;
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Upsert;
}
}
// END: UpsertDayOperation
// START: InsertDayOperation
public class InsertDayOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.AsyncDaemon.Testing.Day _document;
private readonly int _id;
private readonly System.Collections.Generic.Dictionary<int, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public InsertDayOperation(Marten.AsyncDaemon.Testing.Day document, int id, System.Collections.Generic.Dictionary<int, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_insert_day(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Integer;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
}
public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
// Nothing
return System.Threading.Tasks.Task.CompletedTask;
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Insert;
}
}
// END: InsertDayOperation
// START: UpdateDayOperation
public class UpdateDayOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.AsyncDaemon.Testing.Day _document;
private readonly int _id;
private readonly System.Collections.Generic.Dictionary<int, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpdateDayOperation(Marten.AsyncDaemon.Testing.Day document, int id, System.Collections.Generic.Dictionary<int, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_update_day(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Integer;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
postprocessUpdate(reader, exceptions);
}
public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
await postprocessUpdateAsync(reader, exceptions, token);
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Update;
}
}
// END: UpdateDayOperation
// START: QueryOnlyDaySelector
public class QueryOnlyDaySelector : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.Day>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public QueryOnlyDaySelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.Day Resolve(System.Data.Common.DbDataReader reader)
{
Marten.AsyncDaemon.Testing.Day document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Day>(reader, 0);
return document;
}
public System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.Day> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
Marten.AsyncDaemon.Testing.Day document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Day>(reader, 0);
return System.Threading.Tasks.Task.FromResult(document);
}
}
// END: QueryOnlyDaySelector
// START: LightweightDaySelector
public class LightweightDaySelector : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions<Marten.AsyncDaemon.Testing.Day, int>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.Day>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public LightweightDaySelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.Day Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<int>(0);
Marten.AsyncDaemon.Testing.Day document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Day>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.Day> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<int>(0, token);
Marten.AsyncDaemon.Testing.Day document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Day>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
}
// END: LightweightDaySelector
// START: IdentityMapDaySelector
public class IdentityMapDaySelector : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap<Marten.AsyncDaemon.Testing.Day, int>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.Day>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public IdentityMapDaySelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.Day Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<int>(0);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.AsyncDaemon.Testing.Day document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Day>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.Day> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<int>(0, token);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.AsyncDaemon.Testing.Day document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Day>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
}
// END: IdentityMapDaySelector
// START: DirtyTrackingDaySelector
public class DirtyTrackingDaySelector : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking<Marten.AsyncDaemon.Testing.Day, int>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.Day>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public DirtyTrackingDaySelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.Day Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<int>(0);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.AsyncDaemon.Testing.Day document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Day>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.Day> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<int>(0, token);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.AsyncDaemon.Testing.Day document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.Day>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
}
// END: DirtyTrackingDaySelector
// START: QueryOnlyDayDocumentStorage
public class QueryOnlyDayDocumentStorage : Marten.Internal.Storage.QueryOnlyDocumentStorage<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.Schema.DocumentMapping _document;
public QueryOnlyDayDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override int AssignIdentity(Marten.AsyncDaemon.Testing.Day document, Marten.Storage.ITenant tenant)
{
if (document.Id <= 0) _setter(document, tenant.Sequences.SequenceFor(typeof(Marten.AsyncDaemon.Testing.Day)).NextInt());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override int Identity(Marten.AsyncDaemon.Testing.Day document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.QueryOnlyDaySelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: QueryOnlyDayDocumentStorage
// START: LightweightDayDocumentStorage
public class LightweightDayDocumentStorage : Marten.Internal.Storage.LightweightDocumentStorage<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.Schema.DocumentMapping _document;
public LightweightDayDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override int AssignIdentity(Marten.AsyncDaemon.Testing.Day document, Marten.Storage.ITenant tenant)
{
if (document.Id <= 0) _setter(document, tenant.Sequences.SequenceFor(typeof(Marten.AsyncDaemon.Testing.Day)).NextInt());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override int Identity(Marten.AsyncDaemon.Testing.Day document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.LightweightDaySelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: LightweightDayDocumentStorage
// START: IdentityMapDayDocumentStorage
public class IdentityMapDayDocumentStorage : Marten.Internal.Storage.IdentityMapDocumentStorage<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.Schema.DocumentMapping _document;
public IdentityMapDayDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override int AssignIdentity(Marten.AsyncDaemon.Testing.Day document, Marten.Storage.ITenant tenant)
{
if (document.Id <= 0) _setter(document, tenant.Sequences.SequenceFor(typeof(Marten.AsyncDaemon.Testing.Day)).NextInt());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override int Identity(Marten.AsyncDaemon.Testing.Day document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.IdentityMapDaySelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: IdentityMapDayDocumentStorage
// START: DirtyTrackingDayDocumentStorage
public class DirtyTrackingDayDocumentStorage : Marten.Internal.Storage.DirtyCheckedDocumentStorage<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.Schema.DocumentMapping _document;
public DirtyTrackingDayDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override int AssignIdentity(Marten.AsyncDaemon.Testing.Day document, Marten.Storage.ITenant tenant)
{
if (document.Id <= 0) _setter(document, tenant.Sequences.SequenceFor(typeof(Marten.AsyncDaemon.Testing.Day)).NextInt());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertDayOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.Day, int>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.Day document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override int Identity(Marten.AsyncDaemon.Testing.Day document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.DirtyTrackingDaySelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: DirtyTrackingDayDocumentStorage
// START: DayBulkLoader
public class DayBulkLoader : Marten.Internal.CodeGeneration.BulkLoader<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.Day, int> _storage;
public DayBulkLoader(Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.Day, int> storage) : base(storage)
{
_storage = storage;
}
public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.AsyncDaemon.Testing.Day document, Marten.Storage.ITenant tenant, Marten.ISerializer serializer)
{
writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar);
writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Integer);
writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid);
writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb);
}
public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.AsyncDaemon.Testing.Day document, Marten.Storage.ITenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation)
{
await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation);
await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Integer, cancellation);
await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation);
await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation);
}
public override string MainLoaderSql()
{
return "COPY cli.mt_doc_day(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string TempLoaderSql()
{
return "COPY mt_doc_day_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string CreateTempTableForCopying()
{
return "create temporary table mt_doc_day_temp as select * from cli.mt_doc_day limit 0";
}
public override string CopyNewDocumentsFromTempTable()
{
return "insert into cli.mt_doc_day (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_day_temp.\"id\", mt_doc_day_temp.\"data\", mt_doc_day_temp.\"mt_version\", mt_doc_day_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_day_temp left join cli.mt_doc_day on mt_doc_day_temp.id = cli.mt_doc_day.id where cli.mt_doc_day.id is null)";
}
public override string OverwriteDuplicatesFromTempTable()
{
return "update cli.mt_doc_day target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_day_temp source WHERE source.id = target.id";
}
}
// END: DayBulkLoader
// START: UpsertTargetOperation
public class UpsertTargetOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Documents.Target, System.Guid>
{
private readonly Marten.Testing.Documents.Target _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpsertTargetOperation(Marten.Testing.Documents.Target document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_upsert_target(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
}
public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
// Nothing
return System.Threading.Tasks.Task.CompletedTask;
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Upsert;
}
}
// END: UpsertTargetOperation
// START: InsertTargetOperation
public class InsertTargetOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Documents.Target, System.Guid>
{
private readonly Marten.Testing.Documents.Target _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public InsertTargetOperation(Marten.Testing.Documents.Target document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_insert_target(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
}
public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
// Nothing
return System.Threading.Tasks.Task.CompletedTask;
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Insert;
}
}
// END: InsertTargetOperation
// START: UpdateTargetOperation
public class UpdateTargetOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Documents.Target, System.Guid>
{
private readonly Marten.Testing.Documents.Target _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpdateTargetOperation(Marten.Testing.Documents.Target document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_update_target(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
postprocessUpdate(reader, exceptions);
}
public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
await postprocessUpdateAsync(reader, exceptions, token);
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Update;
}
}
// END: UpdateTargetOperation
// START: QueryOnlyTargetSelector
public class QueryOnlyTargetSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector<Marten.Testing.Documents.Target>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public QueryOnlyTargetSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Documents.Target Resolve(System.Data.Common.DbDataReader reader)
{
Marten.Testing.Documents.Target document;
document = _serializer.FromJson<Marten.Testing.Documents.Target>(reader, 0);
return document;
}
public System.Threading.Tasks.Task<Marten.Testing.Documents.Target> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
Marten.Testing.Documents.Target document;
document = _serializer.FromJson<Marten.Testing.Documents.Target>(reader, 0);
return System.Threading.Tasks.Task.FromResult(document);
}
}
// END: QueryOnlyTargetSelector
// START: LightweightTargetSelector
public class LightweightTargetSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions<Marten.Testing.Documents.Target, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Documents.Target>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public LightweightTargetSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Documents.Target Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
Marten.Testing.Documents.Target document;
document = _serializer.FromJson<Marten.Testing.Documents.Target>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Documents.Target> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
Marten.Testing.Documents.Target document;
document = _serializer.FromJson<Marten.Testing.Documents.Target>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
}
// END: LightweightTargetSelector
// START: IdentityMapTargetSelector
public class IdentityMapTargetSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap<Marten.Testing.Documents.Target, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Documents.Target>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public IdentityMapTargetSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Documents.Target Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.Testing.Documents.Target document;
document = _serializer.FromJson<Marten.Testing.Documents.Target>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Documents.Target> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.Testing.Documents.Target document;
document = _serializer.FromJson<Marten.Testing.Documents.Target>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
}
// END: IdentityMapTargetSelector
// START: DirtyTrackingTargetSelector
public class DirtyTrackingTargetSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking<Marten.Testing.Documents.Target, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Documents.Target>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public DirtyTrackingTargetSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Documents.Target Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.Testing.Documents.Target document;
document = _serializer.FromJson<Marten.Testing.Documents.Target>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Documents.Target> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.Testing.Documents.Target document;
document = _serializer.FromJson<Marten.Testing.Documents.Target>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
}
// END: DirtyTrackingTargetSelector
// START: QueryOnlyTargetDocumentStorage
public class QueryOnlyTargetDocumentStorage : Marten.Internal.Storage.QueryOnlyDocumentStorage<Marten.Testing.Documents.Target, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public QueryOnlyTargetDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Documents.Target document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Documents.Target document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.QueryOnlyTargetSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: QueryOnlyTargetDocumentStorage
// START: LightweightTargetDocumentStorage
public class LightweightTargetDocumentStorage : Marten.Internal.Storage.LightweightDocumentStorage<Marten.Testing.Documents.Target, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public LightweightTargetDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Documents.Target document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Documents.Target document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.LightweightTargetSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: LightweightTargetDocumentStorage
// START: IdentityMapTargetDocumentStorage
public class IdentityMapTargetDocumentStorage : Marten.Internal.Storage.IdentityMapDocumentStorage<Marten.Testing.Documents.Target, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public IdentityMapTargetDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Documents.Target document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Documents.Target document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.IdentityMapTargetSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: IdentityMapTargetDocumentStorage
// START: DirtyTrackingTargetDocumentStorage
public class DirtyTrackingTargetDocumentStorage : Marten.Internal.Storage.DirtyCheckedDocumentStorage<Marten.Testing.Documents.Target, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public DirtyTrackingTargetDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Documents.Target document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertTargetOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.Target, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Documents.Target document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.DirtyTrackingTargetSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: DirtyTrackingTargetDocumentStorage
// START: TargetBulkLoader
public class TargetBulkLoader : Marten.Internal.CodeGeneration.BulkLoader<Marten.Testing.Documents.Target, System.Guid>
{
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.Testing.Documents.Target, System.Guid> _storage;
public TargetBulkLoader(Marten.Internal.Storage.IDocumentStorage<Marten.Testing.Documents.Target, System.Guid> storage) : base(storage)
{
_storage = storage;
}
public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Target document, Marten.Storage.ITenant tenant, Marten.ISerializer serializer)
{
writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar);
writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid);
writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid);
writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb);
}
public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Target document, Marten.Storage.ITenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation)
{
await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation);
await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation);
await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation);
await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation);
}
public override string MainLoaderSql()
{
return "COPY cli.mt_doc_target(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string TempLoaderSql()
{
return "COPY mt_doc_target_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string CreateTempTableForCopying()
{
return "create temporary table mt_doc_target_temp as select * from cli.mt_doc_target limit 0";
}
public override string CopyNewDocumentsFromTempTable()
{
return "insert into cli.mt_doc_target (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_target_temp.\"id\", mt_doc_target_temp.\"data\", mt_doc_target_temp.\"mt_version\", mt_doc_target_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_target_temp left join cli.mt_doc_target on mt_doc_target_temp.id = cli.mt_doc_target.id where cli.mt_doc_target.id is null)";
}
public override string OverwriteDuplicatesFromTempTable()
{
return "update cli.mt_doc_target target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_target_temp source WHERE source.id = target.id";
}
}
// END: TargetBulkLoader
// START: UpsertMyAggregateOperation
public class UpsertMyAggregateOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.Testing.Events.Aggregation.MyAggregate _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpsertMyAggregateOperation(Marten.Testing.Events.Aggregation.MyAggregate document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_upsert_myaggregate(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
}
public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
// Nothing
return System.Threading.Tasks.Task.CompletedTask;
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Upsert;
}
}
// END: UpsertMyAggregateOperation
// START: InsertMyAggregateOperation
public class InsertMyAggregateOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.Testing.Events.Aggregation.MyAggregate _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public InsertMyAggregateOperation(Marten.Testing.Events.Aggregation.MyAggregate document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_insert_myaggregate(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
}
public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
// Nothing
return System.Threading.Tasks.Task.CompletedTask;
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Insert;
}
}
// END: InsertMyAggregateOperation
// START: UpdateMyAggregateOperation
public class UpdateMyAggregateOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.Testing.Events.Aggregation.MyAggregate _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpdateMyAggregateOperation(Marten.Testing.Events.Aggregation.MyAggregate document, System.Guid id, System.Collections.Generic.Dictionary<System.Guid, System.Guid> versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping)
{
_document = document;
_id = id;
_versions = versions;
_mapping = mapping;
}
public override string CommandText()
{
return "select cli.mt_update_myaggregate(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session)
{
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(_document);
// .Net Class Type
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar;
parameters[1].Value = _document.GetType().FullName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = document.Id;
setVersionParameter(parameters[3]);
}
public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions)
{
storeVersion();
postprocessUpdate(reader, exceptions);
}
public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList<System.Exception> exceptions, System.Threading.CancellationToken token)
{
storeVersion();
await postprocessUpdateAsync(reader, exceptions, token);
}
public override Marten.Internal.Operations.OperationRole Role()
{
return Marten.Internal.Operations.OperationRole.Update;
}
}
// END: UpdateMyAggregateOperation
// START: QueryOnlyMyAggregateSelector
public class QueryOnlyMyAggregateSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector<Marten.Testing.Events.Aggregation.MyAggregate>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public QueryOnlyMyAggregateSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Events.Aggregation.MyAggregate Resolve(System.Data.Common.DbDataReader reader)
{
Marten.Testing.Events.Aggregation.MyAggregate document;
document = _serializer.FromJson<Marten.Testing.Events.Aggregation.MyAggregate>(reader, 0);
return document;
}
public System.Threading.Tasks.Task<Marten.Testing.Events.Aggregation.MyAggregate> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
Marten.Testing.Events.Aggregation.MyAggregate document;
document = _serializer.FromJson<Marten.Testing.Events.Aggregation.MyAggregate>(reader, 0);
return System.Threading.Tasks.Task.FromResult(document);
}
}
// END: QueryOnlyMyAggregateSelector
// START: LightweightMyAggregateSelector
public class LightweightMyAggregateSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Events.Aggregation.MyAggregate>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public LightweightMyAggregateSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Events.Aggregation.MyAggregate Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
Marten.Testing.Events.Aggregation.MyAggregate document;
document = _serializer.FromJson<Marten.Testing.Events.Aggregation.MyAggregate>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Events.Aggregation.MyAggregate> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
Marten.Testing.Events.Aggregation.MyAggregate document;
document = _serializer.FromJson<Marten.Testing.Events.Aggregation.MyAggregate>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
}
// END: LightweightMyAggregateSelector
// START: IdentityMapMyAggregateSelector
public class IdentityMapMyAggregateSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Events.Aggregation.MyAggregate>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public IdentityMapMyAggregateSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Events.Aggregation.MyAggregate Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.Testing.Events.Aggregation.MyAggregate document;
document = _serializer.FromJson<Marten.Testing.Events.Aggregation.MyAggregate>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Events.Aggregation.MyAggregate> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.Testing.Events.Aggregation.MyAggregate document;
document = _serializer.FromJson<Marten.Testing.Events.Aggregation.MyAggregate>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
}
// END: IdentityMapMyAggregateSelector
// START: DirtyTrackingMyAggregateSelector
public class DirtyTrackingMyAggregateSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Events.Aggregation.MyAggregate>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public DirtyTrackingMyAggregateSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Events.Aggregation.MyAggregate Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.Testing.Events.Aggregation.MyAggregate document;
document = _serializer.FromJson<Marten.Testing.Events.Aggregation.MyAggregate>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Events.Aggregation.MyAggregate> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
if (_identityMap.TryGetValue(id, out var existing)) return existing;
Marten.Testing.Events.Aggregation.MyAggregate document;
document = _serializer.FromJson<Marten.Testing.Events.Aggregation.MyAggregate>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
}
// END: DirtyTrackingMyAggregateSelector
// START: QueryOnlyMyAggregateDocumentStorage
public class QueryOnlyMyAggregateDocumentStorage : Marten.Internal.Storage.QueryOnlyDocumentStorage<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public QueryOnlyMyAggregateDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Events.Aggregation.MyAggregate document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.QueryOnlyMyAggregateSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: QueryOnlyMyAggregateDocumentStorage
// START: LightweightMyAggregateDocumentStorage
public class LightweightMyAggregateDocumentStorage : Marten.Internal.Storage.LightweightDocumentStorage<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public LightweightMyAggregateDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Events.Aggregation.MyAggregate document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.LightweightMyAggregateSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}
// END: LightweightMyAggregateDocumentStorage
// START: IdentityMapMyAggregateDocumentStorage
public class IdentityMapMyAggregateDocumentStorage : Marten.Internal.Storage.IdentityMapDocumentStorage<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public IdentityMapMyAggregateDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Storage.ITenant tenant)
{
if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid());
return document.Id;
}
public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertMyAggregateOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Events.Aggregation.MyAggregate document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Events.Aggregation.MyAggregate document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.IdentityMapMyAggregateSelector(session, _document);
}
public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loaderSql).With("id", id);
}
public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, Marten.Storage.ITenant tenant)
{
return new NpgsqlCommand(_loadArraySql).With("ids", ids);
}
}