Пример #1
0
 internal void CheckForRoleType(IRoleType roleType)
 {
     if (!this.objectType.ExistRoleType(roleType))
     {
         throw new ArgumentException("Extent does not have role " + roleType.SingularName);
     }
 }
Пример #2
0
 internal RoleLessThanRole(ExtentFiltered extent, IRoleType role, IRoleType lessThanRole)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleLessThan(role, lessThanRole);
     this.role = role;
     this.lessThanRole = lessThanRole;
 }
Пример #3
0
 internal RoleLike(ExtentFiltered extent, IRoleType role, string like)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleLikeFilter(role, like);
     this.role = role;
     this.like = like;
 }
Пример #4
0
 internal RoleLessThanValue(ExtentFiltered extent, IRoleType roleType, object obj)
 {
     extent.CheckRole(roleType);
     PredicateAssertions.ValidateRoleLessThan(roleType, obj);
     this.roleType = roleType;
     this.obj = roleType.Normalize(obj);
 }
Пример #5
0
 public RoleContainedInEnumerable(AllorsExtentFilteredSql extent, IRoleType role, IEnumerable<IObject> enumerable)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleContainedIn(role, this.enumerable);
     this.role = role;
     this.enumerable = enumerable;
 }
Пример #6
0
 public ICompositePredicate AddBetween(IRoleType role, object firstValue, object secondValue)
 {
     this.CheckUnarity();
     this.predicate = new RoleBetween(this.extent, role, firstValue, secondValue);
     this.extent.Invalidate();
     return this;
 }
Пример #7
0
 internal AllorsPredicateRoleInstanceofSql(AllorsExtentFilteredSql extent, IRoleType role, IObjectType instanceType, IClass[] instanceClasses)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleInstanceOf(role, instanceType);
     this.role = role;
     this.instanceClasses = instanceClasses;
 }
Пример #8
0
        internal void AddCompositeRole(Reference association, IRoleType roleType, HashSet<ObjectId> added)
        {
            if (this.addCompositeRoleRelationsByRoleType == null)
            {
                this.addCompositeRoleRelationsByRoleType = new Dictionary<IRoleType, List<CompositeRelation>>();
            }

            List<CompositeRelation> relations;
            if (!this.addCompositeRoleRelationsByRoleType.TryGetValue(roleType, out relations))
            {
                relations = new List<CompositeRelation>();
                this.addCompositeRoleRelationsByRoleType[roleType] = relations;
            }

            foreach (var roleObjectId in added)
            {
                relations.Add(new CompositeRelation(association.ObjectId, roleObjectId));
            }

            if (relations.Count > BatchSize)
            {
                this.session.AddCompositeRole(relations, roleType);
                relations.Clear();
            }
        }
Пример #9
0
 internal AllorsPredicateRoleGreaterThanValueSql(AllorsExtentFilteredSql extent, IRoleType roleType, Object obj)
 {
     extent.CheckRole(roleType);
     PredicateAssertions.ValidateRoleGreaterThan(roleType, obj);
     this.roleType = roleType;
     this.obj = roleType.ObjectType is IUnit ? roleType.Normalize(obj) : obj;
 }
Пример #10
0
 internal AllorsPredicateRoleLikeSql(AllorsExtentFilteredSql extent, IRoleType role, String str)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleLikeFilter(role, str);
     this.role = role;
     this.str = str;
 }
Пример #11
0
 internal AllorsPredicateRoleUnitEqualsRoleSql(AllorsExtentFilteredSql extent, IRoleType role, IRoleType equalsRole)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleEquals(role, equalsRole);
     this.role = role;
     this.equalsRole = equalsRole;
 }
Пример #12
0
 public AllorsPredicateRoleInExtentSql(AllorsExtentFilteredSql extent, IRoleType role, Allors.Extent inExtent)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleContainedIn(role, inExtent);
     this.role = role;
     this.inExtent = (AllorsExtentSql)inExtent;
 }
Пример #13
0
 internal RoleContains(ExtentFiltered extent, IRoleType role, IObject allorsObject)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleContains(role, allorsObject);
     this.role = role;
     this.allorsObject = allorsObject;
 }
