コード例 #1
0
        public void AddRelation(Relation relation)
        {
            RelationName relationName = context.RelationNames.Where(x => x.Id == relation.RelationNameId).FirstOrDefault();

            RelationName mirror = context.RelationNames.Where(x => x.Name == relationName.MirrorName).FirstOrDefault();

            Relation mirrorRelation = new Relation()
            {
                SourceId = relation.TargetId, TargetId = relation.SourceId, RelationNameId = mirror.Id
            };

            relation.TargetPerson = null;

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    context.Relations.Add(relation);

                    context.Relations.Add(mirrorRelation);

                    context.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }
コード例 #2
0
        [U] public void Null()
        {
            RelationName value = "foo";

            (value == null).Should().BeFalse();
            (null == value).Should().BeFalse();
        }
コード例 #3
0
        protected virtual Command OnCreateTable(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
        {
            var command    = new Command();
            var isGtt      = MetadataRelationType == MetadataRelationType.GLOBAL_TEMPORARY_PRESERVE || MetadataRelationType == MetadataRelationType.GLOBAL_TEMPORARY_DELETE;
            var isExternal = MetadataRelationType == MetadataRelationType.EXTERNAL;

            command.Append("CREATE ");
            if (isGtt)
            {
                command.Append("GLOBAL TEMPORARY ");
            }
            command.Append($"TABLE {RelationName.AsSqlIndentifier()} ");
            if (isExternal)
            {
                command.Append($"EXTERNAL '{SqlHelper.DoubleSingleQuotes(ExternalFile)}' ");
            }
            command.Append("(");
            command.AppendLine();
            InsertColumns(command, sourceMetadata, targetMetadata, context, false);
            command.AppendLine();
            command.Append(")");
            if (isGtt)
            {
                command.AppendLine();
                command.Append($"ON COMMIT {MetadataRelationType.ToDescription()} ROWS");
            }
            return(command);
        }
コード例 #4
0
    protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        if (IsUserCreatedIndex)
        {
            var command = new Command();
            command
            .Append($"CREATE {(Unique ? "UNIQUE " : string.Empty)}{(Descending ? "DESCENDING" : "ASCENDING")} INDEX {IndexName.AsSqlIndentifier()}")
            .AppendLine()
            .Append($"    ON {RelationName.AsSqlIndentifier()}");
            if (ExpressionSource == null)
            {
                command.Append($"({string.Join(",", Segments.Select(s => s.FieldName.AsSqlIndentifier()))})");
            }
            else
            {
                command.Append($" COMPUTED BY {ExpressionSource}");
            }

            yield return(command);

            if (Inactive)
            {
                yield return(HandleIndexActiveInactive(context));
            }
        }
    }
コード例 #5
0
    protected virtual Command OnCreateView(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var command = new Command();

        command.Append($"CREATE OR ALTER VIEW {RelationName.AsSqlIndentifier()} (");
        command.AppendLine();
        InsertColumns(command, sourceMetadata, targetMetadata, context, true);
        command.Append(")");
        command.AppendLine();
        command.Append("AS");
        if (context.EmptyBodiesEnabled)
        {
            command.AppendLine();
            var fields = string.Join(", ", Fields.Select(x => SqlHelper.GetDataType(x.Field, sourceMetadata.MetadataCharacterSets.CharacterSetsById, sourceMetadata.MetadataDatabase.Database.CharacterSet.CharacterSetId)).Select(RelationField.CreateShimFieldContent));
            command.Append($"SELECT {fields} FROM RDB$DATABASE");
        }
        else
        {
            if (!char.IsWhiteSpace(ViewSource[0]))
            {
                command.AppendLine();
            }
            command.Append(ViewSource);
        }
        return(command);
    }
コード例 #6
0
    protected virtual Command OnCreateTable(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var command    = new Command();
        var isGtt      = MetadataRelationType == MetadataRelationType.GlobalTemporaryPreserve || MetadataRelationType == MetadataRelationType.GlobalTemporaryDelete;
        var isExternal = MetadataRelationType == MetadataRelationType.External;

        command.Append("CREATE ");
        if (isGtt)
        {
            command.Append("GLOBAL TEMPORARY ");
        }
        command.Append($"TABLE {RelationName.AsSqlIndentifier()} ");
        if (isExternal)
        {
            command.Append($"EXTERNAL '{SqlHelper.DoubleSingleQuotes(ExternalFile)}' ");
        }
        command.Append("(");
        command.AppendLine();
        InsertColumns(command, sourceMetadata, targetMetadata, context, false);
        command.AppendLine();
        command.Append(")");
        if (isGtt)
        {
            command.AppendLine();
            command.Append($"ON COMMIT {MetadataRelationType.ToDescription()} ROWS");
        }
        if (SqlSecurity != null)
        {
            command.AppendLine();
            command.Append($"SQL SECURITY {SqlHelper.SqlSecurityString(SqlSecurity)}");
        }
        return(command);
    }
コード例 #7
0
        public void UpdateRelation(Relation relation)
        {
            Relation oldRelation = GetRelation(relation.Id);

            Relation mirrorRelation = GetRelation(x => x.SourceId == oldRelation.TargetId &&
                                                  x.TargetId == oldRelation.SourceId);

            RelationName relationName = context.RelationNames.Where(x => x.Id == relation.RelationNameId).FirstOrDefault();

            RelationName mirror = context.RelationNames.Where(x => x.Name == relationName.MirrorName).FirstOrDefault();

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    oldRelation.RelationNameId = relation.RelationNameId;

                    mirrorRelation.RelationNameId = mirror.Id;

                    context.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }
コード例 #8
0
 private string PrintTag(RelationName tag)
 {
     string output = "";
     if (tag < 0)
     {
         tag = ~tag;
         output += "~";
     }
     return output + tag.ToString();
 }
コード例 #9
0
        [U] public void NotEq()
        {
            RelationName name = "foo";

            RelationName[] notEqual = { "bar", "foo  ", "  foo   ", "x", "", "   ", typeof(Project) };
            foreach (var t in notEqual)
            {
                (t != name).ShouldBeTrue(t);
                t.Should().NotBe(name);
            }
        }
コード例 #10
0
ファイル: ArffHeader.cs プロジェクト: chausner/ArffTools
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>The hash code for the current object.</returns>
        public override int GetHashCode()
        {
            int hashCode = RelationName.GetHashCode();

            foreach (ArffAttribute attribute in Attributes)
            {
                hashCode = unchecked (hashCode * 31 + attribute.GetHashCode());
            }

            return(hashCode);
        }
コード例 #11
0
ファイル: Header.cs プロジェクト: jrenewhite/dotnet-vic
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>The hash code for the current object.</returns>
        public override int GetHashCode()
        {
            int hashCode = RelationName.GetHashCode();

            foreach (Feature feature in Features)
            {
                hashCode = unchecked (hashCode * 31 + feature.GetHashCode());
            }

            return(hashCode);
        }
コード例 #12
0
        [U] public void Eq()
        {
            RelationName name = "foo";

            RelationName[] equal = { "foo" };
            foreach (var t in equal)
            {
                (t == name).ShouldBeTrue(t);
                t.Should().Be(name);
            }
        }
