Exemple #1
0
        public UpsertFunction(DocumentMapping mapping, DbObjectName identifier = null, bool disableConcurrency = false) : base(identifier ?? mapping.UpsertFunction)
        {
            _mapping            = mapping;
            _disableConcurrency = disableConcurrency;
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }

            _tableName = mapping.TableName;

            var table = new DocumentTable(mapping);

            _primaryKeyConstraintName = table.PrimaryKeyName;

            var idType   = mapping.IdMember.GetMemberType();
            var pgIdType = PostgresqlProvider.Instance.GetDatabaseType(idType, mapping.EnumStorage);

            Arguments.Add(new UpsertArgument
            {
                Arg          = "docId",
                PostgresType = pgIdType,
                Column       = "id",
                Members      = new[] { mapping.IdMember }
            });

            Arguments.Add(new DocJsonBodyArgument());

            Arguments.AddRange(mapping.DuplicatedFields.Where(x => !x.OnlyForSearching).Select(x => x.UpsertArgument));

            // These two arguments need to be added this way
            if (mapping.Metadata.Version.Enabled)
            {
                Arguments.Add(new VersionArgument());
            }
            if (mapping.Metadata.DotNetType.Enabled)
            {
                Arguments.Add(new DotNetTypeArgument());
            }

            AddIfActive(mapping.Metadata.CorrelationId);
            AddIfActive(mapping.Metadata.CausationId);
            AddIfActive(mapping.Metadata.LastModifiedBy);
            AddIfActive(mapping.Metadata.Headers);


            if (mapping.IsHierarchy())
            {
                Arguments.Add(new DocTypeArgument());
            }

            if (mapping.UseOptimisticConcurrency)
            {
                Arguments.Add(new CurrentVersionArgument());
            }

            if (mapping.TenancyStyle == TenancyStyle.Conjoined)
            {
                Arguments.Add(new TenantIdArgument());
                _tenantWhereClause    = $"{_tableName.QualifiedName}.{TenantIdColumn.Name} = {TenantIdArgument.ArgName}";
                _andTenantWhereClause = $" and {_tenantWhereClause}";
            }
        }
Exemple #2
0
 protected bool Equals(DocumentTable other)
 {
     return(base.Equals(other));
 }
Exemple #3
0
        public UpsertFunction(DocumentMapping mapping, DbObjectName identifier = null, bool disableConcurrency = false) : base(identifier ?? mapping.UpsertFunction)
        {
            _mapping            = mapping;
            _disableConcurrency = disableConcurrency;
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }

            _tableName = mapping.TableName;

            // TODO -- it'd be nice to not need this here.
            var table = new DocumentTable(mapping);

            if (table.PrimaryKeys.Count > 1)
            {
                _primaryKeyConstraintName = mapping.TableName.Name + "_pkey";
            }
            else
            {
                _primaryKeyConstraintName = "pk_" + mapping.TableName.Name;
            }

            var idType   = mapping.IdMember.GetMemberType();
            var pgIdType = TypeMappings.GetPgType(idType, mapping.EnumStorage);

            Arguments.Add(new UpsertArgument
            {
                Arg          = "docId",
                PostgresType = pgIdType,
                Column       = "id",
                Members      = new[] { mapping.IdMember }
            });

            Arguments.Add(new DocJsonBodyArgument());

            Arguments.AddRange(mapping.DuplicatedFields.Select(x => x.UpsertArgument));

            // TODO -- see the columns below
            if (mapping.Metadata.Version.Enabled)
            {
                Arguments.Add(new VersionArgument());
            }

            if (mapping.Metadata.DotNetType.Enabled)
            {
                Arguments.Add(new DotNetTypeArgument());
            }

            AddIfActive(mapping.Metadata.CorrelationId);
            AddIfActive(mapping.Metadata.CausationId);
            AddIfActive(mapping.Metadata.LastModifiedBy);
            AddIfActive(mapping.Metadata.Headers);


            if (mapping.IsHierarchy())
            {
                Arguments.Add(new DocTypeArgument());
            }

            if (mapping.UseOptimisticConcurrency)
            {
                Arguments.Add(new CurrentVersionArgument());
            }

            if (mapping.TenancyStyle == TenancyStyle.Conjoined)
            {
                Arguments.Add(new TenantIdArgument());
                _tenantWhereClause    = $"{_tableName.QualifiedName}.{TenantIdColumn.Name} = {TenantIdArgument.ArgName}";
                _andTenantWhereClause = $" and {_tenantWhereClause}";
            }
        }