internal void Flush(Flush flush, Roles roles, IRoleType roleType) { if (this.Count == 0) { flush.ClearCompositeAndCompositesRole(roles.Reference, roleType); } else { if (this.added != null && this.added.Count > 0) { flush.AddCompositeRole(roles.Reference, roleType, this.added); } if (this.removed != null && this.removed.Count > 0) { flush.RemoveCompositeRole(roles.Reference, roleType, this.removed); } } if (this.added != null) { this.baseline.UnionWith(this.added); } if (this.removed != null) { this.baseline.ExceptWith(this.removed); } this.added = null; this.removed = null; }
internal void OnChangingCompositesRole(Roles association, IRoleType roleType, Strategy changedRole) { this.associations.Add(association.Reference.ObjectId); if (changedRole != null) { this.roles.Add(changedRole.ObjectId); } this.RoleTypes(association.Reference.ObjectId).Add(roleType); }
internal void OnChangingUnitRole(Roles association, IRoleType roleType) { this.associations.Add(association.Reference.ObjectId); this.RoleTypes(association.Reference.ObjectId).Add(roleType); }
internal void OnChangingCompositeRole(Roles association, IRoleType roleType, ObjectId previousRole, ObjectId newRole) { this.associations.Add(association.Reference.ObjectId); if (previousRole != null) { this.roles.Add(previousRole); } if (newRole != null) { this.roles.Add(newRole); } this.RoleTypes(association.Reference.ObjectId).Add(roleType); }
internal virtual void Release() { this.roles = null; }
internal void PrefetchCompositesRoleRelationTable(HashSet <Reference> associations, IRoleType roleType, HashSet <long> nestedObjectIds, HashSet <long> leafs) { var references = nestedObjectIds == null?this.FilterForPrefetchRoles(associations, roleType) : this.FilterForPrefetchCompositesRoles(associations, roleType, nestedObjectIds); if (references.Count == 0) { return; } if (!this.PrefetchCompositesRoleByRoleType.TryGetValue(roleType, out var command)) { var sql = this.Database.Mapping.ProcedureNameForPrefetchRoleByRelationType[roleType.RelationType]; command = this.Session.Connection.CreateCommand(); command.CommandText = sql; command.CommandType = CommandType.StoredProcedure; command.AddObjectTableParameter(references); this.prefetchCompositesRoleByRoleType[roleType] = command; } else { command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateObjectTable(references); } var rolesByAssociation = new Dictionary <Reference, List <long> >(); using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var associationId = reader.GetInt64(0); var associationReference = this.Session.State.ReferenceByObjectId[associationId]; var roleId = reader.GetInt64(1); if (!rolesByAssociation.TryGetValue(associationReference, out var roleIds)) { roleIds = new List <long>(); rolesByAssociation[associationReference] = roleIds; } roleIds.Add(roleId); } } var cache = this.Database.Cache; foreach (var reference in references) { Roles modifiedRoles = null; this.Session.State.ModifiedRolesByReference?.TryGetValue(reference, out modifiedRoles); if (modifiedRoles == null || !modifiedRoles.ModifiedRoleByRoleType.ContainsKey(roleType)) { var cachedObject = cache.GetOrCreateCachedObject(reference.Class, reference.ObjectId, reference.Version); if (rolesByAssociation.TryGetValue(reference, out var roleIds)) { cachedObject.SetValue(roleType, roleIds.ToArray()); nestedObjectIds?.UnionWith(roleIds); if (nestedObjectIds == null) { leafs.UnionWith(roleIds); } } else { cachedObject.SetValue(roleType, EmptyObjectIds); } } } }
internal void PrefetchUnitRoles(IClass @class, HashSet <Reference> associations, IRoleType anyRoleType) { var references = this.FilterForPrefetchRoles(associations, anyRoleType); if (references.Count == 0) { return; } if (!this.PrefetchUnitRolesByClass.TryGetValue(@class, out var command)) { if (!this.Database.Mapping.ProcedureNameForPrefetchUnitRolesByClass.ContainsKey(@class)) { Console.WriteLine(0); } var sql = this.Database.Mapping.ProcedureNameForPrefetchUnitRolesByClass[@class]; command = this.Session.Connection.CreateCommand(); command.CommandText = sql; command.CommandType = CommandType.StoredProcedure; command.AddObjectTableParameter(references); this.prefetchUnitRolesByClass[@class] = command; } else { command.Parameters[Mapping.ParamNameForTableType].Value = this.Database.CreateObjectTable(references); } using (DbDataReader reader = command.ExecuteReader()) { var sortedUnitRoles = this.Database.GetSortedUnitRolesByObjectType(@class); var cache = this.Database.Cache; while (reader.Read()) { var associatoinId = reader.GetInt64(0); var associationReference = this.Session.State.ReferenceByObjectId[associatoinId]; Roles modifiedRoles = null; this.Session.State.ModifiedRolesByReference?.TryGetValue(associationReference, out modifiedRoles); var cachedObject = cache.GetOrCreateCachedObject(@class, associatoinId, associationReference.Version); for (var i = 0; i < sortedUnitRoles.Length; i++) { var roleType = sortedUnitRoles[i]; var index = i + 1; object unit = null; if (!reader.IsDBNull(index)) { var unitTypeTag = ((IUnit)roleType.ObjectType).UnitTag; switch (unitTypeTag) { case UnitTags.String: unit = reader.GetString(index); break; case UnitTags.Integer: unit = reader.GetInt32(index); break; case UnitTags.Float: unit = reader.GetDouble(index); break; case UnitTags.Decimal: unit = reader.GetDecimal(index); break; case UnitTags.DateTime: var dateTime = reader.GetDateTime(index); if (dateTime == DateTime.MaxValue || dateTime == DateTime.MinValue) { unit = dateTime; } else { unit = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond, DateTimeKind.Utc); } break; case UnitTags.Boolean: unit = reader.GetBoolean(index); break; case UnitTags.Unique: unit = reader.GetGuid(index); break; case UnitTags.Binary: var byteArray = (byte[])reader.GetValue(index); unit = byteArray; break; default: throw new ArgumentException("Unknown Unit ObjectType: " + roleType.ObjectType.Name); } } if (modifiedRoles == null || !modifiedRoles.ModifiedRoleByRoleType.ContainsKey(roleType)) { cachedObject.SetValue(roleType, unit); } } } } }