コード例 #1
0
ファイル: ExtentFiltered.cs プロジェクト: whesius/allors
 internal void CheckForRoleType(IRoleType roleType)
 {
     if (!this.objectType.ExistRoleType(roleType))
     {
         throw new ArgumentException("Extent does not have role " + roleType.SingularName);
     }
 }
コード例 #2
0
ファイル: RoleLessThanRole.cs プロジェクト: whesius/allors
 internal RoleLessThanRole(ExtentFiltered extent, IRoleType role, IRoleType lessThanRole)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleLessThan(role, lessThanRole);
     this.role = role;
     this.lessThanRole = lessThanRole;
 }
コード例 #3
0
ファイル: RoleLike.cs プロジェクト: whesius/allors
 internal RoleLike(ExtentFiltered extent, IRoleType role, string like)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleLikeFilter(role, like);
     this.role = role;
     this.like = like;
 }
コード例 #4
0
ファイル: RoleLessThanValue.cs プロジェクト: whesius/allors
 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
ファイル: Not.cs プロジェクト: whesius/allors
 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
ファイル: RoleInstanceOf.cs プロジェクト: whesius/allors
 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
ファイル: Flush.cs プロジェクト: whesius/allors
        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
ファイル: RoleLike.cs プロジェクト: whesius/allors
 internal AllorsPredicateRoleLikeSql(AllorsExtentFilteredSql extent, IRoleType role, String str)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleLikeFilter(role, str);
     this.role = role;
     this.str = str;
 }
コード例 #11
0
ファイル: RoleUnitEqualsRole.cs プロジェクト: whesius/allors
 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
ファイル: RoleContains.cs プロジェクト: whesius/allors
 internal RoleContains(ExtentFiltered extent, IRoleType role, IObject allorsObject)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleContains(role, allorsObject);
     this.role = role;
     this.allorsObject = allorsObject;
 }
コード例 #14
0
ファイル: RoleCompositeEquals.cs プロジェクト: whesius/allors
 internal AllorsPredicateRoleCompositeEqualsSql(AllorsExtentFilteredSql extent, IRoleType role, Object obj)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleEquals(role, obj);
     this.role = role;
     this.obj = obj;
 }
コード例 #15
0
ファイル: RoleGreaterThanRole.cs プロジェクト: whesius/allors
 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
ファイル: RoleEqualsRole.cs プロジェクト: whesius/allors
 internal RoleEqualsRole(ExtentFiltered extent, IRoleType role, IRoleType equalsRole)
 {
     extent.CheckRole(role);
     PredicateAssertions.ValidateRoleEquals(role, equalsRole);
     this.role = role;
     this.equalsRole = equalsRole;
 }
コード例 #18
0
ファイル: RoleExists.cs プロジェクト: whesius/allors
        internal RoleExists(ExtentFiltered extent, IRoleType roleType)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleExists(roleType);

            this.roleType = roleType;
        }
コード例 #19
0
ファイル: RoleBetweenValue.cs プロジェクト: whesius/allors
 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
ファイル: RoleContains.cs プロジェクト: whesius/allors
        internal RoleContains(ExtentFiltered extent, IRoleType roleType, IObject containedObject)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleContains(roleType, containedObject);

            this.roleType = roleType;
            this.containedObject = containedObject;
        }
コード例 #21
0
ファイル: RoleInstanceOf.cs プロジェクト: whesius/allors
        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
ファイル: RoleBetweenValue.cs プロジェクト: whesius/allors
 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
ファイル: RoleBetweenRole.cs プロジェクト: whesius/allors
 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
ファイル: RoleCompositeEquals.cs プロジェクト: whesius/allors
        internal RoleCompositeEqualsValue(ExtentFiltered extent, IRoleType roleType, object equals)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleEquals(roleType, equals);

            this.roleType = roleType;
            this.equals = equals;
        }
コード例 #26
0
        internal RoleManyContainedInEnumerable(ExtentFiltered extent, IRoleType roleType, IEnumerable<IObject> containingEnumerable)
        {
            extent.CheckForRoleType(roleType);
            PredicateAssertions.ValidateRoleContainedIn(roleType, containingEnumerable);

            this.roleType = roleType;
            this.containingEnumerable = containingEnumerable;
        }
コード例 #27
0
ファイル: RoleLike.cs プロジェクト: whesius/allors
        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
ファイル: RoleLessThan.cs プロジェクト: whesius/allors
        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
ファイル: ExtentSort.cs プロジェクト: whesius/allors
 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
ファイル: ExtentSort.cs プロジェクト: whesius/allors
 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
ファイル: Strategy.cs プロジェクト: Zonsoft-be/ExcelShowcase
        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
ファイル: Strategy.cs プロジェクト: lulzzz/allors2
        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
ファイル: Strategy.cs プロジェクト: Zonsoft-be/ExcelShowcase
        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
ファイル: Strategy.cs プロジェクト: Zonsoft-be/ExcelShowcase
        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
ファイル: Roles.cs プロジェクト: lulzzz/allors2
        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
ファイル: Roles.cs プロジェクト: lulzzz/allors2
        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
ファイル: Commands.cs プロジェクト: lulzzz/allors2
        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
ファイル: Commands.cs プロジェクト: lulzzz/allors2
        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();
        }