Skip to content

Commit a8c39a3

Browse files
committed
Merge branch 'devel' of github.com:bards/Epic.NET into predicate-refactoring
2 parents b2e5839 + c01ef7a commit a8c39a3

File tree

8 files changed

+47
-76
lines changed

8 files changed

+47
-76
lines changed

Code/Epic.Query/Relational/Operations/InnerJoin.cs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,6 @@ public sealed class InnerJoin: Relation, IEquatable<InnerJoin>
3838
private readonly Relation _rightRelation;
3939
private readonly Predicate _predicate;
4040

41-
/// <summary>
42-
/// Initializes a new instance of the <see cref="Epic.Query.Relational.Operations.InnerJoin"/> class.
43-
/// </summary>
44-
/// <param name='leftRelation'>
45-
/// Left relation in the Join operation.
46-
/// </param>
47-
/// <param name='rightRelation'>
48-
/// Right relation in the Join operation.
49-
/// </param>
50-
/// <param name='predicate'>
51-
/// Predicate used to join the two Relations.
52-
/// </param>
53-
/// <exception cref="ArgumentNullException">Thrown when any argument is <see langword="null"/></exception>
54-
public InnerJoin (Relation leftRelation, Relation rightRelation, Predicate predicate) :
55-
base(RelationType.InnerJoin, getDefaultName(leftRelation))
56-
{
57-
if (null == rightRelation)
58-
throw new ArgumentNullException("rightRelation");
59-
if (null == predicate)
60-
throw new ArgumentNullException("predicate");
61-
62-
this._leftRelation = leftRelation;
63-
this._rightRelation = rightRelation;
64-
this._predicate = predicate;
65-
}
66-
6741
/// <summary>
6842
/// Initializes a new instance of the <see cref="Epic.Query.Relational.Operations.InnerJoin"/> class.
6943
/// </summary>
@@ -151,7 +125,8 @@ public bool Equals (InnerJoin other)
151125

152126
return this.LeftRelation.Equals (other.LeftRelation) &&
153127
this.RightRelation.Equals (other.RightRelation) &&
154-
this.Predicate.Equals (other.Predicate);
128+
this.Predicate.Equals (other.Predicate) &&
129+
this.Name.Equals (other.Name);
155130
}
156131

157132
/// <summary>
@@ -164,7 +139,7 @@ public bool Equals (InnerJoin other)
164139
public override int GetHashCode ()
165140
{
166141
return this.LeftRelation.GetHashCode () ^ this.RightRelation.GetHashCode () ^
167-
this.Predicate.GetHashCode ();
142+
this.Predicate.GetHashCode() ^ this.Name.GetHashCode();
168143
}
169144

170145
/// <summary>
@@ -183,14 +158,6 @@ public override TResult Accept<TResult> (IVisitor<TResult> visitor, IVisitContex
183158
{
184159
return AcceptMe (this, visitor, context);
185160
}
186-
187-
private static string getDefaultName (Relation relation)
188-
{
189-
if (null == relation)
190-
throw new ArgumentNullException("relation");
191-
192-
return relation.Name;
193-
}
194161
}
195162
}
196163