Пример #14
0
 internal AllorsPredicateRoleCompositeEqualsSql(AllorsExtentFilteredSql extent, IRoleType role, Object obj)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleEquals(role, obj);
     this.role = role;
     this.obj = obj;
 }
Пример #15
0
 internal AllorsPredicateRoleGreaterThanSql(AllorsExtentFilteredSql extent, IRoleType role, IRoleType greaterThanRole)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleGreaterThan(role, greaterThanRole);
     this.role = role;
     this.greaterThanRole = greaterThanRole;
 }
Пример #16
0
 internal RoleContainedInExtent(ExtentFiltered extent, IRoleType role, Allors.Extent inExtent)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleContainedIn(role, inExtent);
     this.role = role;
     this.inExtent = ((Extent)inExtent).ContainedInExtent;
 }
Пример #17
0
 internal RoleEqualsRole(ExtentFiltered extent, IRoleType role, IRoleType equalsRole)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleEquals(role, equalsRole);
     this.role = role;
     this.equalsRole = equalsRole;
 }
Пример #18
0
        internal RoleExists(ExtentFiltered extent, IRoleType roleType)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleExists(roleType);

            this.roleType = roleType;
        }
Пример #19
0
 internal AllorsPredicateRoleBetweenValueSql(AllorsExtentFilteredSql extent, IRoleType roleType, Object first, Object second)
 {
     extent.CheckRole(roleType);
     PredicateAssertions.ValidateRoleBetween(roleType, first, second);
     this.roleType = roleType;
     this.first = roleType.ObjectType is IUnit ? roleType.Normalize(first) : first;
     this.second = roleType.ObjectType is IUnit ? roleType.Normalize(second) : second;
 }
Пример #20
0
        internal RoleContains(ExtentFiltered extent, IRoleType roleType, IObject containedObject)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleContains(roleType, containedObject);

            this.roleType = roleType;
            this.containedObject = containedObject;
        }
Пример #21
0
        internal RoleInstanceof(ExtentFiltered extent, IRoleType roleType, IComposite objectType)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleInstanceOf(roleType, objectType);

            this.roleType = roleType;
            this.objectType = objectType;
        }
Пример #22
0
        internal RoleOneContainedInExtent(ExtentFiltered extent, IRoleType roleType, Allors.Extent containingExtent)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleContainedIn(roleType, containingExtent);

            this.roleType = roleType;
            this.containingExtent = containingExtent;
        }
Пример #23
0
 internal RoleBetweenValue(ExtentFiltered extent, IRoleType roleType, object first, object second)
 {
     extent.CheckRole(roleType);
     PredicateAssertions.ValidateRoleBetween(roleType, first, second);
     this.roleType = roleType;
     this.first = roleType.Normalize(first);
     this.second = roleType.Normalize(second);
 }
Пример #24
0
 internal AllorsPredicateRoleBetweenRoleSql(AllorsExtentFilteredSql extent, IRoleType role, IRoleType first, IRoleType second)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleBetween(role, first, second);
     this.role = role;
     this.first = first;
     this.second = second;
 }
Пример #25
0
        internal RoleCompositeEqualsValue(ExtentFiltered extent, IRoleType roleType, object equals)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleEquals(roleType, equals);

            this.roleType = roleType;
            this.equals = equals;
        }
        internal RoleManyContainedInEnumerable(ExtentFiltered extent, IRoleType roleType, IEnumerable<IObject> containingEnumerable)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleContainedIn(roleType, containingEnumerable);

            this.roleType = roleType;
            this.containingEnumerable = containingEnumerable;
        }
Пример #27
0
        internal RoleLike(ExtentFiltered extent, IRoleType roleType, string like)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleLikeFilter(roleType, like);

            this.roleType = roleType;
            this.isEmpty = like.Length == 0;
            this.regex = new Regex("^" + like.Replace("%", ".*") + "$");
        }
