Browse Source

Added doc comments to MongoDBRef, MongoServerAddress, QueryFlags, RemoveFlags, SafeMode and UpdateFlags.

pull/47/head
rstam 15 years ago
parent
commit
c373fb0cba
  1. 23
      Driver/Core/MongoDBRef.cs
  2. 69
      Driver/Core/MongoServerAddress.cs
  3. 24
      Driver/Core/QueryFlags.cs
  4. 9
      Driver/Core/RemoveFlags.cs
  5. 131
      Driver/Core/SafeMode.cs
  6. 12
      Driver/Core/UpdateFlags.cs

23
Driver/Core/MongoDBRef.cs

@ -25,6 +25,9 @@ using MongoDB.Bson.Serialization;
using MongoDB.Driver;
namespace MongoDB.Driver {
/// <summary>
/// Represents a DBRef (a convenient way to refer to a document).
/// </summary>
public class MongoDBRef : IBsonSerializable {
#region private fields
private string databaseName;
@ -37,6 +40,11 @@ namespace MongoDB.Driver {
private MongoDBRef() {
}
/// <summary>
/// Creates a MongoDBRef.
/// </summary>
/// <param name="collectionName">The name of the collection that contains the document.</param>
/// <param name="id">The Id of the document.</param>
public MongoDBRef(
string collectionName,
BsonValue id
@ -45,6 +53,12 @@ namespace MongoDB.Driver {
this.id = id;
}
/// <summary>
/// Creates a MongoDBRef.
/// </summary>
/// <param name="databaseName">The name of the database that contains the document.</param>
/// <param name="collectionName">The name of the collection that contains the document.</param>
/// <param name="id">The Id of the document.</param>
public MongoDBRef(
string databaseName,
string collectionName,
@ -57,14 +71,23 @@ namespace MongoDB.Driver {
#endregion
#region public properties
/// <summary>
/// Gets the name of the database that contains the document.
/// </summary>
public string DatabaseName {
get { return databaseName; }
}
/// <summary>
/// Gets the name of the collection that contains the document.
/// </summary>
public string CollectionName {
get { return collectionName; }
}
/// <summary>
/// Gets the Id of the document.
/// </summary>
public BsonValue Id {
get { return id; }
}

69
Driver/Core/MongoServerAddress.cs

@ -23,6 +23,9 @@ using System.Text.RegularExpressions;
using System.Xml;
namespace MongoDB.Driver {
/// <summary>
/// The address of a MongoDB server.
/// </summary>
[Serializable]
public class MongoServerAddress : IEquatable<MongoServerAddress> {
#region private fields
@ -31,6 +34,10 @@ namespace MongoDB.Driver {
#endregion
#region constructors
/// <summary>
/// Initializes a new instance of MongoServerAddress.
/// </summary>
/// <param name="host">The server's host name.</param>
public MongoServerAddress(
string host
) {
@ -38,6 +45,11 @@ namespace MongoDB.Driver {
this.port = 27017;
}
/// <summary>
/// Initializes a new instance of MongoServerAddress.
/// </summary>
/// <param name="host">The server's host name.</param>
/// <param name="port">The server's port number.</param>
public MongoServerAddress(
string host,
int port
@ -48,6 +60,11 @@ namespace MongoDB.Driver {
#endregion
#region factory methods
/// <summary>
/// Parses a string representation of a server address.
/// </summary>
/// <param name="value">The string representation of a server address.</param>
/// <returns>A new instance of MongoServerAddress initialized with values parsed from the string.</returns>
public static MongoServerAddress Parse(
string value
) {
@ -59,6 +76,12 @@ namespace MongoDB.Driver {
}
}
/// <summary>
/// Tries to parse a string representation of a server address.
/// </summary>
/// <param name="value">The string representation of a server address.</param>
/// <param name="address">The server address (set to null if TryParse fails).</param>
/// <returns>True if the string is parsed succesfully.</returns>
public static bool TryParse(
string value,
out MongoServerAddress address
@ -80,16 +103,28 @@ namespace MongoDB.Driver {
#endregion
#region public properties
/// <summary>
/// Gets the server's host name.
/// </summary>
public string Host {
get { return host; }
}
/// <summary>
/// Gets the server's port number.
/// </summary>
public int Port {
get { return port; }
}
#endregion
#region public operators
/// <summary>
/// Compares two server addresses.
/// </summary>
/// <param name="lhs">The first server address.</param>
/// <param name="rhs">The other server address.</param>
/// <returns>True if the two server addresses are equal (or both are null).</returns>
public static bool operator ==(
MongoServerAddress lhs,
MongoServerAddress rhs
@ -100,6 +135,12 @@ namespace MongoDB.Driver {
return lhs.host == rhs.host && lhs.port == rhs.port;
}
/// <summary>
/// Compares two server addresses.
/// </summary>
/// <param name="lhs">The first server address.</param>
/// <param name="rhs">The other server address.</param>
/// <returns>True if the two server addresses are not equal (or one is null and the other is not).</returns>
public static bool operator !=(
MongoServerAddress lhs,
MongoServerAddress rhs
@ -109,6 +150,12 @@ namespace MongoDB.Driver {
#endregion
#region public static methods
/// <summary>
/// Compares two server addresses.
/// </summary>
/// <param name="lhs">The first server address.</param>
/// <param name="rhs">The other server address.</param>
/// <returns>True if the two server addresses are equal (or both are null).</returns>
public static bool Equals(
MongoServerAddress lhs,
MongoServerAddress rhs
@ -118,16 +165,30 @@ namespace MongoDB.Driver {
#endregion
#region public methods
/// <summary>
/// Compares two server addresses.
/// </summary>
/// <param name="rhs">The other server address.</param>
/// <returns>True if the two server addresses are equal.</returns>
public bool Equals(
MongoServerAddress rhs
) {
return this == rhs;
}
/// <summary>
/// Compares two server addresses.
/// </summary>
/// <param name="obj">The other server address.</param>
/// <returns>True if the two server addresses are equal.</returns>
public override bool Equals(object obj) {
return this == obj as MongoServerAddress; // works even if obj is null or of a different type
}
/// <summary>
/// Get the hash code for this object.
/// </summary>
/// <returns>The hash code.</returns>
public override int GetHashCode() {
// see Effective Java by Joshua Bloch
int hash = 17;
@ -136,10 +197,18 @@ namespace MongoDB.Driver {
return hash;
}
/// <summary>
/// Returns a string representation of the server address.
/// </summary>
/// <returns>A string representation of the server address.</returns>
public override string ToString() {
return string.Format("{0}:{1}", host, port);
}
/// <summary>
/// Returns the server address as an IPEndPoint (does a DNS lookup).
/// </summary>
/// <returns>The IPEndPoint of the server.</returns>
public IPEndPoint ToIPEndPoint() {
var ipAddresses = Dns.GetHostAddresses(host);
if (ipAddresses != null && ipAddresses.Length != 0) {

24
Driver/Core/QueryFlags.cs

@ -19,14 +19,38 @@ using System.Linq;
using System.Text;
namespace MongoDB.Driver {
/// <summary>
/// Flags used with queries (see the SetQueryFlags method of MongoCursor).
/// </summary>
[Flags]
public enum QueryFlags {
/// <summary>
/// No flags.
/// </summary>
None = 0,
/// <summary>
/// This cursor should be tailable.
/// </summary>
TailableCursor = 2,
/// <summary>
/// It's OK for the query to be handled by a secondary server.
/// </summary>
SlaveOk = 4,
/// <summary>
/// Tell the server not to let the cursor timeout.
/// </summary>
NoCursorTimeout = 16,
/// <summary>
/// Tell the server to wait for data to become available before returning (only used with TailableCursor).
/// </summary>
AwaitData = 32,
/// <summary>
/// Tell the server to send all the data at once (in multiple messages if necessary) without waiting for GetMore messages.
/// </summary>
Exhaust = 64,
/// <summary>
/// Allow partial results in a sharded system if some of the shards are down.
/// </summary>
Partial = 128
}
}

9
Driver/Core/RemoveFlags.cs

@ -19,9 +19,18 @@ using System.Linq;
using System.Text;
namespace MongoDB.Driver {
/// <summary>
/// Flags used with the Remove method of MongoCollection.
/// </summary>
[Flags]
public enum RemoveFlags {
/// <summary>
/// No flags.
/// </summary>
None = 0,
/// <summary>
/// Remove only a single document.
/// </summary>
Single = 1
}
}

131
Driver/Core/SafeMode.cs

@ -19,6 +19,9 @@ using System.Linq;
using System.Text;
namespace MongoDB.Driver {
/// <summary>
/// Represents the different safe modes that can be used.
/// </summary>
[Serializable]
public class SafeMode {
#region private static fields
@ -38,12 +41,21 @@ namespace MongoDB.Driver {
#endregion
#region constructors
/// <summary>
/// Creates a new instance of SafeMode.
/// </summary>
/// <param name="enabled">Whether safe mode is enabled.</param>
public SafeMode(
bool enabled
)
: this(enabled, false) {
}
/// <summary>
/// Creates a new instance of SafeMode.
/// </summary>
/// <param name="enabled">Whether safe mode is enabled.</param>
/// <param name="fsync">Whether the server should call fsync after each operation.</param>
public SafeMode(
bool enabled,
bool fsync
@ -51,6 +63,12 @@ namespace MongoDB.Driver {
: this(enabled, fsync, 0) {
}
/// <summary>
/// Creates a new instance of SafeMode.
/// </summary>
/// <param name="enabled">Whether safe mode is enabled.</param>
/// <param name="fsync">Whether the server should call fsync after each operation.</param>
/// <param name="w">The number of write replications that should be completed before server returns.</param>
public SafeMode(
bool enabled,
bool fsync,
@ -59,6 +77,13 @@ namespace MongoDB.Driver {
: this(enabled, fsync, w, TimeSpan.Zero) {
}
/// <summary>
/// Creates a new instance of SafeMode.
/// </summary>
/// <param name="enabled">Whether safe mode is enabled.</param>
/// <param name="fsync">Whether the server should call fsync after each operation.</param>
/// <param name="w">The number of write replications that should be completed before server returns.</param>
/// <param name="wtimeout">The timeout for each operation.</param>
public SafeMode(
bool enabled,
bool fsync,
@ -81,12 +106,21 @@ namespace MongoDB.Driver {
this.wtimeout = wtimeout;
}
/// <summary>
/// Creates a new instance of SafeMode.
/// </summary>
/// <param name="w">The number of write replications that should be completed before server returns.</param>
public SafeMode(
int w
)
: this(true, false, w) {
}
/// <summary>
/// Creates a new instance of SafeMode.
/// </summary>
/// <param name="w">The number of write replications that should be completed before server returns.</param>
/// <param name="wtimeout">The timeout for each operation.</param>
public SafeMode(
int w,
TimeSpan wtimeout
@ -96,50 +130,86 @@ namespace MongoDB.Driver {
#endregion
#region public static properties
/// <summary>
/// Gets an instance of SafeMode with safe mode off.
/// </summary>
public static SafeMode False {
get { return @false; }
}
/// <summary>
/// Gets an instance of SafeMode with fsync=true.
/// </summary>
public static SafeMode FSyncTrue {
get { return fsyncTrue; }
}
/// <summary>
/// Gets an instance of SafeMode with safe mode on.
/// </summary>
public static SafeMode True {
get { return @true; }
}
/// <summary>
/// Gets an instance of SafeMode with safe mode on and w=2.
/// </summary>
public static SafeMode W2 {
get { return w2; }
}
/// <summary>
/// Gets an instance of SafeMode with safe mode on and w=3.
/// </summary>
public static SafeMode W3 {
get { return w3; }
}
/// <summary>
/// Gets an instance of SafeMode with safe mode on and w=4.
/// </summary>
public static SafeMode W4 {
get { return w4; }
}
#endregion
#region public properties
/// <summary>
/// Gets whether safe mode is enabled.
/// </summary>
public bool Enabled {
get { return enabled; }
}
/// <summary>
/// Gets whether fsync is true.
/// </summary>
public bool FSync {
get { return fsync; }
}
/// <summary>
/// Gets the w value (the number of write replications that must complete before the server returns).
/// </summary>
public int W {
get { return w; }
}
/// <summary>
/// Gets the wtimeout value (the timeout before which the server must return).
/// </summary>
public TimeSpan WTimeout {
get { return wtimeout; }
}
#endregion
#region public operators
/// <summary>
/// Compares to SafeMode values.
/// </summary>
/// <param name="lhs">The first SafeMode value.</param>
/// <param name="rhs">The second SafeMode value.</param>
/// <returns>True if the values are equal (or both null).</returns>
public static bool operator ==(
SafeMode lhs,
SafeMode rhs
@ -147,6 +217,12 @@ namespace MongoDB.Driver {
return object.Equals(lhs, rhs);
}
/// <summary>
/// Compares to SafeMode values.
/// </summary>
/// <param name="lhs">The first SafeMode value.</param>
/// <param name="rhs">The second SafeMode value.</param>
/// <returns>True if the values are not equal (or one is null and the other is not).</returns>
public static bool operator !=(
SafeMode lhs,
SafeMode rhs
@ -156,12 +232,23 @@ namespace MongoDB.Driver {
#endregion
#region public static methods
/// <summary>
/// Creates a SafeMode instance (or returns an existing instance).
/// </summary>
/// <param name="enabled">Whether safe mode is enabled.</param>
/// <returns>A SafeMode instance.</returns>
public static SafeMode Create(
bool enabled
) {
return Create(enabled, false);
}
/// <summary>
/// Creates a SafeMode instance (or returns an existing instance).
/// </summary>
/// <param name="enabled">Whether safe mode is enabled.</param>
/// <param name="fsync">Whether fysnc is true.</param>
/// <returns>A SafeMode instance.</returns>
public static SafeMode Create(
bool enabled,
bool fsync
@ -169,6 +256,13 @@ namespace MongoDB.Driver {
return Create(enabled, fsync, 0);
}
/// <summary>
/// Creates a SafeMode instance (or returns an existing instance).
/// </summary>
/// <param name="enabled">Whether safe mode is enabled.</param>
/// <param name="fsync">Whether fysnc is true.</param>
/// <param name="w">The number of write replications that should be completed before server returns.</param>
/// <returns>A SafeMode instance.</returns>
public static SafeMode Create(
bool enabled,
bool fsync,
@ -177,6 +271,14 @@ namespace MongoDB.Driver {
return Create(enabled, fsync, w, TimeSpan.Zero);
}
/// <summary>
/// Creates a SafeMode instance (or returns an existing instance).
/// </summary>
/// <param name="enabled">Whether safe mode is enabled.</param>
/// <param name="fsync">Whether fysnc is true.</param>
/// <param name="w">The number of write replications that should be completed before server returns.</param>
/// <param name="wtimeout">The timeout for each operation.</param>
/// <returns>A SafeMode instance.</returns>
public static SafeMode Create(
bool enabled,
bool fsync,
@ -198,12 +300,23 @@ namespace MongoDB.Driver {
return new SafeMode(enabled, fsync, w, wtimeout);
}
/// <summary>
/// Creates a SafeMode instance (or returns an existing instance).
/// </summary>
/// <param name="w">The number of write replications that should be completed before server returns.</param>
/// <returns>A SafeMode instance.</returns>
public static SafeMode Create(
int w
) {
return Create(w, TimeSpan.Zero);
}
/// <summary>
/// Creates a SafeMode instance (or returns an existing instance).
/// </summary>
/// <param name="w">The number of write replications that should be completed before server returns.</param>
/// <param name="wtimeout">The timeout for each operation.</param>
/// <returns>A SafeMode instance.</returns>
public static SafeMode Create(
int w,
TimeSpan wtimeout
@ -213,12 +326,22 @@ namespace MongoDB.Driver {
#endregion
#region public methods
/// <summary>
/// Compares to SafeMode values.
/// </summary>
/// <param name="obj">The other SafeMode value.</param>
/// <returns>True if the values are equal.</returns>
public override bool Equals(
object obj
) {
return Equals(obj as SafeMode); // works even if obj is null
}
/// <summary>
/// Compares to SafeMode values.
/// </summary>
/// <param name="rhs">The other SafeMode value.</param>
/// <returns>True if the values are equal.</returns>
public bool Equals(
SafeMode rhs
) {
@ -226,6 +349,10 @@ namespace MongoDB.Driver {
return this.enabled == rhs.enabled && this.fsync == rhs.fsync && this.w == rhs.w && this.wtimeout == rhs.wtimeout;
}
/// <summary>
/// Get the hash code for the SafeMode.
/// </summary>
/// <returns>The hash code.</returns>
public override int GetHashCode() {
// see Effective Java by Joshua Bloch
int hash = 17;
@ -236,6 +363,10 @@ namespace MongoDB.Driver {
return hash;
}
/// <summary>
/// Returns a string representation of the SafeMode.
/// </summary>
/// <returns>A string representation of the SafeMode.</returns>
public override string ToString() {
if (enabled) {
var sb = new StringBuilder("safe=true");

12
Driver/Core/UpdateFlags.cs

@ -19,10 +19,22 @@ using System.Linq;
using System.Text;
namespace MongoDB.Driver {
/// <summary>
/// Flags used with the Update method in MongoCollection.
/// </summary>
[Flags]
public enum UpdateFlags {
/// <summary>
/// No flags.
/// </summary>
None = 0,
/// <summary>
/// If document doesn't exist then do an Insert.
/// </summary>
Upsert = 1,
/// <summary>
/// Update all matching documents (instead of just one).
/// </summary>
Multi = 2
}
}
Loading…
Cancel
Save