Code/Epic.Query/Relational/Operations/Projection.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public Projection (Relation relation, IEnumerable<RelationAttribute> attributes,
7070
/// The collection of <see cref="RelationAttributes"/> extracted
7171
/// </param>
7272
public Projection(Relation relation, IEnumerable<RelationAttribute> attributes):
73-
base(RelationType.Projection, getDefaultName(relation, attributes))
73+
base(RelationType.Projection, getDefaultName(relation))
7474
{
7575
// if (null == relation) throw new ArgumentNullException("relation");
76-
// if (null == attributes) throw new ArgumentNullException("attributes");
76+
if (null == attributes) throw new ArgumentNullException("attributes");
7777
this._relation = relation;
7878
this._attributes = attributes;
7979
}
@@ -123,7 +123,8 @@ public override bool Equals (Relation other)
123123
public bool Equals(Projection other)
124124
{
125125
if (null == other) return false;
126-
return this.Relation.Equals (other.Relation) && this.Attributes.SequenceEqual(other.Attributes);
126+
return this.Relation.Equals (other.Relation) && this.Attributes.SequenceEqual(other.Attributes)
127+
&& this.Name.Equals (other.Name);
127128
}
128129

129130
/// <summary>
@@ -152,7 +153,7 @@ public override TResult Accept<TResult> (IVisitor<TResult> visitor, IVisitContex
152153
/// </returns>
153154
public override int GetHashCode ()
154155
{
155-
int hash = this.Relation.GetHashCode ();
156+
int hash = this.Relation.GetHashCode () ^ this.Name.GetHashCode ();
156157
foreach (RelationAttribute attribute in this.Attributes)
157158
hash ^= attribute.GetHashCode ();
158159
return hash;
@@ -170,17 +171,10 @@ public override int GetHashCode ()
170171
/// <param name='attributes'>
171172
/// The attributes to be extracted from the relation.
172173
/// </param>
173-
private static string getDefaultName (Relation relation, IEnumerable<RelationAttribute> attributes)
174+
private static string getDefaultName (Relation relation)
174175
{
175176
if (null == relation) throw new ArgumentNullException("relation");
176-
if (null == attributes) throw new ArgumentNullException("attributes");
177-
StringBuilder sb = new StringBuilder();
178-
sb.Append("Take ");
179-
foreach (RelationAttribute attribute in attributes)
180-
sb.Append (attribute.Name).Append(",");
181-
sb.Append (" from ");
182-
sb.Append (relation.Name);
183-
return sb.ToString ();
177+
return relation.Name;
184178
}
185179

186180
}

Code/Epic.Query/Relational/Operations/Rename.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ public sealed class Rename: Relation, IEquatable<Rename>
4444
/// The new name given to the relation.
4545
/// </param>
4646
public Rename (Relation relation, string newRelationName):
47-
base(RelationType.BaseRelation, getDefaultName (relation, newRelationName))
47+
base(RelationType.BaseRelation, getDefaultName (relation))
4848
{
49+
if (String.IsNullOrEmpty (newRelationName))
50+
throw new ArgumentNullException("newRelationName");
4951
this.relation = relation;
5052
this.newRelationName = newRelationName;
5153
}
@@ -114,7 +116,7 @@ public override bool Equals (Relation other)
114116
/// </returns>
115117
public override int GetHashCode ()
116118
{
117-
return this.relation.GetHashCode () ^ this.newRelationName.GetHashCode ();
119+
return this.relation.GetHashCode () ^ this.newRelationName.GetHashCode () ^ this.Name.GetHashCode ();
118120
}
119121

120122
/// <summary>
@@ -149,17 +151,16 @@ public override TResult Accept<TResult> (IVisitor<TResult> visitor, IVisitContex
149151
public bool Equals (Rename other)
150152
{
151153
if (null == other) return false;
152-
return this.relation.Equals (other.relation) && this.newRelationName.Equals (other.newRelationName);
154+
return this.relation.Equals (other.relation) && this.newRelationName.Equals (other.newRelationName)
155+
&& this.Name.Equals (other.Name);
153156
}
154157
#endregion
155158

156-
private static string getDefaultName(Relation relation, string newRelationName)
159+
private static string getDefaultName(Relation relation)
157160
{
158161
if(null == relation)
159162
throw new ArgumentNullException("relation");
160-
if(string.IsNullOrEmpty(newRelationName))
161-
throw new ArgumentNullException("newRelationName");
162-
return string.Format ("{0} as {1}", relation.Name, newRelationName);
163+
return relation.Name;
163164
}
164165
}
165166
}

Code/Epic.Query/Relational/Operations/Selection.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ public sealed class Selection: Relation, IEquatable<Selection>
4747
/// The <see cref="Predicate"/> against which the records are matched.
4848
/// </param>
4949
public Selection (Relation relation, Predicate condition)
50-
: base(RelationType.Selection, getDefaultName (relation, condition))
50+
: base(RelationType.Selection, getDefaultName (relation))
5151
{
52-
// if (null == relation) throw new ArgumentNullException("relation");
53-
// if (null == condition) throw new ArgumentNullException("condition");
52+
if (null == condition) throw new ArgumentNullException("condition");
5453
this._condition = condition;
5554
this._relation = relation;
5655
}
@@ -121,7 +120,8 @@ public override bool Equals (Relation other)
121120
public bool Equals(Selection other)
122121
{
123122
if (null == other) return false;
124-
return this.Relation.Equals (other.Relation) && this.Condition.Equals (other.Condition);
123+
return this.Relation.Equals (other.Relation) && this.Condition.Equals (other.Condition)
124+
&& this.Name.Equals (other.Name);
125125
}
126126

127127
/// <summary>
@@ -133,7 +133,7 @@ public bool Equals(Selection other)
133133
/// </returns>
134134
public override int GetHashCode ()
135135
{
136-
return this.Relation.GetHashCode () ^ this.Condition.GetHashCode ();
136+
return this.Relation.GetHashCode () ^ this.Condition.GetHashCode () ^ this.Name.GetHashCode ();
137137
}
138138

139139
/// <summary>
@@ -165,11 +165,10 @@ public override TResult Accept<TResult> (IVisitor<TResult> visitor, IVisitContex
165165
/// <param name='predicate'>
166166
/// The condition against which the records are matched.
167167
/// </param>
168-
private static string getDefaultName(Relation relation, Predicate predicate)
168+
private static string getDefaultName(Relation relation)
169169
{
170170
if (null == relation) throw new ArgumentNullException("relation");
171-
if (null == predicate) throw new ArgumentNullException("predicate");
172-
return string.Format ("SELECT * from {0} where {1}", relation.Name, predicate.ToString ());
171+
return relation.Name;
173172
}
174173
}
175174
}