Пример #28
0
        internal RoleLessThan(ExtentFiltered extent, IRoleType roleType, object compare)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleLessThan(roleType, compare);

            this.extent = extent;
            this.roleType = roleType;
            this.compare = compare;
        }
Пример #29
0
 internal void AddSort(IRoleType sortRoleType, SortDirection sortDirection)
 {
     if (this.subSorter == null)
     {
         this.subSorter = new AllorsExtentSortSql(this.session, sortRoleType, sortDirection);
     }
     else
     {
         this.subSorter.AddSort(sortRoleType, sortDirection);
     }
 }
Пример #30
0
 internal void AddSort(IRoleType subSortIRoleType, SortDirection subSortDirection)
 {
     if (this.subSorter == null)
     {
         this.subSorter = new ExtentSort(this.session, subSortIRoleType, subSortDirection);
     }
     else
     {
         this.subSorter.AddSort(subSortIRoleType, subSortDirection);
     }
 }
Пример #31
0
        internal IObject ExtentGetItem(IRoleType roleType, int index)
        {
            var i = 0;

            foreach (var oid in this.Roles.GetCompositesRole(roleType))
            {
                if (i == index)
                {
                    return(this.Session.State.GetOrCreateReferenceForExistingObject(oid, this.Session).Strategy.GetObject());
                }

                ++i;
            }

            return(null);
        }
Пример #32
0
        internal void OnChangingCompositeRole(Roles association, IRoleType roleType, long? previousRole, long? newRole)
        {
            this.associations.Add(association.Reference.ObjectId);

            if (previousRole != null)
            {
                this.roles.Add(previousRole.Value);
            }

            if (newRole != null)
            {
                this.roles.Add(newRole.Value);
            }

            this.RoleTypes(association.Reference.ObjectId).Add(roleType);
        }
Пример #33
0
        public bool ExistCompositeRoles(IRoleType roleType)
        {
            this.AssertNotDeleted();

            switch (roleType.RelationType.Multiplicity)
            {
            case Multiplicity.OneToMany:
                return(this.session.ExistCompositeRoleOneToMany(this.objectId, roleType));

            case Multiplicity.ManyToMany:
                return(this.session.ExistCompositeRoleManyToMany(this.objectId, roleType));

            default:
                throw new Exception("Unsupported multiplicity " + roleType.RelationType.Multiplicity);
            }
        }
Пример #34
0
        internal int ExtentIndexOf(IRoleType roleType, IObject value)
        {
            var i = 0;

            foreach (var oid in this.Roles.GetCompositesRole(roleType))
            {
                if (oid.Equals(value.Id))
                {
                    return(i);
                }

                ++i;
            }

            return(-1);
        }
Пример #35
0
        private void AddCompositeRoleOne2Many(IRoleType roleType, Strategy newRoleStrategy)
        {
            this.compositesRoleByRoleType.TryGetValue(roleType, out var previousRoleStrategies);
            if (previousRoleStrategies != null && previousRoleStrategies.Contains(newRoleStrategy))
            {
                return;
            }

            this.ChangeSet.OnChangingCompositesRole(this.ObjectId, roleType, newRoleStrategy);

            // 1-...
            newRoleStrategy.compositeAssociationByAssociationType.TryGetValue(roleType.AssociationType, out var newRolePreviousAssociationStrategy);
            if (newRolePreviousAssociationStrategy != null)
            {
                this.ChangeSet.OnChangingCompositesRole(newRolePreviousAssociationStrategy.ObjectId, roleType, null);

                // Remove obsolete role
                newRolePreviousAssociationStrategy.Backup(roleType);
                newRolePreviousAssociationStrategy.compositesRoleByRoleType.TryGetValue(roleType, out var newRolePreviousAssociationStrategyRoleStrategies);
                if (newRolePreviousAssociationStrategyRoleStrategies == null)
                {
                    newRolePreviousAssociationStrategyRoleStrategies = new HashSet <Strategy>();
                    newRolePreviousAssociationStrategy.compositesRoleByRoleType[roleType] = newRolePreviousAssociationStrategyRoleStrategies;
                }

                newRolePreviousAssociationStrategyRoleStrategies.Remove(newRoleStrategy);
                if (newRolePreviousAssociationStrategyRoleStrategies.Count == 0)
                {
                    newRolePreviousAssociationStrategy.compositesRoleByRoleType.Remove(roleType);
                }
            }

            // Add the new role
            this.Backup(roleType);
            this.compositesRoleByRoleType.TryGetValue(roleType, out var roleStrategies);
            if (roleStrategies == null)
            {
                roleStrategies = new HashSet <Strategy>();
                this.compositesRoleByRoleType[roleType] = roleStrategies;
            }

            roleStrategies.Add(newRoleStrategy);

            // Set new association
            newRoleStrategy.Backup(roleType.AssociationType);
            newRoleStrategy.compositeAssociationByAssociationType[roleType.AssociationType] = this;
        }
