Skip to content

Commit

Permalink
Made MapReduce non generic again, since we dose not need it to be gen…
Browse files Browse the repository at this point in the history
…eric.
  • Loading branch information
lanwin committed May 12, 2010
1 parent 90b0912 commit ffa6baa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions source/MongoDB/Exceptions/MongoMapReduceException.cs
Expand Up @@ -5,7 +5,7 @@ namespace MongoDB
/// <summary>
/// Raised when a map reduce call fails.
/// </summary>
public class MongoMapReduceException<T> : MongoCommandException
public class MongoMapReduceException : MongoCommandException
{
/// <summary>
/// Gets or sets the map reduce result.
Expand All @@ -14,7 +14,7 @@ public class MongoMapReduceException<T> : MongoCommandException
public MapReduceResult MapReduceResult { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="MongoMapReduceException&lt;T&gt;"/> class.
/// Initializes a new instance of the <see cref="MongoMapReduceException"/> class.
/// </summary>
/// <param name="exception">The exception.</param>
public MongoMapReduceException(MongoCommandException exception)
Expand Down
2 changes: 1 addition & 1 deletion source/MongoDB/IMongoCollection_1.cs
Expand Up @@ -156,7 +156,7 @@ public interface IMongoCollection<T>
/// Entrypoint into executing a map/reduce query against the collection.
/// </summary>
/// <returns></returns>
MapReduce<T> MapReduce();
MapReduce MapReduce();

///<summary>
/// Count all items in the collection.
Expand Down
40 changes: 22 additions & 18 deletions source/MongoDB/MapReduce.cs
Expand Up @@ -8,25 +8,29 @@ namespace MongoDB
/// <summary>
/// Provides a Fluent interface to build and execute Map/Reduce calls.
/// </summary>
public class MapReduce<T> : IDisposable
where T : class
public class MapReduce : IDisposable
{
private readonly IMongoDatabase _database;
private readonly Type _rootType;
private bool _canModify = true;
private bool _disposing;

/// <summary>
/// Initializes a new instance of the <see cref = "MapReduce&lt;T&gt;" /> class.
/// Initializes a new instance of the <see cref = "MapReduce" /> class.
/// </summary>
/// <param name = "database">The database.</param>
/// <param name = "name">The name.</param>
public MapReduce(IMongoDatabase database, string name)
/// <param name = "rootType">Type of the root.</param>
public MapReduce(IMongoDatabase database, string name, Type rootType)
{
if(database == null)
throw new ArgumentNullException("database");
if(name == null)
throw new ArgumentNullException("name");
if(rootType == null)
throw new ArgumentNullException("rootType");

_rootType = rootType;
_database = database;
Command = new MapReduceCommand(name);
}
Expand Down Expand Up @@ -87,7 +91,7 @@ public void Dispose()
/// A map function must call emit(key,value) at least once, but may be invoked any number of times,
/// as may be appropriate.
/// </summary>
public MapReduce<T> Map(string function)
public MapReduce Map(string function)
{
return Map(new Code(function));
}
Expand All @@ -97,7 +101,7 @@ public MapReduce<T> Map(string function)
/// A map function must call emit(key,value) at least once, but may be invoked any number of times,
/// as may be appropriate.
/// </summary>
public MapReduce<T> Map(Code function)
public MapReduce Map(Code function)
{
TryModify();
Command.Map = function;
Expand All @@ -112,7 +116,7 @@ public MapReduce<T> Map(Code function)
/// The MapReduce engine may invoke reduce functions iteratively; thus, these functions
/// must be idempotent. If you need to perform an operation only once, use a finalize function.
/// </remarks>
public MapReduce<T> Reduce(string function)
public MapReduce Reduce(string function)
{
return Reduce(new Code(function));
}
Expand All @@ -125,7 +129,7 @@ public MapReduce<T> Reduce(string function)
/// The MapReduce engine may invoke reduce functions iteratively; thus, these functions
/// must be idempotent. If you need to perform an operation only once, use a finalize function.
/// </remarks>
public MapReduce<T> Reduce(Code function)
public MapReduce Reduce(Code function)
{
TryModify();
Command.Reduce = function;
Expand All @@ -135,7 +139,7 @@ public MapReduce<T> Reduce(Code function)
/// <summary>
/// Query filter object
/// </summary>
public MapReduce<T> Query(Document query)
public MapReduce Query(Document query)
{
TryModify();
Command.Query = query;
Expand All @@ -145,7 +149,7 @@ public MapReduce<T> Query(Document query)
/// <summary>
/// Sort the query. Useful for optimization
/// </summary>
public MapReduce<T> Sort(Document sort)
public MapReduce Sort(Document sort)
{
TryModify();
Command.Sort = sort;
Expand All @@ -155,7 +159,7 @@ public MapReduce<T> Sort(Document sort)
/// <summary>
/// Number of objects to return from collection
/// </summary>
public MapReduce<T> Limit(long limit)
public MapReduce Limit(long limit)
{
TryModify();
Command.Limit = limit;
Expand All @@ -168,7 +172,7 @@ public MapReduce<T> Limit(long limit)
/// <remarks>
/// A temporary collection is still used and then renamed to the target name atomically.
/// </remarks>
public MapReduce<T> Out(String name)
public MapReduce Out(String name)
{
TryModify();
Command.Out = name;
Expand All @@ -179,7 +183,7 @@ public MapReduce<T> Out(String name)
/// When true the generated collection is not treated as temporary. Specifying out automatically makes
/// the collection permanent
/// </summary>
public MapReduce<T> KeepTemp(bool keep)
public MapReduce KeepTemp(bool keep)
{
TryModify();
Command.KeepTemp = keep;
Expand All @@ -189,7 +193,7 @@ public MapReduce<T> KeepTemp(bool keep)
/// <summary>
/// Provides statistics on job execution time.
/// </summary>
public MapReduce<T> Verbose(bool val)
public MapReduce Verbose(bool val)
{
TryModify();
Command.Verbose = val;
Expand All @@ -199,7 +203,7 @@ public MapReduce<T> Verbose(bool val)
/// <summary>
/// Function to apply to all the results when finished.
/// </summary>
public MapReduce<T> Finalize(Code function)
public MapReduce Finalize(Code function)
{
TryModify();
Command.Finalize = function;
Expand All @@ -209,7 +213,7 @@ public MapReduce<T> Finalize(Code function)
/// <summary>
/// Document where fields go into javascript global scope
/// </summary>
public MapReduce<T> Scope(Document scope)
public MapReduce Scope(Document scope)
{
TryModify();
Command.Scope = scope;
Expand All @@ -228,12 +232,12 @@ internal void RetrieveData()

try
{
Result = new MapReduceResult(_database.SendCommand(typeof(T), Command.Command));
Result = new MapReduceResult(_database.SendCommand(_rootType, Command.Command));
}
catch(MongoCommandException exception)
{
Result = new MapReduceResult(exception.Error);
throw new MongoMapReduceException<T>(exception);
throw new MongoMapReduceException(exception);
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/MongoDB/MongoCollection_1.cs
Expand Up @@ -232,8 +232,8 @@ public T FindOne(string javascriptWhere)
/// Entrypoint into executing a map/reduce query against the collection.
/// </summary>
/// <returns>A <see cref="MapReduce"/></returns>
public MapReduce<T> MapReduce(){
return new MapReduce<T>(Database, Name);
public MapReduce MapReduce(){
return new MapReduce(Database, Name, typeof(T));
}

///<summary>
Expand Down
2 changes: 1 addition & 1 deletion source/MongoDB/Obsolete/IMongoCollection.cs
Expand Up @@ -129,7 +129,7 @@ public interface IMongoCollection
/// Maps the reduce.
/// </summary>
/// <returns></returns>
MapReduce<Document> MapReduce();
MapReduce MapReduce();

/// <summary>
/// Counts this instance.
Expand Down
2 changes: 1 addition & 1 deletion source/MongoDB/Obsolete/MongoCollection.cs
Expand Up @@ -180,7 +180,7 @@ public Document FindAndModify (Document document, Document spec, Document sort,
/// Maps the reduce.
/// </summary>
/// <returns></returns>
public MapReduce<Document> MapReduce(){
public MapReduce MapReduce(){
return _collection.MapReduce();
}

Expand Down

0 comments on commit ffa6baa

Please sign in to comment.