Code/UnitTests/Epic.Query.UnitTests/Relational/Operations/InnerJoinQA.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public void Initialize_WithEitherArgumentNull_Fails()
4545
string name = "testName";
4646

4747
// assert:
48-
Assert.Throws<ArgumentNullException>(() => new InnerJoin(null, fakeRelation2, predicate));
49-
Assert.Throws<ArgumentNullException>(() => new InnerJoin(fakeRelation1, null, predicate));
50-
Assert.Throws<ArgumentNullException>(() => new InnerJoin(fakeRelation1, fakeRelation2, null));
5148
Assert.Throws<ArgumentNullException>(() => new InnerJoin(null, fakeRelation2, predicate, name));
5249
Assert.Throws<ArgumentNullException>(() => new InnerJoin(fakeRelation1, null, predicate, name));
5350
Assert.Throws<ArgumentNullException>(() => new InnerJoin(fakeRelation1, fakeRelation2, null, name));
@@ -58,11 +55,12 @@ public void Initialize_WithEitherArgumentNull_Fails()
5855
public void Initialize_WithFakeArguments_Works()
5956
{
6057
// arrange:
61-
string name = "testName";
58+
string firstName = "firstName";
59+
string secondName = "secondName";
6260

6361
// act:
64-
InnerJoin firstJoin = new InnerJoin(fakeRelation1, fakeRelation2, predicate);
65-
InnerJoin secondJoin = new InnerJoin(fakeRelation1, fakeRelation2, predicate, name);
62+
InnerJoin firstJoin = new InnerJoin(fakeRelation1, fakeRelation2, predicate, firstName);
63+
InnerJoin secondJoin = new InnerJoin(fakeRelation1, fakeRelation2, predicate, secondName);
6664

6765
// assert:
6866
Assert.IsTrue (firstJoin.LeftRelation.Equals (fakeRelation1));
@@ -74,8 +72,9 @@ public void Initialize_WithFakeArguments_Works()
7472
Assert.IsTrue (firstJoin.Predicate.Equals (predicate));
7573
Assert.IsTrue (firstJoin.Predicate.Equals (secondJoin.Predicate));
7674

77-
Assert.IsTrue (secondJoin.Name.Equals (name));
78-
Assert.IsTrue (firstJoin.Equals (secondJoin));
75+
Assert.IsTrue (firstJoin.Name.Equals (firstName));
76+
Assert.IsTrue (secondJoin.Name.Equals (secondName));
77+
Assert.IsFalse (firstJoin.Equals (secondJoin));
7978
}
8079