Пример #36
0
        /// <summary>
        /// Asserts that the <see cref="RoleType"/> and the unit are compatible with
        /// <see cref="ICompositePredicate#AddLessThan"/>.
        /// </summary>
        /// <param name="role">The role .</param>
        /// <param name="unit">The unit .</param>
        public static void ValidateRoleLessThan(IRoleType role, object unit)
        {
            if (role.ObjectType is IComposite)
            {
                throw new ArgumentException("AddLessThan() can only be used with unit types.");
            }

            if (unit == null)
            {
                throw new ArgumentException("AddLessThan() requires a value.");
            }

            if (unit is IRoleType compareRole && compareRole.ObjectType is IComposite)
            {
                throw new ArgumentException("AddLessThan() can only be used with roles having unit types.");
            }
        }
Пример #37
0
        internal void SetCompositeRoleMany2One(IRoleType roleType, IObject newRole)
        {
            this.AssertNotDeleted();
            this.session.MemoryDatabase.CompositeRoleChecks(this, roleType, newRole);

            var previousRole = this.GetCompositeRole(roleType.RelationType);

            this.ChangeSet.OnChangingCompositeRole(this.ObjectId, roleType, previousRole?.Id, newRole?.Id);

            if (!newRole.Equals(previousRole))
            {
                var associationType = roleType.AssociationType;

                // Update association of previous role
                if (previousRole != null)
                {
                    var previousRoleStrategy = this.session.GetStrategy(previousRole);
                    HashSet <Strategy> previousRoleStrategies;
                    previousRoleStrategy.compositesAssociationByAssociationType.TryGetValue(associationType, out previousRoleStrategies);

                    previousRoleStrategy.Backup(associationType);
                    previousRoleStrategies.Remove(this);
                    if (previousRoleStrategies.Count == 0)
                    {
                        previousRoleStrategy.compositesAssociationByAssociationType.Remove(associationType);
                    }
                }

                var newRoleStrategy = this.session.GetStrategy(newRole);

                this.Backup(roleType);
                this.compositeRoleByRoleType[roleType] = newRoleStrategy;

                HashSet <Strategy> strategies;
                newRoleStrategy.compositesAssociationByAssociationType.TryGetValue(associationType, out strategies);

                newRoleStrategy.Backup(associationType);
                if (strategies == null)
                {
                    strategies = new HashSet <Strategy>();
                    newRoleStrategy.compositesAssociationByAssociationType[associationType] = strategies;
                }

                strategies.Add(this);
            }
        }
Пример #38
0
        internal void SetCompositeRolesMany2Many(IRoleType roleType, HashSet <Strategy> roles)
        {
            this.AssertNotDeleted();

            var originalRoles = this.GetStrategies(roleType);

            if (!roles.SetEquals(originalRoles))
            {
                this.RemoveCompositeRolesMany2Many(roleType);

                // TODO: Optimize this
                foreach (var strategy in roles)
                {
                    this.AddCompositeRoleMany2Many(roleType, strategy);
                }
            }
        }
