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);
}
}
// END: IdentityMapMyAggregateDocumentStorage
// START: DirtyTrackingMyAggregateDocumentStorage
public class DirtyTrackingMyAggregateDocumentStorage : Marten.Internal.Storage.DirtyCheckedDocumentStorage<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public DirtyTrackingMyAggregateDocumentStorage(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.DirtyTrackingMyAggregateSelector(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: DirtyTrackingMyAggregateDocumentStorage
// START: MyAggregateBulkLoader
public class MyAggregateBulkLoader : Marten.Internal.CodeGeneration.BulkLoader<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid> _storage;
public MyAggregateBulkLoader(Marten.Internal.Storage.IDocumentStorage<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid> storage) : base(storage)
{
_storage = storage;
}
public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Events.Aggregation.MyAggregate 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.Events.Aggregation.MyAggregate 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_myaggregate(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string TempLoaderSql()
{
return "COPY mt_doc_myaggregate_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string CreateTempTableForCopying()
{
return "create temporary table mt_doc_myaggregate_temp as select * from cli.mt_doc_myaggregate limit 0";
}
public override string CopyNewDocumentsFromTempTable()
{
return "insert into cli.mt_doc_myaggregate (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_myaggregate_temp.\"id\", mt_doc_myaggregate_temp.\"data\", mt_doc_myaggregate_temp.\"mt_version\", mt_doc_myaggregate_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_myaggregate_temp left join cli.mt_doc_myaggregate on mt_doc_myaggregate_temp.id = cli.mt_doc_myaggregate.id where cli.mt_doc_myaggregate.id is null)";
}
public override string OverwriteDuplicatesFromTempTable()
{
return "update cli.mt_doc_myaggregate 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_myaggregate_temp source WHERE source.id = target.id";
}
}
// END: MyAggregateBulkLoader
// START: UpsertUserOperation
public class UpsertUserOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Documents.User, System.Guid>
{
private readonly Marten.Testing.Documents.User _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpsertUserOperation(Marten.Testing.Documents.User 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_user(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.User 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: UpsertUserOperation
// START: InsertUserOperation
public class InsertUserOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Documents.User, System.Guid>
{
private readonly Marten.Testing.Documents.User _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public InsertUserOperation(Marten.Testing.Documents.User 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_user(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.User 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: InsertUserOperation
// START: UpdateUserOperation
public class UpdateUserOperation : Marten.Internal.Operations.StorageOperation<Marten.Testing.Documents.User, System.Guid>
{
private readonly Marten.Testing.Documents.User _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpdateUserOperation(Marten.Testing.Documents.User 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_user(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.User 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: UpdateUserOperation
// START: QueryOnlyUserSelector
public class QueryOnlyUserSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector<Marten.Testing.Documents.User>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public QueryOnlyUserSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Documents.User Resolve(System.Data.Common.DbDataReader reader)
{
Marten.Testing.Documents.User document;
document = _serializer.FromJson<Marten.Testing.Documents.User>(reader, 0);
return document;
}
public System.Threading.Tasks.Task<Marten.Testing.Documents.User> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
Marten.Testing.Documents.User document;
document = _serializer.FromJson<Marten.Testing.Documents.User>(reader, 0);
return System.Threading.Tasks.Task.FromResult(document);
}
}
// END: QueryOnlyUserSelector
// START: LightweightUserSelector
public class LightweightUserSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions<Marten.Testing.Documents.User, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Documents.User>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public LightweightUserSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Documents.User Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
Marten.Testing.Documents.User document;
document = _serializer.FromJson<Marten.Testing.Documents.User>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Documents.User> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
Marten.Testing.Documents.User document;
document = _serializer.FromJson<Marten.Testing.Documents.User>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
}
// END: LightweightUserSelector
// START: IdentityMapUserSelector
public class IdentityMapUserSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap<Marten.Testing.Documents.User, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Documents.User>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public IdentityMapUserSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Documents.User 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.User document;
document = _serializer.FromJson<Marten.Testing.Documents.User>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Documents.User> 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.User document;
document = _serializer.FromJson<Marten.Testing.Documents.User>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
}
// END: IdentityMapUserSelector
// START: DirtyTrackingUserSelector
public class DirtyTrackingUserSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking<Marten.Testing.Documents.User, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.Testing.Documents.User>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public DirtyTrackingUserSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.Testing.Documents.User 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.User document;
document = _serializer.FromJson<Marten.Testing.Documents.User>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.Testing.Documents.User> 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.User document;
document = _serializer.FromJson<Marten.Testing.Documents.User>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
}
// END: DirtyTrackingUserSelector
// START: QueryOnlyUserDocumentStorage
public class QueryOnlyUserDocumentStorage : Marten.Internal.Storage.QueryOnlyDocumentStorage<Marten.Testing.Documents.User, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public QueryOnlyUserDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Documents.User 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.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Documents.User document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.QueryOnlyUserSelector(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: QueryOnlyUserDocumentStorage
// START: LightweightUserDocumentStorage
public class LightweightUserDocumentStorage : Marten.Internal.Storage.LightweightDocumentStorage<Marten.Testing.Documents.User, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public LightweightUserDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Documents.User 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.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Documents.User document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.LightweightUserSelector(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: LightweightUserDocumentStorage
// START: IdentityMapUserDocumentStorage
public class IdentityMapUserDocumentStorage : Marten.Internal.Storage.IdentityMapDocumentStorage<Marten.Testing.Documents.User, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public IdentityMapUserDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Documents.User 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.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Documents.User document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.IdentityMapUserSelector(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: IdentityMapUserDocumentStorage
// START: DirtyTrackingUserDocumentStorage
public class DirtyTrackingUserDocumentStorage : Marten.Internal.Storage.DirtyCheckedDocumentStorage<Marten.Testing.Documents.User, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public DirtyTrackingUserDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.Testing.Documents.User 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.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertUserOperation
(
document, Identity(document),
session.Versions.ForType<Marten.Testing.Documents.User, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.Testing.Documents.User document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.DirtyTrackingUserSelector(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: DirtyTrackingUserDocumentStorage
// START: UserBulkLoader
public class UserBulkLoader : Marten.Internal.CodeGeneration.BulkLoader<Marten.Testing.Documents.User, System.Guid>
{
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.Testing.Documents.User, System.Guid> _storage;
public UserBulkLoader(Marten.Internal.Storage.IDocumentStorage<Marten.Testing.Documents.User, System.Guid> storage) : base(storage)
{
_storage = storage;
}
public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.User 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.User 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_user(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string TempLoaderSql()
{
return "COPY mt_doc_user_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string CreateTempTableForCopying()
{
return "create temporary table mt_doc_user_temp as select * from cli.mt_doc_user limit 0";
}
public override string CopyNewDocumentsFromTempTable()
{
return "insert into cli.mt_doc_user (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_user_temp.\"id\", mt_doc_user_temp.\"data\", mt_doc_user_temp.\"mt_version\", mt_doc_user_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_user_temp left join cli.mt_doc_user on mt_doc_user_temp.id = cli.mt_doc_user.id where cli.mt_doc_user.id is null)";
}
public override string OverwriteDuplicatesFromTempTable()
{
return "update cli.mt_doc_user 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_user_temp source WHERE source.id = target.id";
}
}
// END: UserBulkLoader
// START: UpsertTripOperation
public class UpsertTripOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.AsyncDaemon.Testing.TestingSupport.Trip _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpsertTripOperation(Marten.AsyncDaemon.Testing.TestingSupport.Trip 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_trip(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.TestingSupport.Trip 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: UpsertTripOperation
// START: InsertTripOperation
public class InsertTripOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.AsyncDaemon.Testing.TestingSupport.Trip _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public InsertTripOperation(Marten.AsyncDaemon.Testing.TestingSupport.Trip 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_trip(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.TestingSupport.Trip 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: InsertTripOperation
// START: UpdateTripOperation
public class UpdateTripOperation : Marten.Internal.Operations.StorageOperation<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.AsyncDaemon.Testing.TestingSupport.Trip _document;
private readonly System.Guid _id;
private readonly System.Collections.Generic.Dictionary<System.Guid, System.Guid> _versions;
private readonly Marten.Schema.DocumentMapping _mapping;
public UpdateTripOperation(Marten.AsyncDaemon.Testing.TestingSupport.Trip 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_trip(?, ?, ?, ?)";
}
public override NpgsqlTypes.NpgsqlDbType DbType()
{
return NpgsqlTypes.NpgsqlDbType.Uuid;
}
public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.AsyncDaemon.Testing.TestingSupport.Trip 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: UpdateTripOperation
// START: QueryOnlyTripSelector
public class QueryOnlyTripSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.TestingSupport.Trip>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public QueryOnlyTripSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.TestingSupport.Trip Resolve(System.Data.Common.DbDataReader reader)
{
Marten.AsyncDaemon.Testing.TestingSupport.Trip document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.TestingSupport.Trip>(reader, 0);
return document;
}
public System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.TestingSupport.Trip> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
Marten.AsyncDaemon.Testing.TestingSupport.Trip document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.TestingSupport.Trip>(reader, 0);
return System.Threading.Tasks.Task.FromResult(document);
}
}
// END: QueryOnlyTripSelector
// START: LightweightTripSelector
public class LightweightTripSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.TestingSupport.Trip>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public LightweightTripSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.TestingSupport.Trip Resolve(System.Data.Common.DbDataReader reader)
{
var id = reader.GetFieldValue<System.Guid>(0);
Marten.AsyncDaemon.Testing.TestingSupport.Trip document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.TestingSupport.Trip>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.TestingSupport.Trip> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
Marten.AsyncDaemon.Testing.TestingSupport.Trip document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.TestingSupport.Trip>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
return document;
}
}
// END: LightweightTripSelector
// START: IdentityMapTripSelector
public class IdentityMapTripSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.TestingSupport.Trip>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public IdentityMapTripSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.TestingSupport.Trip 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.TestingSupport.Trip document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.TestingSupport.Trip>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.TestingSupport.Trip> 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.TestingSupport.Trip document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.TestingSupport.Trip>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
return document;
}
}
// END: IdentityMapTripSelector
// START: DirtyTrackingTripSelector
public class DirtyTrackingTripSelector : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>, Marten.Linq.Selectors.ISelector<Marten.AsyncDaemon.Testing.TestingSupport.Trip>
{
private readonly Marten.Internal.IMartenSession _session;
private readonly Marten.Schema.DocumentMapping _mapping;
public DirtyTrackingTripSelector(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping)
{
_session = session;
_mapping = mapping;
}
public Marten.AsyncDaemon.Testing.TestingSupport.Trip 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.TestingSupport.Trip document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.TestingSupport.Trip>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
public async System.Threading.Tasks.Task<Marten.AsyncDaemon.Testing.TestingSupport.Trip> 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.TestingSupport.Trip document;
document = _serializer.FromJson<Marten.AsyncDaemon.Testing.TestingSupport.Trip>(reader, 1);
_session.MarkAsDocumentLoaded(id, document);
_identityMap[id] = document;
StoreTracker(_session, document);
return document;
}
}
// END: DirtyTrackingTripSelector
// START: QueryOnlyTripDocumentStorage
public class QueryOnlyTripDocumentStorage : Marten.Internal.Storage.QueryOnlyDocumentStorage<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public QueryOnlyTripDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.AsyncDaemon.Testing.TestingSupport.Trip 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.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.AsyncDaemon.Testing.TestingSupport.Trip document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.QueryOnlyTripSelector(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: QueryOnlyTripDocumentStorage
// START: LightweightTripDocumentStorage
public class LightweightTripDocumentStorage : Marten.Internal.Storage.LightweightDocumentStorage<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public LightweightTripDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.AsyncDaemon.Testing.TestingSupport.Trip 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.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.AsyncDaemon.Testing.TestingSupport.Trip document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.LightweightTripSelector(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: LightweightTripDocumentStorage
// START: IdentityMapTripDocumentStorage
public class IdentityMapTripDocumentStorage : Marten.Internal.Storage.IdentityMapDocumentStorage<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public IdentityMapTripDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.AsyncDaemon.Testing.TestingSupport.Trip 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.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.AsyncDaemon.Testing.TestingSupport.Trip document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.IdentityMapTripSelector(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: IdentityMapTripDocumentStorage
// START: DirtyTrackingTripDocumentStorage
public class DirtyTrackingTripDocumentStorage : Marten.Internal.Storage.DirtyCheckedDocumentStorage<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.Schema.DocumentMapping _document;
public DirtyTrackingTripDocumentStorage(Marten.Schema.DocumentMapping document) : base(document)
{
_document = document;
}
public override System.Guid AssignIdentity(Marten.AsyncDaemon.Testing.TestingSupport.Trip 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.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpdateTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Insert(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.InsertTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
return new Marten.Generated.UpsertTripOperation
(
document, Identity(document),
session.Versions.ForType<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>(),
_document
);
}
public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.AsyncDaemon.Testing.TestingSupport.Trip document, Marten.Internal.IMartenSession session, Marten.Storage.ITenant tenant)
{
throw new System.NotSupportedException();
}
public override System.Guid Identity(Marten.AsyncDaemon.Testing.TestingSupport.Trip document)
{
return document.Id;
}
public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session)
{
return new Marten.Generated.DirtyTrackingTripSelector(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: DirtyTrackingTripDocumentStorage
// START: TripBulkLoader
public class TripBulkLoader : Marten.Internal.CodeGeneration.BulkLoader<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid> _storage;
public TripBulkLoader(Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid> storage) : base(storage)
{
_storage = storage;
}
public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.AsyncDaemon.Testing.TestingSupport.Trip 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.TestingSupport.Trip 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_trip(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string TempLoaderSql()
{
return "COPY mt_doc_trip_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY";
}
public override string CreateTempTableForCopying()
{
return "create temporary table mt_doc_trip_temp as select * from cli.mt_doc_trip limit 0";
}
public override string CopyNewDocumentsFromTempTable()
{
return "insert into cli.mt_doc_trip (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_trip_temp.\"id\", mt_doc_trip_temp.\"data\", mt_doc_trip_temp.\"mt_version\", mt_doc_trip_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_trip_temp left join cli.mt_doc_trip on mt_doc_trip_temp.id = cli.mt_doc_trip.id where cli.mt_doc_trip.id is null)";
}
public override string OverwriteDuplicatesFromTempTable()
{
return "update cli.mt_doc_trip 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_trip_temp source WHERE source.id = target.id";
}
}
// END: TripBulkLoader
// START: FindUserByAllTheThingsCompiledQuery
public class FindUserByAllTheThingsCompiledQuery : Marten.Internal.CompiledQueries.ClonedCompiledQuery<Marten.Testing.Documents.User, Marten.Testing.Linq.Compiled.FindUserByAllTheThings>
{
private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner;
private readonly Marten.Testing.Linq.Compiled.FindUserByAllTheThings _query;
private readonly Marten.Linq.QueryStatistics _statistics;
private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded;
public FindUserByAllTheThingsCompiledQuery(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, Marten.Testing.Linq.Compiled.FindUserByAllTheThings query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded)
{
_inner = inner;
_query = query;
_statistics = statistics;
_hardcoded = hardcoded;
}
public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session)
{
var parameters = builder.AppendWithParameters(@"select d.id, d.data from cli.mt_doc_user as d where ((d.data ->> 'FirstName' = ? and d.data ->> 'UserName' = ?) and d.data ->> 'LastName' = ?) LIMIT ?");
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
parameters[1].Value = _query.Username;
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
parameters[0].Value = _query.FirstName;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
parameters[2].Value = _query.LastName;
_hardcoded.Apply(parameters);
}
}
// END: FindUserByAllTheThingsCompiledQuery
// START: FindUserByAllTheThingsCompiledQuerySource
public class FindUserByAllTheThingsCompiledQuerySource : Marten.Internal.CompiledQueries.CompiledQuerySource<Marten.Testing.Documents.User, Marten.Testing.Linq.Compiled.FindUserByAllTheThings>
{
private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded;
private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler;
public FindUserByAllTheThingsCompiledQuerySource(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler)
{
_hardcoded = hardcoded;
_maybeStatefulHandler = maybeStatefulHandler;
}
public override Marten.Linq.QueryHandlers.IQueryHandler<Marten.Testing.Documents.User> BuildHandler(Marten.Testing.Linq.Compiled.FindUserByAllTheThings query, Marten.Internal.IMartenSession session)
{
return new Marten.Generated.FindUserByAllTheThingsCompiledQuery(_maybeStatefulHandler, query, null, _hardcoded);
}
}
// END: FindUserByAllTheThingsCompiledQuerySource
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment