Exemple #1
0
        public RelationType(MetaPopulation metaPopulation, Guid id, Guid associationTypeId, Guid roleTypdId)
            : base(metaPopulation)
        {
            this.Id = id;

            this.associationType = new AssociationType(this, associationTypeId);
            this.roleType = new RoleType(this, roleTypdId);

            metaPopulation.OnRelationTypeCreated(this);
        }
Exemple #2
0
        public void AssertAreEqual(IObject association, RoleType roleType, RoleType otherRoleType)
        {
            var value = association.Strategy.GetRole(roleType);
            var otherValue = association.Strategy.GetRole(otherRoleType);

            bool equal;
            if (value == null)
            {
                equal = otherValue == null;
            }
            else
            {
                equal = value.Equals(otherValue);
            }

            if (!equal)
            {
                this.AddError(new DerivationErrorEquals(this, DerivationRelation.Create(association, roleType, otherRoleType)));
            }
        }
Exemple #3
0
 public bool CanWrite(RoleType roleType)
 {
     return this.IsPermitted(roleType, Operation.Write);
 }
Exemple #4
0
 public void SetUnit(IObject allorsObject, RoleType role, Units values)
 {
     if (role.ObjectType.IsString)
     {
         allorsObject.Strategy.SetUnitRole(role, values.String);
     }
     else if (role.ObjectType.IsInteger)
     {
         allorsObject.Strategy.SetUnitRole(role, values.Integer);
     }
     else if (role.ObjectType.IsLong)
     {
         allorsObject.Strategy.SetUnitRole(role, values.Long);
     }
     else if (role.ObjectType.IsDecimal)
     {
         allorsObject.Strategy.SetUnitRole(role, values.Decimal);
     }
     else if (role.ObjectType.IsDouble)
     {
         allorsObject.Strategy.SetUnitRole(role, values.Double);
     }
     else if (role.ObjectType.IsBoolean)
     {
         allorsObject.Strategy.SetUnitRole(role, values.Boolean);
     }
     else if (role.ObjectType.IsDateTime)
     {
         allorsObject.Strategy.SetUnitRole(role, values.DateTime);
     }
     else if (role.ObjectType.IsDate)
     {
         allorsObject.Strategy.SetUnitRole(role, values.Date);
     }
     else if (role.ObjectType.IsUnique)
     {
         allorsObject.Strategy.SetUnitRole(role, values.Unique);
     }
     else if (role.ObjectType.IsBinary)
     {
         allorsObject.Strategy.SetUnitRole(role, values.Binary);
     }
 }
Exemple #5
0
 public void GetUnit(IObject allorsObject, RoleType role, Units values)
 {
     if (role.ObjectType.IsString)
     {
         values.String = (string)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsInteger)
     {
         values.Integer = (int)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsLong)
     {
         values.Long = (long)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsDecimal)
     {
         values.Decimal = (decimal)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsDouble)
     {
         values.Double = (double)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsBoolean)
     {
         values.Boolean = (bool)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsDateTime)
     {
         values.DateTime = (DateTime)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsDate)
     {
         values.Date = (DateTime)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsUnique)
     {
         values.Unique = (Guid)allorsObject.Strategy.GetUnitRole(role);
     }
     else if (role.ObjectType.IsBinary)
     {
         values.Binary = (byte[])allorsObject.Strategy.GetUnitRole(role);
     }
 }
Exemple #6
0
 public void AssertExistsNonEmptyString(IObject association, RoleType roleType)
 {
     this.AssertExists(association, roleType);
     this.AssertNonEmptyString(association, roleType);
 }
Exemple #7
0
 public Tree Add(RoleType roleType, Tree tree)
 {
     var treeNode = new TreeNode(roleType, tree.Nodes);
     this.nodes.Add(treeNode);
     return this;
 }
 private Permission FindPermission(ObjectType objectType, RoleType roleType, Operation operation)
 {
     Extent<Permission> permissions = this.DatabaseSession.Extent<Permission>();
     permissions.Filter.AddEquals(Permissions.Meta.ConcreteClassPointer, objectType.Id);
     permissions.Filter.AddEquals(Permissions.Meta.OperandTypePointer, roleType.Id);
     permissions.Filter.AddEquals(Permissions.Meta.OperationEnum, operation);
     return permissions.First;
 }
            private void AssertRoleNotExists(RoleType roleType, IObject[] associations, IObject[] roles, bool transactionFlag, int testRepeat, int assertRepeat)
            {
                for (int testRepeatIndex = 0; testRepeatIndex < testRepeat; testRepeatIndex++)
                {
                    for (int iAssociation = 0; iAssociation < associations.Length; iAssociation++)
                    {
                        var association = associations[iAssociation];
                        for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                        {
                            Assert.IsEmpty((IObject[])association.Strategy.GetCompositeRoles(roleType));
                        }
                    }

                    for (int iRole = 0; iRole < roles.Length; iRole++)
                    {
                        IObject testRole = roles[iRole];
                        for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                        {
                            Assert.IsNull(testRole.Strategy.GetCompositeAssociation(roleType.AssociationType));
                        }
                    }

                    if (transactionFlag)
                    {
                        this.GetSession().Commit();
                    }
                }
            }
Exemple #10
0
 public void AddError(IObject association, RoleType roleType, string errorMessage, params object[] messageParam)
 {
     var error = new DerivationErrorGeneric(this, new DerivationRelation(association, roleType), errorMessage, messageParam);
     this.AddError(error);
 }
Exemple #11
0
 public void AssertNotExists(IObject association, RoleType roleType)
 {
     if (association.Strategy.ExistRole(roleType))
     {
         this.AddError(new DerivationErrorNotAllowed(this, association, roleType));
     }
 }
Exemple #12
0
 public void AssertNonEmptyString(IObject association, RoleType roleType)
 {
     if (association.Strategy.ExistRole(roleType))
     {
         if (association.Strategy.GetUnitRole(roleType).Equals(string.Empty))
         {
             this.AddError(new DerivationErrorRequired(this, association, roleType));
         }
     }
 }
Exemple #13
0
        public void AssertIsUnique(IObject association, RoleType roleType)
        {
            ISet<IRoleType> roleTypes;
            if (this.Derivation.ChangeSet.RoleTypesByAssociation.TryGetValue(association.Id, out roleTypes))
            {
                if (roleTypes.Contains(roleType))
                {
                    var objectType = roleType.AssociationType.ObjectType;
                    var role = association.Strategy.GetRole(roleType);

                    if (role != null)
                    {
                        var session = association.Strategy.Session;
                        var extent = association.Strategy.Session.Extent(objectType);
                        extent.Filter.AddEquals(roleType, role);
                        if (extent.Count != 1)
                        {
                            this.AddError(new DerivationErrorUnique(this, association, roleType));
                        }
                    }
                }
            }
        }
 public DerivationErrorGeneric(DerivationLog derivationLog, IObject association, RoleType roleType, string message, params object[] messageParam)
     : this(derivationLog, new DerivationRelation(association, roleType), message, messageParam)
 {
 }
            public void Test(RoleType roleType, IObject[] associations, IObject[] roles, IObject[] emptyRoles, bool transactionFlag, int repeat, int testRepeat, int assertRepeat)
            {
                for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                {
                    this.AssertRoleNotExists(roleType, associations, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Add Null
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                    {
                        association.Strategy.AddCompositeRole(roleType, null);
                        this.Commit(transactionFlag);
                    }

                    this.AssertRoleNotExists(roleType, associations, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Remove Null
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                    {
                        association.Strategy.RemoveCompositeRole(roleType, null);
                        this.Commit(transactionFlag);
                    }

                    this.AssertRoleNotExists(roleType, associations, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Add
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            var role = roles[j];
                            association.Strategy.AddCompositeRole(roleType, role);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationForwardExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Add Null
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                    {
                        association.Strategy.AddCompositeRole(roleType, null);
                        this.Commit(transactionFlag);
                    }

                    this.AssertRelationExists(roleType, associations, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Remove Null
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                    {
                        association.Strategy.RemoveCompositeRole(roleType, null);
                        this.Commit(transactionFlag);
                    }

                    this.AssertRelationExists(roleType, associations, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Remove Forward
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        var role = roles[j];
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            association.Strategy.RemoveCompositeRole(roleType, role);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationForwardNotExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Remove Null
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                    {
                        association.Strategy.RemoveCompositeRole(roleType, null);
                        this.Commit(transactionFlag);
                    }

                    this.AssertRoleNotExists(roleType, associations, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Add
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            var role = roles[j];
                            association.Strategy.AddCompositeRole(roleType, role);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationForwardExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Remove Backward
                for (int i = associations.Length - 1; i >= 0; i--)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        var role = roles[j];
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            association.Strategy.RemoveCompositeRole(roleType, role);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationBackwardNotExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Remove Null
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                    {
                        association.Strategy.RemoveCompositeRole(roleType, null);
                        this.Commit(transactionFlag);
                    }

                    this.AssertRoleNotExists(roleType, associations, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Add
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            var role = roles[j];
                            association.Strategy.AddCompositeRole(roleType, role);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationForwardExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Remove All
                for (int i = associations.Length - 1; i >= 0; i--)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            association.Strategy.RemoveCompositeRoles(roleType);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationBackwardNotExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Add
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            var role = roles[j];
                            association.Strategy.AddCompositeRole(roleType, role);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationForwardExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Set Null
                for (int i = associations.Length - 1; i >= 0; i--)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            association.Strategy.SetCompositeRoles(roleType, (IObject[])null);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationBackwardNotExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Add
                for (int i = 0; i < associations.Length; i++)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            var role = roles[j];
                            association.Strategy.AddCompositeRole(roleType, role);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationForwardExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }

                // Set Empty
                for (int i = associations.Length - 1; i >= 0; i--)
                {
                    var association = associations[i];
                    for (int j = i; j < roles.Length; j++)
                    {
                        for (int repeatIndex = 0; repeatIndex < repeat; repeatIndex++)
                        {
                            association.Strategy.SetCompositeRoles(roleType, emptyRoles);
                            this.Commit(transactionFlag);
                        }
                    }

                    this.AssertRelationBackwardNotExists(roleType, associations, i, roles, transactionFlag, testRepeat, assertRepeat);
                }
            }
Exemple #16
0
        internal void OnRoleTypeCreated(RoleType roleType)
        {
            this.roleTypes.Add(roleType);
            this.metaObjectById.Add(roleType.Id, roleType);

            this.Stale();
        }
            private void AssertRelationForwardExists(RoleType roleType, IObject[] associations, int associationIndex, IObject[] roles, bool transactionFlag, int testRepeat, int assertRepeat)
            {
                for (int testRepeatIndex = 0; testRepeatIndex < testRepeat; testRepeatIndex++)
                {
                    for (int k = 0; k < associations.Length; k++)
                    {
                        IObject testAssociation = associations[k];
                        if (k < associationIndex)
                        {
                            for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                            {
                                Assert.IsNotEmpty((IObject[])testAssociation.Strategy.GetCompositeRoles(roleType));
                            }

                            for (int l = 0; l < roles.Length; l++)
                            {
                                IObject testRole = roles[l];
                                if (l == k)
                                {
                                    for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                                    {
                                        Assert.Contains(testRole, (IObject[])testAssociation.Strategy.GetCompositeRoles(roleType));
                                    }

                                    for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                                    {
                                        Assert.AreEqual(testAssociation, testRole.Strategy.GetCompositeAssociation(roleType.AssociationType));
                                    }
                                }
                                else
                                {
                                    for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                                    {
                                        CollectionAssert.DoesNotContain((IObject[])testAssociation.Strategy.GetCompositeRoles(roleType), testRole);
                                    }

                                    for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                                    {
                                        Assert.AreNotEqual(testAssociation, testRole.Strategy.GetCompositeAssociation(roleType.AssociationType));
                                    }
                                }
                            }
                        }
                        else if (k == associationIndex)
                        {
                            for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                            {
                                Assert.IsNotEmpty((IObject[])testAssociation.Strategy.GetCompositeRoles(roleType));
                            }

                            for (int l = 0; l < roles.Length; l++)
                            {
                                IObject testRole = roles[l];
                                if (l >= k)
                                {
                                    for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                                    {
                                        Assert.Contains(testRole, (IObject[])testAssociation.Strategy.GetCompositeRoles(roleType));
                                    }

                                    for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                                    {
                                        Assert.AreEqual(testAssociation, testRole.Strategy.GetCompositeAssociation(roleType.AssociationType));
                                    }
                                }
                                else
                                {
                                    for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                                    {
                                        CollectionAssert.DoesNotContain((IObject[])testAssociation.Strategy.GetCompositeRoles(roleType), testRole);
                                    }

                                    for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                                    {
                                        Assert.AreNotEqual(testAssociation, testRole.Strategy.GetCompositeAssociation(roleType.AssociationType));
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int assertRepeateIndex = 0; assertRepeateIndex < assertRepeat; assertRepeateIndex++)
                            {
                                Assert.IsEmpty((IObject[])testAssociation.Strategy.GetCompositeRoles(roleType));
                            }
                        }
                    }

                    this.Commit(transactionFlag);
                }
            }
 private Permission FindPermission(RoleType roleType, Operation operation)
 {
     return this.FindPermission(roleType.AssociationType.ObjectType, roleType, operation);
 }
Exemple #19
0
 public DerivationRelation(IObject association, RoleType roleType)
 {
     this.association = association;
     this.roleType = roleType;
 }
 public DerivationErrorRequired(DerivationLog derivationLog, IObject association, RoleType roleType)
     : this(derivationLog, new DerivationRelation(association, roleType))
 {
 }
Exemple #21
0
 public TreeNode(RoleType roleType, List<TreeNode> nodes = null)
 {
     this.roleType = roleType;
     this.nodes = nodes ?? new List<TreeNode>();
 }