Пример #39
0
        internal void SetCompositeRoleOne2One(IRoleType roleType, IObject newRole)
        {
            this.AssertNotDeleted();
            this.MemorySession.MemoryDatabase.CompositeRoleChecks(this, roleType, newRole);

            var previousRole = this.GetCompositeRole(roleType.RelationType);

            if (!newRole.Equals(previousRole))
            {
                this.ChangeSet.OnChangingCompositeRole(this.ObjectId, roleType, previousRole?.Id, newRole?.Id);

                var newRoleStrategy = this.MemorySession.GetStrategy(newRole);

                if (previousRole != null)
                {
                    // previous role
                    var previousRoleStrategy = this.MemorySession.GetStrategy(previousRole);
                    var associationType      = roleType.AssociationType;
                    previousRoleStrategy.Backup(associationType);
                    previousRoleStrategy.compositeAssociationByAssociationType.Remove(associationType);
                }

                // previous association of newRole
                var newRolePreviousAssociation = newRoleStrategy.GetCompositeAssociation(roleType.RelationType);
                if (newRolePreviousAssociation != null)
                {
                    var newRolePreviousAssociationStrategy = this.MemorySession.GetStrategy(newRolePreviousAssociation);
                    if (!this.Equals(newRolePreviousAssociationStrategy))
                    {
                        this.ChangeSet.OnChangingCompositeRole(newRolePreviousAssociationStrategy.ObjectId, roleType, previousRole?.Id, null);

                        newRolePreviousAssociationStrategy.Backup(roleType);
                        newRolePreviousAssociationStrategy.compositeRoleByRoleType.Remove(roleType);
                    }
                }

                // Set new role
                this.Backup(roleType);
                this.compositeRoleByRoleType[roleType] = newRoleStrategy;

                // Set new role's association
                var associationType1 = roleType.AssociationType;
                newRoleStrategy.Backup(associationType1);
                newRoleStrategy.compositeAssociationByAssociationType[associationType1] = this;
            }
        }
Пример #40
0
        public bool TryGetComposites(long association, object cacheId, IRoleType roleType, out long[] role)
        {
            if (this.cachedCompositesRoleByAssociationByRoleType.TryGetValue(roleType, out var entryByAssociation))
            {
                if (entryByAssociation.TryGetValue(association, out var cachedCompositesRole))
                {
                    if (cachedCompositesRole.CacheId.Equals(cacheId))
                    {
                        role = cachedCompositesRole.Role;
                        return(true);
                    }
                }
            }

            role = null;
            return(false);
        }
Пример #41
0
        private long[] GetNonModifiedCompositeRoles(IRoleType roleType)
        {
            if (!this.Reference.IsNew)
            {
                if (this.CachedObject != null && this.CachedObject.TryGetValue(roleType, out var roleOut))
                {
                    return((long[])roleOut);
                }

                this.Reference.Session.Commands.GetCompositesRole(this, roleType);
                this.cachedObject.TryGetValue(roleType, out roleOut);
                var role = (long[])roleOut;
                return(role);
            }

            return(Database.EmptyObjectIds);
        }
Пример #42
0
        internal IObject ExtentFirst(Session session, IRoleType roleType)
        {
            if (this.ModifiedRolesByRoleType != null && this.ModifiedRolesByRoleType.TryGetValue(roleType, out var compositesRole))
            {
                var objectId = compositesRole.First;
                return(objectId == null ? null : session.State.GetOrCreateReferenceForExistingObject(objectId.Value, session).Strategy.GetObject());
            }

            var nonModifiedCompositeRoles = this.GetNonModifiedCompositeRoles(roleType);

            if (nonModifiedCompositeRoles.Length > 0)
            {
                return(session.State.GetOrCreateReferenceForExistingObject(nonModifiedCompositeRoles[0], session).Strategy.GetObject());
            }

            return(null);
        }
Пример #43
0
        public static void RoleExistHasException(IObject allorsObject, IRoleType roleType)
        {
            var exceptionOccured = false;

            try
            {
                object o = allorsObject.Strategy.ExistRole(roleType.RelationType);
            }
            catch
            {
                exceptionOccured = true;
            }

            if (!exceptionOccured)
            {
                Assert.True(false, "Exist didn't threw an Exception for role " + roleType);
            }
        }
