Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
InnerJoinedSource.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
6
8{
13 {
21 : base(Left, Right, Conditions)
22 {
23 }
24
36 public override async Task<IResultSetEnumerator> Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables,
37 KeyValuePair<VariableReference, bool>[] Order, ScriptNode Node)
38 {
39 ScriptNode LeftWhere = await Reduce(this.Left, Where);
40 KeyValuePair<VariableReference, bool>[] LeftOrder = await Reduce(this.Left, Order);
41
42 IResultSetEnumerator e = await this.Left.Find(0, int.MaxValue, Generic, LeftWhere, Variables, LeftOrder, Node);
43
44 ScriptNode RightWhere = await Reduce(this.Right, this.Left, Where);
45 RightWhere = this.Combine(RightWhere, this.Conditions);
46
47 e = new InnerJoinEnumerator(e, this.Left.Name, this.Right, this.Right.Name, Generic, RightWhere, Variables);
48
49 if (!(Where is null))
50 e = new ConditionalEnumerator(e, Variables, Where);
51
52 if (Offset > 0)
53 e = new OffsetEnumerator(e, Offset);
54
55 if (Top != int.MaxValue)
56 e = new MaxCountEnumerator(e, Top);
57
58 return e;
59 }
60
61 private class InnerJoinEnumerator : IResultSetEnumerator
62 {
63 private readonly IResultSetEnumerator left;
64 private readonly IDataSource rightSource;
65 private readonly ScriptNode conditions;
66 private readonly Variables variables;
67 private readonly string leftName;
68 private readonly string rightName;
69 private readonly bool hasLeftName;
70 private readonly bool generic;
71 private IResultSetEnumerator right;
72 private JoinedObject current = null;
73 private ObjectProperties leftVariables = null;
74
75 public InnerJoinEnumerator(IResultSetEnumerator Left, string LeftName, IDataSource RightSource, string RightName,
77 {
78 this.left = Left;
79 this.leftName = LeftName;
80 this.rightName = RightName;
81 this.rightSource = RightSource;
82 this.generic = Generic;
83 this.conditions = Conditions;
84 this.variables = Variables;
85 this.hasLeftName = !string.IsNullOrEmpty(this.leftName);
86 }
87
88 public object Current => this.current;
89
90 public bool MoveNext()
91 {
92 return this.MoveNextAsync().Result;
93 }
94
95 public async Task<bool> MoveNextAsync()
96 {
97 while (true)
98 {
99 if (!(this.right is null))
100 {
101 if (await this.right.MoveNextAsync())
102 {
103 this.current = new JoinedObject(this.left.Current, this.leftName,
104 this.right.Current, this.rightName);
105
106 return true;
107 }
108 else
109 this.right = null;
110 }
111
112 if (!await this.left.MoveNextAsync())
113 return false;
114
115 if (this.leftVariables is null)
116 this.leftVariables = new ObjectProperties(this.left.Current, this.variables);
117 else
118 this.leftVariables.Object = this.left.Current;
119
120 if (this.hasLeftName)
121 this.leftVariables[this.leftName] = this.left.Current;
122
123 this.right = await this.rightSource.Find(0, int.MaxValue, this.generic, this.conditions, this.leftVariables,
124 null, this.conditions);
125 }
126 }
127
128 public void Reset()
129 {
130 this.current = null;
131 this.right = null;
132 this.left.Reset();
133 }
134 }
135
136 }
137}
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Enumerator that only returns elements matching a set of conditions.
Enumerator that limits the return set to a maximum number of records.
Enumerator that skips a given number of result records.
Data source formed through an INNER JOIN of two sources.
InnerJoinedSource(IDataSource Left, IDataSource Right, ScriptNode Conditions)
Data source formed through an INNER JOIN of two sources.
override async Task< IResultSetEnumerator > Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds objects matching filter conditions in Where .
Abstract base classes of joined sources.
Definition: JoinedSource.cs:14
ScriptNode Conditions
Conditions for join.
Definition: JoinedSource.cs:45
ScriptNode Combine(ScriptNode Where, ScriptNode On)
Combines one or two restrictions.
static async Task< ScriptNode > Reduce(IDataSource Source, ScriptNode Where)
Reduces a where clause to fit the current data source.
Collection of variables.
Definition: Variables.cs:25
Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
Interface for data sources that can be used in SQL statements.
Definition: IDataSource.cs:13
Task< IResultSetEnumerator > Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds objects matching filter conditions in Where .
string Name
Collection name or alias.
Definition: IDataSource.cs:76