コード例 #13
0
    protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var command = SqlHelper.IsValidExternalEngine(this) ? new Command() : new PSqlCommand();

        command
        .Append($"CREATE OR ALTER TRIGGER {TriggerName.AsSqlIndentifier()}")
        .AppendLine()
        .Append($"{(Inactive ? "INACTIVE" : "ACTIVE")} ");
        switch (TriggerClass)
        {
        case TriggerClassType.DML:
        case TriggerClassType.DDL:
            command.Append($"{TriggerBeforeAfter.ToDescription()} {TriggerEvents[0].ToDescription()} ");
            foreach (var item in TriggerEvents.Skip(1))
            {
                command.Append($"OR {item.ToDescription()} ");
            }
            break;

        case TriggerClassType.DB:
            command.Append($"ON {TriggerEvents[0].ToDescription()} ");
            break;
        }
        command
        .Append($"POSITION {TriggerSequence}")
        .AppendLine();
        if (TriggerClass == TriggerClassType.DML)
        {
            command
            .Append($"ON {RelationName.AsSqlIndentifier()}")
            .AppendLine();
        }
        if (SqlHelper.IsValidExternalEngine(this))
        {
            command.Append($"EXTERNAL NAME '{SqlHelper.DoubleSingleQuotes(EntryPoint)}'");
            command.AppendLine();
            command.Append($"ENGINE {EngineName.AsSqlIndentifier()}");
        }
        else
        {
            if (SqlSecurity != null)
            {
                command.Append($"SQL SECURITY {SqlHelper.SqlSecurityString(SqlSecurity)}");
                command.AppendLine();
            }
            command.Append(TriggerSource);
        }
        yield return(command);
    }