Пример #44
0
        public static void RoleGetHasException(IObject allorsObject, IRoleType roleType)
        {
            var exceptionOccured = false;

            try
            {
                var o = allorsObject.Strategy.GetRole(roleType.RelationType);
            }
            catch
            {
                exceptionOccured = true;
            }

            if (!exceptionOccured)
            {
                Assert.True(false); // Fail
            }
        }
Пример #45
0
 public virtual void RemoveRole(IRoleType roleType)
 {
     if (roleType.ObjectType is IUnit)
     {
         this.RemoveUnitRole(roleType);
     }
     else
     {
         if (roleType.IsMany)
         {
             this.RemoveCompositeRoles(roleType);
         }
         else
         {
             this.RemoveCompositeRole(roleType);
         }
     }
 }
Пример #46
0
        internal RoleUnitEquals(ExtentFiltered extent, IRoleType roleType, object equals)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleEquals(roleType, equals);

            this.extent   = extent;
            this.roleType = roleType;
            if (equals is Enum)
            {
                if (roleType.ObjectType is IUnit unitType && unitType.IsInteger)
                {
                    this.equals = (int)equals;
                }
                else
                {
                    throw new Exception("Role Object Type " + roleType.ObjectType.SingularName + " doesn't support enumerations.");
                }
            }
Пример #47
0
        internal void OnChangingCompositeRole(long association, IRoleType roleType, long?previousRole, long?newRole)
        {
            this.associations.Add(association);

            if (previousRole != null)
            {
                this.roles.Add(previousRole.Value);
                this.AssociationTypes(previousRole.Value).Add(roleType.AssociationType);
            }

            if (newRole != null)
            {
                this.roles.Add(newRole.Value);
                this.AssociationTypes(newRole.Value).Add(roleType.AssociationType);
            }

            this.RoleTypes(association).Add(roleType);
        }
Пример #48
0
        public string GetSql(IObjectType objectType, IRoleType roleType)
        {
            Dictionary <IRoleType, string> sqlByRoleType;

            if (!this.sqlByRoleTypeByObjectType.TryGetValue(objectType, out sqlByRoleType))
            {
                sqlByRoleType = new Dictionary <IRoleType, string>();
                this.sqlByRoleTypeByObjectType.Add(objectType, sqlByRoleType);
            }

            if (!sqlByRoleType.ContainsKey(roleType))
            {
                var sql = Schema.AllorsPrefix + "SR_" + objectType.SingularName + "_" + roleType.SingularPropertyName;
                sqlByRoleType[roleType] = sql;
            }

            return(sqlByRoleType[roleType]);
        }
Пример #49
0
        internal void RemoveCompositeRole(List <CompositeRelation> relations, IRoleType roleType)
        {
            if (!this.RemoveCompositeRoleByRoleType.TryGetValue(roleType, out var command))
            {
                var sql = this.Database.Mapping.ProcedureNameForRemoveRoleByRelationType[roleType.RelationType];
                command             = this.connection.CreateCommand();
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;
                command.AddCompositeRoleTableParameter(relations);
                this.removeCompositeRoleByRoleType[roleType] = command;
            }
            else
            {
                command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateCompositeRelationTable(relations);
            }

            command.ExecuteNonQuery();
        }
Пример #50
0
        public static void RoleGetHasException(IObject allorsObject, IRoleType roleType)
        {
            bool exceptionOccured = false;

            try
            {
                object o = allorsObject.Strategy.GetRole(roleType.RelationType);
            }
            catch
            {
                exceptionOccured = true;
            }

            if (!exceptionOccured)
            {
                Assert.Fail();
            }
        }
