public PrefetchPolicy this[IClass @class] // Indexer declaration { get { if (!this.prefetchPolicyByClass.TryGetValue(@class, out var prefetchPolicy)) { var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); foreach (var roleType in @class.RoleTypes) { prefetchPolicyBuilder.WithRule(roleType); } foreach (var associationType in @class.AssociationTypes) { prefetchPolicyBuilder.WithRule(associationType); } prefetchPolicy = prefetchPolicyBuilder.Build(); this.prefetchPolicyByClass[@class] = prefetchPolicy; } return(prefetchPolicy); } }
public SyncResponse Build() { var objects = this.session.Instantiate(this.syncRequest.Objects); // Prefetch var objectByClass = objects.GroupBy(v => v.Strategy.Class, v => v); foreach (var groupBy in objectByClass) { var prefetchClass = (Class)groupBy.Key; var prefetchObjects = groupBy.ToArray(); var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); prefetchPolicyBuilder.WithGroupRules(prefetchClass, this.@group); prefetchPolicyBuilder.WithSecurityRules(); var prefetcher = prefetchPolicyBuilder.Build(); this.session.Prefetch(prefetcher, prefetchObjects); } return(new SyncResponse { UserSecurityHash = this.user.SecurityHash(), Objects = objects.Select(x => new SyncResponseObject { I = x.Id.ToString(), V = x.Strategy.ObjectVersion.ToString(), T = x.Strategy.Class.Name, Roles = this.GetRoles(x), Methods = this.GetMethods(x), }).ToArray() }); }
public PrefetchPolicy BuildPrefetechPolicy() { var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); foreach (var node in this.Nodes) { node.BuildPrefetchPolicy(prefetchPolicyBuilder); } return(prefetchPolicyBuilder.Build()); }
public static PrefetchPolicy BuildPrefetchPolicy(this Node[] treeNodes) { var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); foreach (var node in treeNodes) { node.BuildPrefetchPolicy(prefetchPolicyBuilder); } return(prefetchPolicyBuilder.Build()); }
public void BuildPrefetchPolicy(PrefetchPolicyBuilder prefetchPolicyBuilder) { if (this.Nodes == null || this.Nodes.Length == 0) { prefetchPolicyBuilder.WithRule(this.PropertyType); } else { var nestedPrefetchPolicyBuilder = new PrefetchPolicyBuilder(); foreach (var node in this.Nodes) { node.BuildPrefetchPolicy(nestedPrefetchPolicyBuilder); } var nestedPrefetchPolicy = nestedPrefetchPolicyBuilder.Build(); prefetchPolicyBuilder.WithRule(this.PropertyType, nestedPrefetchPolicy); } }
public void BuildPrefetchPolicy(PrefetchPolicyBuilder prefetchPolicyBuilder) { if (this.Nodes.Count == 0) { prefetchPolicyBuilder.WithRule(this.RoleType); } else { var nestedPrefetchPolicyBuilder = new PrefetchPolicyBuilder(); foreach (var node in this.Nodes) { node.BuildPrefetchPolicy(nestedPrefetchPolicyBuilder); } var nestedPrefetchPolicy = nestedPrefetchPolicyBuilder.Build(); prefetchPolicyBuilder.WithRule(this.RoleType, nestedPrefetchPolicy); } }
public void PrefetchCompositesRole() { var database = this.CreateDatabase(); database.Init(); using (var session = database.CreateSession()) { var c1a = C1.Create(session); var c1b = C1.Create(session); var c2a = C2.Create(session); var c2b = C2.Create(session); var c2c = C2.Create(session); c1a.AddC1C2one2many(c2a); c1a.AddC1C2one2many(c2b); session.Commit(); c1a.RemoveC1C1one2manies(); c1a.AddC1C2one2many(c2c); var extent = session.Extent <C1>(); var array = extent.ToArray(); var nestedPrefetchPolicyBuilder = new PrefetchPolicyBuilder(); nestedPrefetchPolicyBuilder.WithRule(M.C2.C2C2one2manies); var nestedPrefetchPolicy = nestedPrefetchPolicyBuilder.Build(); var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); prefetchPolicyBuilder.WithRule(M.C1.C1C2one2manies, nestedPrefetchPolicy); var prefetchPolicy = prefetchPolicyBuilder.Build(); session.Prefetch(prefetchPolicy, new[] { c1a, c1b }); var result = c1a.C1C2one2manies; session.Rollback(); Assert.Equal(2, c1a.C1C2one2manies.Count); Assert.Contains(c2a, c1a.C1C2one2manies.ToArray()); Assert.Contains(c2b, c1a.C1C2one2manies.ToArray()); } }
public void PrefetchCompositeRole() { var database = this.CreateDatabase(); database.Init(); using (var session = database.CreateSession()) { var c1a = C1.Create(session); var c1b = C1.Create(session); var c2a = C2.Create(session); var c2b = C2.Create(session); session.Commit(); c1a.C1C2many2one = c2a; var extent = session.Extent <C1>(); var array = extent.ToArray(); var nestedPrefetchPolicyBuilder = new PrefetchPolicyBuilder(); nestedPrefetchPolicyBuilder.WithRule(M.C2.C2C2one2manies); var nestedPrefetchPolicy = nestedPrefetchPolicyBuilder.Build(); var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); prefetchPolicyBuilder.WithRule(M.C1.C1C2many2one, nestedPrefetchPolicy); var prefetchPolicy = prefetchPolicyBuilder.Build(); session.Prefetch(prefetchPolicy, new[] { c1a, c1b }); var result = c1a.C1C2many2one; session.Rollback(); Assert.False(c1a.ExistC1C2many2one); } }
public SyncResponse Build() { var objects = this.session.Instantiate(this.syncRequest.Objects); // Prefetch var objectByClass = objects.GroupBy(v => v.Strategy.Class, v => v); foreach (var groupBy in objectByClass) { var prefetchClass = (Class)groupBy.Key; var prefetchObjects = groupBy.ToArray(); var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); prefetchPolicyBuilder.WithWorkspaceRules(prefetchClass); prefetchPolicyBuilder.WithSecurityRules(prefetchClass); var prefetcher = prefetchPolicyBuilder.Build(); this.session.Prefetch(prefetcher, prefetchObjects); } SyncResponseRole CreateSyncResponseRole(IObject @object, IRoleType roleType) { var syncResponseRole = new SyncResponseRole { T = roleType.IdAsString }; if (roleType.ObjectType.IsUnit) { syncResponseRole.V = UnitConvert.ToString(@object.Strategy.GetUnitRole(roleType.RelationType)); } else if (roleType.IsOne) { syncResponseRole.V = @object.Strategy.GetCompositeRole(roleType.RelationType)?.Id.ToString(); } else { var roles = @object.Strategy.GetCompositeRoles(roleType.RelationType); if (roles.Count > 0) { syncResponseRole.V = string.Join( separator: Encoding.Separator, values: roles .Cast <IObject>() .Select(roleObject => roleObject.Id.ToString())); } } return(syncResponseRole); } var syncResponse = new SyncResponse { Objects = objects.Select(v => { var @class = (Class)v.Strategy.Class; var acl = this.acls[v]; return(new SyncResponseObject { I = v.Id.ToString(), V = v.Strategy.ObjectVersion.ToString(), T = v.Strategy.Class.IdAsString, R = @class.WorkspaceRoleTypes .Where(w => acl.CanRead(w) && v.Strategy.ExistRole(w.RelationType)) .Select(w => CreateSyncResponseRole(v, w)) .ToArray(), A = this.accessControlsWriter.Write(v), D = this.permissionsWriter.Write(v), }); }).ToArray(), }; syncResponse.AccessControls = this.acls.EffectivePermissionIdsByAccessControl.Keys .Select(v => new[] { v.Strategy.ObjectId.ToString(), v.Strategy.ObjectVersion.ToString(), }) .ToArray(); return(syncResponse); }