コード例 #14
0
        protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
        {
            var command = new PSqlCommand();

            command
            .Append($"CREATE OR ALTER TRIGGER {TriggerName.AsSqlIndentifier()}")
            .AppendLine()
            .Append($"{(Inactive ? "INACTIVE" : "ACTIVE")} ");

            if (TriggerClass == TriggerClassType.DB)
            {
                command.Append($"ON {TriggerAction1.ToDescription()} ");
            }
            else if (TriggerClass == TriggerClassType.DML)
            {
                var beforeOrAfter = TriggerAction1.In(new[] { TriggerActionType.BEFORE_INSERT, TriggerActionType.BEFORE_UPDATE, TriggerActionType.BEFORE_DELETE }) ? "BEFORE" : "AFTER";
                command.Append($"{beforeOrAfter} {TriggerAction1.ToDescription()} ");
                if (TriggerAction2 != null)
                {
                    command.Append($"OR {TriggerAction2.ToDescription()} ");
                }
                if (TriggerAction3 != null)
                {
                    command.Append($"OR {TriggerAction3.ToDescription()} ");
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException($"Unknown trigger class {TriggerClass}.");
            }

            command
            .Append($"POSITION {TriggerSequence}")
            .AppendLine();

            if (TriggerClass == TriggerClassType.DML)
            {
                command
                .Append($"ON {RelationName.AsSqlIndentifier()}")
                .AppendLine();
            }

            command.Append(TriggerSource);
            yield return(command);
        }
コード例 #15
0
 public Parent(RelationName name) => Name = name;
コード例 #16
0
    protected virtual IEnumerable <Command> OnAlterTable(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var otherRelation = FindOtherChecked(targetMetadata.MetadataRelations.Relations, RelationName, "table");

        var fieldNames = sourceMetadata
                         .MetadataRelations
                         .Relations[RelationName]
                         .Fields
                         .Select(f => f.FieldName);
        var otherFieldNames = targetMetadata
                              .MetadataRelations
                              .Relations[RelationName]
                              .Fields
                              .Select(f => f.FieldName);

        // 1. new fields
        var newFieldNames = new HashSet <Identifier>(fieldNames);

        newFieldNames.ExceptWith(otherFieldNames);
        var newFields = newFieldNames
                        .Select(fieldName => sourceMetadata.MetadataRelations.RelationFields[new RelationFieldKey(RelationName, fieldName)]);

        foreach (var field in newFields)
        {
            foreach (var command in field.Create(sourceMetadata, targetMetadata, context))
            {
                yield return(command);
            }
            context.CreatedRelationFields.Add(new RelationFieldKey(field.RelationName, field.FieldName));
        }

        // 2. altered fields
        var alteredFieldNames = new HashSet <Identifier>(fieldNames);

        alteredFieldNames.IntersectWith(otherFieldNames);
        var alteredFields = alteredFieldNames
                            .Select(fieldName => new
        {
            Field      = sourceMetadata.MetadataRelations.RelationFields[new RelationFieldKey(RelationName, fieldName)],
            OtherField = targetMetadata.MetadataRelations.RelationFields[new RelationFieldKey(RelationName, fieldName)]
        })
                            .Where(x => x.Field != x.OtherField)
                            .Select(x => x.Field);

        foreach (var command in alteredFields.SelectMany(newField => newField.Alter(sourceMetadata, targetMetadata, context)))
        {
            yield return(command);
        }

        // 3. dropped fields
        var droppedFieldNames = new HashSet <Identifier>(otherFieldNames);

        droppedFieldNames.ExceptWith(fieldNames);
        var droppedFields = droppedFieldNames
                            .Select(fieldName => targetMetadata.MetadataRelations.RelationFields[new RelationFieldKey(RelationName, fieldName)]);

        foreach (var field in droppedFields)
        {
            context.DeferredColumnsToDrop.Add(new CommandGroup().Append(field.Drop(sourceMetadata, targetMetadata, context)));
        }

        // 3. SQL SECURITY
        if (SqlSecurity == null && otherRelation.SqlSecurity != null)
        {
            yield return(new Command().Append($"ALTER TABLE {RelationName.AsSqlIndentifier()} DROP SQL SECURITY"));
        }
        else if (SqlSecurity != null && otherRelation.SqlSecurity != null && SqlSecurity != otherRelation.SqlSecurity)
        {
            yield return(new Command().Append($"ALTER TABLE {RelationName.AsSqlIndentifier()} ALTER SQL SECURITY {SqlHelper.SqlSecurityString(SqlSecurity)}"));
        }
    }
コード例 #17
0
 protected override IEnumerable <Command> OnDrop(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
 {
     yield return(new Command()
                  .Append($"DROP {(MetadataRelationType == MetadataRelationType.View ? "VIEW" : "TABLE")} {RelationName.AsSqlIndentifier()}"));
 }
コード例 #18
0
 public Child(RelationName name, Id parent)
 {
     Name     = name;
     ParentId = parent;
 }
コード例 #19
0
 public string RelationName(RelationName type) => RelationNameResolver.Resolve(type);
 internal static bool IsConditionless(this RelationName marker) => marker == null || marker.Name.IsNullOrEmpty() && marker.Type == null;
コード例 #21
0
ファイル: StateDefs.cs プロジェクト: fgeraci/CS195-Core
    public static string PrettyPrint(RelationName state, bool value)
    {
        return (value == true) ? state.ToString() : "";

        //switch (state)
        //{
        //    case RelationName.IsSittingOn:    return value ? " Iso" : "";
        //    case RelationName.IsFriendOf:     return value ? " Ifo" : "";
        //    case RelationName.IsAdjacentTo:   return value ? " Iat" : "";
        //    case RelationName.IsGuarding: return value ? " Igd" : "";
        //    case RelationName.IsInZone:       return value ? " Iir" : "";
        //    case RelationName.FrontZone:  return value ? " Dfz" : "";
        //    case RelationName.RearZone:   return value ? " Drz" : "";
        //    default: return value ? " Xxx" : "";
        //}
    }
コード例 #22
0
 public static JoinField Link(RelationName child, Id parentId) => new Child(child, parentId);
コード例 #23
0
        [U] public void TypedEq()
        {
            RelationName t1 = typeof(Project), t2 = typeof(Project);

            (t1 == t2).ShouldBeTrue(t2);
        }
コード例 #24
0
ファイル: Rules.cs プロジェクト: fgeraci/CS195-Core
 private static void StoreCache(
     RelationName[] relations,
     IList<Tuple<IHasState, IHasState>> objs)
 {
     if (cacheRelations == null)
         cacheRelations =
             new Dictionary<
                 RelationName[], 
                 IList<Tuple<IHasState, IHasState>>>();
     cacheRelations[relations] = objs;
 }
コード例 #25
0
ファイル: Rules.cs プロジェクト: fgeraci/CS195-Core
 private static IList<Tuple<IHasState, IHasState>> CheckCache(RelationName[] states)
 {
     if (cacheRelations == null)
         return null;
     IList<Tuple<IHasState, IHasState>> results;
     if (cacheRelations.TryGetValue(states, out results) == false)
         return null;
     return results;
 }
コード例 #26
0
    protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var command = new Command();

        command.Append($"ALTER TABLE {RelationName.AsSqlIndentifier()}");
        if (!SqlHelper.IsImplicitIntegrityConstraintName(ConstraintName))
        {
            command.Append($" ADD CONSTRAINT {ConstraintName.AsSqlIndentifier()}");
        }
        else
        {
            command.Append(" ADD");
        }

        switch (RelationConstraintType)
        {
        case RelationConstraintType.Check:
            command.Append($" {Triggers[0].TriggerSource}");
            break;

        case RelationConstraintType.NotNull:
            break;

        case RelationConstraintType.ForeignKey:
        case RelationConstraintType.PrimaryKey:
        case RelationConstraintType.Unique:
        {
            var fields =
                Index
                .Segments
                .OrderBy(s => s.FieldPosition)
                .Select(s => s.FieldName);

            command.Append($" {RelationConstraintType.ToDescription()} ({string.Join(", ", fields)})");

            if (RelationConstraintType == RelationConstraintType.ForeignKey)
            {
                var referenceConstraint         = sourceMetadata.MetadataConstraints.ReferenceConstraintsByName[ConstraintName];
                var referenceRelationConstraint = referenceConstraint.RelationConstraintUq;
                var primaryKeyFields            =
                    referenceRelationConstraint
                    .Index
                    .Segments
                    .OrderBy(s => s.FieldPosition)
                    .Select(s => s.FieldName);

                command
                .AppendLine()
                .Append($"  REFERENCES {referenceRelationConstraint.RelationName} ({string.Join(", ", primaryKeyFields)})");
                if (referenceConstraint.UpdateRule != ConstraintRule.Restrict)
                {
                    command
                    .AppendLine()
                    .Append($"  ON UPDATE {referenceConstraint.UpdateRule.ToDescription()}");
                }
                if (referenceConstraint.DeleteRule != ConstraintRule.Restrict)
                {
                    command
                    .AppendLine()
                    .Append($"  ON DELETE {referenceConstraint.DeleteRule.ToDescription()}");
                }
                if (referenceConstraint.UpdateRule != ConstraintRule.Restrict || referenceConstraint.DeleteRule != ConstraintRule.Restrict)
                {
                    command.AppendLine();
                }
            }

            command.Append(AddConstraintUsingIndex(sourceMetadata, targetMetadata, context));
            break;
        }

        default:
            throw new ArgumentOutOfRangeException($"Unknown relation constraint type: {RelationConstraintType}.");
        }

        yield return(command);
    }
コード例 #27
0
        [U] public void TypedNotEq()
        {
            RelationName t1 = typeof(Project), t2 = typeof(CommitActivity);

            (t1 != t2).ShouldBeTrue(t2);
        }
コード例 #28
0
 protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
 {
     yield return(new Command()
                  .Append($"ALTER TABLE {RelationName.AsSqlIndentifier()} ADD {CreateDefinition(sourceMetadata, targetMetadata, context)}"));
 }
コード例 #29
0
 protected override IEnumerable <Command> OnDrop(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
 {
     yield return(new Command()
                  .Append($"ALTER TABLE {RelationName.AsSqlIndentifier()} DROP {FieldName.AsSqlIndentifier()}"));
 }
コード例 #30
0
 public static JoinField Root(RelationName parent) => new Parent(parent);