Skip to content

Commit 3c7f93c

Browse files
author
rstam
committed
Some more LINQ work. Added MongoExpression and related types.
1 parent ab8eaaf commit 3c7f93c

15 files changed

+484
-7
lines changed

Driver/Driver.csproj

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,23 @@
180180
<Compile Include="Internal\MongoReplyMessage.cs" />
181181
<Compile Include="Internal\MongoUpdateMessage.cs" />
182182
<Compile Include="Internal\ReplicaSetConnector.cs" />
183-
<Compile Include="Linq\Nominator.cs" />
184-
<Compile Include="Linq\PartialEvaluator.cs" />
185-
<Compile Include="Linq\ExpressionPrettyPrinter.cs" />
186-
<Compile Include="Linq\ExpressionVisitor.cs" />
187-
<Compile Include="Linq\TranslatedFindQuery.cs" />
183+
<Compile Include="Linq\Expressions\MongoCollectionExpression.cs" />
184+
<Compile Include="Linq\Expressions\MongoExpression.cs" />
185+
<Compile Include="Linq\Expressions\MongoExpressionType.cs" />
186+
<Compile Include="Linq\Expressions\MongoExpressionVisitor.cs" />
187+
<Compile Include="Linq\Expressions\MongoFieldExpression.cs" />
188+
<Compile Include="Linq\Expressions\MongoProjectionExpression.cs" />
189+
<Compile Include="Linq\Expressions\MongoSelectExpression.cs" />
190+
<Compile Include="Linq\Translators\Nominator.cs" />
191+
<Compile Include="Linq\Translators\PartialEvaluator.cs" />
192+
<Compile Include="Linq\Expressions\ExpressionPrettyPrinter.cs" />
193+
<Compile Include="Linq\Expressions\ExpressionVisitor.cs" />
194+
<Compile Include="Linq\Translators\TranslatedFindQuery.cs" />
188195
<Compile Include="Linq\ExtensionMethods.cs" />
189196
<Compile Include="Linq\MongoQueryable.cs" />
190197
<Compile Include="Linq\MongoQueryProvider.cs" />
191-
<Compile Include="Linq\MongoQueryTranslator.cs" />
192-
<Compile Include="Linq\TranslatedQuery.cs" />
198+
<Compile Include="Linq\Translators\MongoQueryTranslator.cs" />
199+
<Compile Include="Linq\Translators\TranslatedQuery.cs" />
193200
<Compile Include="Linq\TypeSystem.cs" />
194201
<Compile Include="MongoUtils.cs" />
195202
<Compile Include="MongoDefaults.cs" />
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* Copyright 2010-2012 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Linq.Expressions;
20+
using System.Text;
21+
22+
namespace MongoDB.Driver.Linq
23+
{
24+
/// <summary>
25+
/// A MongoExpression that represents a collection.
26+
/// </summary>
27+
public class MongoCollectionExpression : MongoExpression
28+
{
29+
private MongoCollection _collection;
30+
private Type _documentType;
31+
32+
/// <summary>
33+
/// Initializes an instance of the MongoCollectionExpression class.
34+
/// </summary>
35+
/// <param name="collection">The collection referenced.</param>
36+
/// <param name="documentType">The document type.</param>
37+
public MongoCollectionExpression(MongoCollection collection, Type documentType)
38+
: base(MongoExpressionType.Collection, typeof(void))
39+
{
40+
_collection = collection;
41+
_documentType = documentType;
42+
}
43+
44+
/// <summary>
45+
/// Gets the collection.
46+
/// </summary>
47+
public MongoCollection Collection
48+
{
49+
get { return _collection; }
50+
}
51+
52+
/// <summary>
53+
/// Gets the document type.
54+
/// </summary>
55+
public Type DocumentType
56+
{
57+
get { return _documentType; }
58+
}
59+
}
60+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Copyright 2010-2012 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Linq.Expressions;
20+
using System.Text;
21+
22+
namespace MongoDB.Driver.Linq
23+
{
24+
/// <summary>
25+
/// A custom Expression that represents some Mongo LINQ construct (see derived classes).
26+
/// </summary>
27+
public abstract class MongoExpression : Expression
28+
{
29+
/// <summary>
30+
/// Initializes an instance of the MongoExpression class.
31+
/// </summary>
32+
/// <param name="nodeType">The MongoExpressionType of this node.</param>
33+
/// <param name="type">The Type of this MongoExpression.</param>
34+
protected MongoExpression(MongoExpressionType nodeType, Type type)
35+
: base((ExpressionType)nodeType, type)
36+
{
37+
}
38+
}
39+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright 2010-2012 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Linq.Expressions;
20+
using System.Text;
21+
22+
namespace MongoDB.Driver.Linq
23+
{
24+
/// <summary>
25+
/// Represents additional Expression node types for MongoExpression nodes in an expression tree.
26+
/// </summary>
27+
public enum MongoExpressionType
28+
{
29+
// note: make sure these values don't conflict with ExpressionType
30+
31+
/// <summary>
32+
/// An operation that references a MongoDB collection.
33+
/// </summary>
34+
Collection = 1000,
35+
36+
/// <summary>
37+
/// An operation that references a MongoDB field.
38+
/// </summary>
39+
Field,
40+
41+
/// <summary>
42+
/// A select operation against MongoDB.
43+
/// </summary>
44+
Select,
45+
46+
/// <summary>
47+
/// A projection operation against MongoDB.
48+
/// </summary>
49+
Projection
50+
}
51+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* Copyright 2010-2012 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Linq.Expressions;
20+
using System.Text;
21+
22+
namespace MongoDB.Driver.Linq
23+
{
24+
/// <summary>
25+
/// A base class for classes that visit MongoExpressions.
26+
/// </summary>
27+
public abstract class MongoExpressionVisitor : ExpressionVisitor
28+
{
29+
/// <summary>
30+
/// Initializes an instance of the MongoExpressionVisitor class.
31+
/// </summary>
32+
protected MongoExpressionVisitor()
33+
{
34+
}
35+
36+
/// <summary>
37+
/// Visits an Expression (which might be a MongoExpression).
38+
/// </summary>
39+
/// <param name="node">The expression to visit.</param>
40+
/// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns>
41+
protected override Expression Visit(Expression node)
42+
{
43+
if (node == null)
44+
{
45+
return null;
46+
}
47+
48+
switch ((MongoExpressionType)node.NodeType)
49+
{
50+
case MongoExpressionType.Collection:
51+
return VisitCollection((MongoCollectionExpression)node);
52+
case MongoExpressionType.Field:
53+
return VisitField((MongoFieldExpression)node);
54+
case MongoExpressionType.Projection:
55+
return VisitProjection((MongoProjectionExpression)node);
56+
case MongoExpressionType.Select:
57+
return VisitSelect((MongoSelectExpression)node);
58+
default:
59+
return base.Visit(node);
60+
}
61+
}
62+
63+
/// <summary>
64+
/// Visits a MongoCollectionExpression.
65+
/// </summary>
66+
/// <param name="node">The expression to visit.</param>
67+
/// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns>
68+
protected virtual Expression VisitCollection(MongoCollectionExpression node)
69+
{
70+
throw new NotImplementedException();
71+
}
72+
73+
/// <summary>
74+
/// Visits a MongoFieldExpression.
75+
/// </summary>
76+
/// <param name="node">The expression to visit.</param>
77+
/// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns>
78+
protected virtual Expression VisitField(MongoFieldExpression node)
79+
{
80+
throw new NotImplementedException();
81+
}
82+
83+
/// <summary>
84+
/// Visits a MongoProjectionExpression.
85+
/// </summary>
86+
/// <param name="node">The expression to visit.</param>
87+
/// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns>
88+
protected virtual Expression VisitProjection(MongoProjectionExpression node)
89+
{
90+
throw new NotImplementedException();
91+
}
92+
93+
/// <summary>
94+
/// Visits a MongoSelectExpression.
95+
/// </summary>
96+
/// <param name="node">The expression to visit.</param>
97+
/// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns>
98+
protected virtual Expression VisitSelect(MongoSelectExpression node)
99+
{
100+
throw new NotImplementedException();
101+
}
102+
}
103+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* Copyright 2010-2012 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Linq.Expressions;
20+
using System.Text;
21+
22+
using MongoDB.Bson.Serialization;
23+
24+
namespace MongoDB.Driver.Linq
25+
{
26+
/// <summary>
27+
/// A MongoExpression that represents a field reference.
28+
/// </summary>
29+
public class MongoFieldExpression : MongoExpression
30+
{
31+
private Expression _expression;
32+
private string _name;
33+
private BsonMemberMap _memberMap;
34+
35+
/// <summary>
36+
/// Initializes an instance of the MongoFieldExpression class.
37+
/// </summary>
38+
/// <param name="expression">The expression that references the field.</param>
39+
/// <param name="name">The name of the referenced field.</param>
40+
/// <param name="memberMap">The BsonMemberMap of the referenced field.</param>
41+
public MongoFieldExpression(Expression expression, string name, BsonMemberMap memberMap)
42+
: base(MongoExpressionType.Field, expression.Type)
43+
{
44+
_expression = expression;
45+
_name = name;
46+
_memberMap = memberMap;
47+
}
48+
49+
/// <summary>
50+
/// Gets the expression that references the field.
51+
/// </summary>
52+
public Expression Expression
53+
{
54+
get { return _expression; }
55+
}
56+
57+
/// <summary>
58+
/// Gets the BsonMemberMap of the referenced field.
59+
/// </summary>
60+
public BsonMemberMap MemberMap
61+
{
62+
get { return _memberMap; }
63+
}
64+
65+
/// <summary>
66+
/// Gets the name of the referenced field.
67+
/// </summary>
68+
public string Name
69+
{
70+
get { return _name; }
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)