Пример #51
0
        /// <summary>
        /// Asserts that the <see cref="RoleType"/> and the object are compatible with
        /// <see cref="ICompositePredicate#AddEquals"/>.
        /// </summary>
        /// <param name="role">The role .</param>
        /// <param name="compareObject">The compare object.</param>
        public static void ValidateRoleEquals(IRoleType role, object compareObject)
        {
            if (role.IsMany)
            {
                throw new ArgumentException("AddRoleEqual() can only be used when the role has multiplicity one.");
            }

            if (compareObject == null)
            {
                throw new ArgumentException(
                          "AddEquals() requires a non-null value or object, use AddNot().AddExists() instead.");
            }

            if (compareObject is IRoleType compareRole && compareRole.ObjectType is IComposite)
            {
                throw new ArgumentException("AddRoleEqual() for composites can only be used with objects (not other roles).");
            }
        }
Пример #52
0
        public object GetUnitRole(IRoleType roleType)
        {
            object role = null;

            if (this.modifiedRoleByRoleType == null || !this.modifiedRoleByRoleType.TryGetValue(roleType, out role))
            {
                if (this.CachedObject == null || !this.CachedObject.TryGetValue(roleType, out role))
                {
                    if (!this.Reference.IsNew)
                    {
                        this.Reference.Session.SessionCommands.GetUnitRolesCommand.Execute(this);
                        this.cachedObject.TryGetValue(roleType, out role);
                    }
                }
            }

            return(role);
        }
Пример #53
0
        public virtual long?GetCompositeRole(IRoleType roleType)
        {
            object role = null;

            if (this.modifiedRoleByRoleType == null || !this.modifiedRoleByRoleType.TryGetValue(roleType, out role))
            {
                if (this.CachedObject == null || !this.CachedObject.TryGetValue(roleType, out role))
                {
                    if (!this.Reference.IsNew)
                    {
                        this.Reference.Session.SessionCommands.GetCompositeRoleCommand.Execute(this, roleType);
                        this.cachedObject.TryGetValue(roleType, out role);
                    }
                }
            }

            return((long?)role);
        }
Пример #54
0
        // TODO: inline
        internal SqlMetaData GetSqlMetaData(string name, IRoleType roleType)
        {
            var unit = (IUnit)roleType.ObjectType;

            switch (unit.UnitTag)
            {
            case UnitTags.String:
                if (roleType.Size == -1 || roleType.Size > 4000)
                {
                    return(new SqlMetaData(name, SqlDbType.NVarChar, -1));
                }

                return(new SqlMetaData(name, SqlDbType.NVarChar, roleType.Size.Value));

            case UnitTags.Integer:
                return(new SqlMetaData(name, SqlDbType.Int));

            case UnitTags.Decimal:
                return(new SqlMetaData(name, SqlDbType.Decimal, (byte)roleType.Precision.Value, (byte)roleType.Scale.Value));

            case UnitTags.Float:
                return(new SqlMetaData(name, SqlDbType.Float));

            case UnitTags.Boolean:
                return(new SqlMetaData(name, SqlDbType.Bit));

            case UnitTags.DateTime:
                return(new SqlMetaData(name, SqlDbType.DateTime2));

            case UnitTags.Unique:
                return(new SqlMetaData(name, SqlDbType.UniqueIdentifier));

            case UnitTags.Binary:
                if (roleType.Size == -1 || roleType.Size > 8000)
                {
                    return(new SqlMetaData(name, SqlDbType.VarBinary, -1));
                }

                return(new SqlMetaData(name, SqlDbType.VarBinary, (long)roleType.Size));

            default:
                throw new Exception("!UNKNOWN VALUE TYPE!");
            }
        }
Пример #55
0
        internal void GetCompositesRole(Roles roles, IRoleType roleType)
        {
            var reference = roles.Reference;

            Command command;

            if (!this.GetCompositesRoleByRoleType.TryGetValue(roleType, out command))
            {
                var associationType = roleType.AssociationType;

                string sql;
                if (associationType.IsMany || !roleType.RelationType.ExistExclusiveClasses)
                {
                    sql = this.Database.Mapping.ProcedureNameForGetRoleByRelationType[roleType.RelationType];
                }
                else
                {
                    sql = this.Database.Mapping.ProcedureNameForGetRoleByRelationType[roleType.RelationType];
                }

                command             = this.connection.CreateCommand();
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;
                command.AddAssociationParameter(reference.ObjectId);
                this.getCompositesRoleByRoleType[roleType] = command;
            }
            else
            {
                command.Parameters[Mapping.ParamNameForAssociation].Value = reference.ObjectId;
            }

            var objectIds = new List <long>();

            using (DbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var id = this.Session.State.GetObjectIdForExistingObject(reader[0].ToString());
                    objectIds.Add(id);
                }
            }

            roles.CachedObject.SetValue(roleType, objectIds.ToArray());
        }