8180
[Test]
@@ -110,15 +109,18 @@ public void Equals_AgainstEquivalentObject_works()
110109
{
111110
// arrange:
112111
string name = "testName";
112+
string otherName = "otherTestName";
113113

114114
// act:
115115
InnerJoin firstJoin = new InnerJoin(fakeRelation1, fakeRelation2, predicate, name);
116116
InnerJoin secondJoin = new InnerJoin(fakeRelation1, fakeRelation2, predicate, name);
117+
InnerJoin thirdJoin = new InnerJoin(fakeRelation1, fakeRelation2, predicate, otherName);
117118
Relation relation = secondJoin;
118119

119120
// assert:
120121
Assert.IsTrue (firstJoin.Equals (secondJoin));
121122
Assert.IsTrue (firstJoin.Equals (relation));
123+
Assert.IsFalse (firstJoin.Equals (thirdJoin));
122124
Assert.AreEqual (firstJoin.GetHashCode (), secondJoin.GetHashCode ());
123125
}
124126

Code/UnitTests/Epic.Query.UnitTests/Relational/Operations/ProjectionQA.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ public void Initialize_WithFakeArguments_Works()
7575
Assert.IsTrue (firstProjection.Attributes.SequenceEqual (attributes));
7676
Assert.IsTrue (firstProjection.Attributes.SequenceEqual (secondProjection.Attributes));
7777

78+
Assert.IsTrue (firstProjection.Name.Equals (table.Name));
7879
Assert.IsTrue (secondProjection.Name.Equals (operationName));
79-
Assert.IsTrue (firstProjection.Equals (secondProjection));
80+
Assert.IsFalse (firstProjection.Equals (secondProjection));
8081
}
8182

8283
[Test]
@@ -124,11 +125,13 @@ public void Equals_AgainstEquivalentObject_works()
124125
// act:
125126
Projection firstProjection = new Projection(table, attributes, operationName);
126127
Projection secondProjection = new Projection(table, attributes, operationName);
128+
Projection thirdProjection = new Projection(table, attributes);
127129
Relation relation = secondProjection;
128130

129131
// assert:
130132
Assert.IsTrue (firstProjection.Equals (secondProjection));
131133
Assert.IsTrue (firstProjection.Equals (relation));
134+
Assert.IsFalse (firstProjection.Equals (thirdProjection));
132135
Assert.AreEqual (firstProjection.GetHashCode (), secondProjection.GetHashCode ());
133136
}
134137

Code/UnitTests/Epic.Query.UnitTests/Relational/Operations/RenameQA.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ public void Initialize_WithFakeArguments_Works()
6969
Assert.IsTrue (firstRename.NewRelationName.Equals (newRelationName));
7070
Assert.IsTrue (firstRename.NewRelationName.Equals (secondRename.NewRelationName));
7171

72+
Assert.IsTrue (firstRename.Name.Equals (table.Name));
7273
Assert.IsTrue (secondRename.Name.Equals (operationName));
73-
Assert.IsTrue (firstRename.Equals (secondRename));
74+
Assert.IsFalse (firstRename.Equals (secondRename));
7475
}
7576

7677
[Test]

Code/UnitTests/Epic.Query.UnitTests/Relational/Operations/SelectionQA.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public void Initialize_WithFakeArguments_Works()
7070
Assert.IsTrue (firstSelection.Condition.Equals (predicate));
7171
Assert.IsTrue (firstSelection.Condition.Equals (secondSelection.Condition));
7272

73+
Assert.IsTrue (firstSelection.Name.Equals (table.Name));
7374
Assert.IsTrue (secondSelection.Name.Equals (operationName));
74-
Assert.IsTrue (firstSelection.Equals (secondSelection));
75+
Assert.IsFalse (firstSelection.Equals (secondSelection));
7576
}
7677

7778
[Test]
@@ -119,15 +120,18 @@ public void Equals_AgainstEquivalentObject_works()
119120
// act:
120121
Selection firstSelection = new Selection(table, predicate, operationName);
121122
Selection secondSelection = new Selection(table, predicate, operationName);
123+
Selection thirdSelection = new Selection(table, predicate);
122124
Relation relation = secondSelection;
123125

124126
// assert:
125127
Assert.IsTrue (firstSelection.Equals (secondSelection));
126128
Assert.IsTrue (firstSelection.Equals (relation));
127129
Assert.AreEqual (firstSelection.GetHashCode (), secondSelection.GetHashCode ());
130+
131+
Assert.IsFalse (firstSelection.Equals (thirdSelection));
128132
}
129133

130-
[Test]
134+
[Test]
131135
public void Test_Serialization_Works()
132136
{
133137
// arrange:

0 commit comments

Comments
 (0)