Beispiel #1
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();
            }
        }
Beispiel #2
0
        internal void ClearCompositeAndCompositesRole(Reference association, IRoleType roleType)
        {
            if (this.clearCompositeAndCompositesRoleRelationsByRoleType == null)
            {
                this.clearCompositeAndCompositesRoleRelationsByRoleType = new Dictionary<IRoleType, IList<ObjectId>>();
            }

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

            relations.Add(association.ObjectId);

            if (relations.Count > BatchSize)
            {
                this.session.ClearCompositeAndCompositesRole(relations, roleType);
                relations.Clear();
            }
        }
Beispiel #3
0
        internal void SetCompositeRole(Reference association, IRoleType roleType, ObjectId role)
        {
            if (this.setCompositeRoleRelationsByRoleType == null)
            {
                this.setCompositeRoleRelationsByRoleType = new Dictionary<IRoleType, List<CompositeRelation>>();
            }

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

            relations.Add(new CompositeRelation(association.ObjectId, role));

            if (relations.Count > BatchSize)
            {
                this.session.SetCompositeRole(relations, roleType);
                relations.Clear();
            }
        }
Beispiel #4
0
        internal void SetUnitRole(Reference association, IRoleType roleType, object role)
        {
            if (this.setUnitRoleRelationsByRoleTypeByExclusiveClass == null)
            {
                this.setUnitRoleRelationsByRoleTypeByExclusiveClass = new Dictionary<IClass, Dictionary<IRoleType, List<UnitRelation>>>();
            }

            var exclusiveClass = association.Class.ExclusiveClass;

            Dictionary<IRoleType, List<UnitRelation>> setUnitRoleRelationsByRoleType;
            if (!this.setUnitRoleRelationsByRoleTypeByExclusiveClass.TryGetValue(exclusiveClass, out setUnitRoleRelationsByRoleType))
            {
                setUnitRoleRelationsByRoleType = new Dictionary<IRoleType, List<UnitRelation>>();
                this.setUnitRoleRelationsByRoleTypeByExclusiveClass[exclusiveClass] = setUnitRoleRelationsByRoleType;
            }

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

            var unitRelation = new UnitRelation(association.ObjectId, role);
            relations.Add(unitRelation);

            if (relations.Count > BatchSize)
            {
                this.session.SetUnitRole(relations, exclusiveClass, roleType);
                relations.Clear();
            }
        }
Beispiel #5
0
        internal void PrefetchCompositeAssociationRelationTable(HashSet <Reference> roles, IAssociationType associationType, HashSet <long> nestedObjectIds, HashSet <long> leafs)
        {
            var references = nestedObjectIds == null?this.FilterForPrefetchAssociations(roles, associationType) : this.FilterForPrefetchCompositesAssociations(roles, associationType, nestedObjectIds);

            if (references.Count == 0)
            {
                return;
            }

            if (!this.PrefetchCompositeAssociationByAssociationType.TryGetValue(associationType, out var command))
            {
                var roleType = associationType.RoleType;
                var sql      = this.Database.Mapping.ProcedureNameForPrefetchAssociationByRelationType[roleType.RelationType];
                command             = this.Session.Connection.CreateCommand();
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;
                command.AddObjectTableParameter(roles);
                this.prefetchCompositeAssociationByAssociationType[associationType] = command;
            }
            else
            {
                command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateObjectTable(roles);
            }

            var prefetchedAssociationByRole = new Dictionary <Reference, long>();

            using (DbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var roleId        = reader.GetInt64(1);
                    var roleReference = this.Session.State.ReferenceByObjectId[roleId];
                    var associationId = reader.GetInt64(0);
                    prefetchedAssociationByRole.Add(roleReference, associationId);
                }
            }

            var associationByRole = this.Session.State.GetAssociationByRole(associationType);

            foreach (var role in roles)
            {
                if (!associationByRole.ContainsKey(role))
                {
                    Reference association = null;

                    if (prefetchedAssociationByRole.TryGetValue(role, out var associationId))
                    {
                        association = associationType.ObjectType.ExistExclusiveClass ?
                                      this.Session.State.GetOrCreateReferenceForExistingObject(associationType.ObjectType.ExclusiveClass, associationId, this.Session) :
                                      this.Session.State.GetOrCreateReferenceForExistingObject(associationId, this.Session);

                        nestedObjectIds?.Add(associationId);
                        if (nestedObjectIds == null)
                        {
                            leafs.Add(associationId);
                        }
                    }

                    associationByRole[role] = association;

                    this.Session.FlushConditionally(role.ObjectId, associationType);
                }
            }
        }