Пример #56
0
        /// <summary>
        /// Asserts that the <see cref="RoleType"/> and the unit are compatible with
        /// <see cref="ICompositePredicate#AddGreaterThan"/>.
        /// </summary>
        /// <param name="role">The role .</param>
        /// <param name="unit">The unit .</param>
        public static void ValidateRoleGreaterThan(IRoleType role, object unit)
        {
            if (role.ObjectType is IComposite)
            {
                throw new ArgumentException("AddGreaterThan() can only be used with unit types.");
            }

            if (unit == null)
            {
                throw new ArgumentException("AddGreaterThan() requires a non-null value.");
            }

            var compareRole = unit as IRoleType;

            if (compareRole != null && compareRole.ObjectType is IComposite)
            {
                throw new ArgumentException("AAddGreaterThan() can only be used with roles having unit types.");
            }
        }
Пример #57
0
        public void RemoveCompositeRoles(IRoleType roleType)
        {
            this.AssertNotDeleted();
            RoleAssertions.CompositeRolesChecks(this, roleType);

            switch (roleType.RelationType.Multiplicity)
            {
            case Multiplicity.OneToMany:
                this.session.RemoveCompositeRolesOneToMany(this.objectId, roleType);
                return;

            case Multiplicity.ManyToMany:
                this.session.RemoveCompositeRolesManyToMany(this.objectId, roleType);
                return;

            default:
                throw new Exception("Unsupported multiplicity " + roleType.RelationType.Multiplicity);
            }
        }
Пример #58
0
        public ObjectId[] ExtentGetCompositeRoles(IRoleType roleType)
        {
            ObjectId[] roles;
            switch (roleType.RelationType.Multiplicity)
            {
            case Multiplicity.OneToMany:
                roles = this.session.GetCompositeRolesOneToMany(this.objectId, roleType);
                break;

            case Multiplicity.ManyToMany:
                roles = this.session.GetCompositeRolesManyToMany(this.objectId, roleType);
                break;

            default:
                throw new Exception("Unsupported multiplicity " + roleType.RelationType.Multiplicity);
            }

            return(roles);
        }
Пример #59
0
        public IObject ExtentFirst(DatabaseSession session, IRoleType roleType)
        {
            CompositeRoles compositeRoles;

            if (this.ModifiedRolesByRoleType != null && this.ModifiedRolesByRoleType.TryGetValue(roleType, out compositeRoles))
            {
                var objectId = compositeRoles.First;
                return(objectId == null ? null : session.GetOrCreateAssociationForExistingObject(objectId.Value).Strategy.GetObject());
            }

            var nonModifiedCompositeRoles = this.GetNonModifiedCompositeRoles(roleType);

            if (nonModifiedCompositeRoles.Length > 0)
            {
                return(session.GetOrCreateAssociationForExistingObject(nonModifiedCompositeRoles[0]).Strategy.GetObject());
            }

            return(null);
        }
Пример #60
0
        internal void ClearCompositeAndCompositesRole(IList <long> associations, IRoleType roleType)
        {
            var sql = this.Database.Mapping.ProcedureNameForClearRoleByRelationType[roleType.RelationType];

            if (!this.ClearCompositeAndCompositesRoleByRoleType.TryGetValue(roleType, out var command))
            {
                command             = this.connection.CreateCommand();
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;
                command.AddObjectTableParameter(associations);
                this.clearCompositeAndCompositesRoleByRoleType[roleType] = command;
            }
            else
            {
                command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateObjectTable(associations);
            }

            command.ExecuteNonQuery();
        }