Permalink
Browse files

Use Save for Update(doc).

Add missing obsolete attribute.
  • Loading branch information...
1 parent d909def commit a292e296ceebc8708929a148287d6c55a1cf076d @lanwin lanwin committed Mar 22, 2010
Showing with 22 additions and 29 deletions.
  1. +18 −26 MongoDBDriver/Generic/Collection.cs
  2. +4 −3 MongoDBDriver/Generic/IMongoCollection.cs
@@ -413,17 +413,16 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
/// <param name="document">The document.</param>
/// <param name="safemode">if set to <c>true</c> [safemode].</param>
public void Update(Document document, bool safemode){
- Update((object)document, safemode);
+ Save((object)document, safemode);
}
/// <summary>
/// Updates the specified document.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="safemode">if set to <c>true</c> [safemode].</param>
- public void Update(object document, bool safemode){
- Update(document);
- CheckError(safemode);
+ public void Update(object document, bool safemode){
+ Save(document, safemode);
}
/// <summary>
@@ -436,7 +435,7 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
/// instead.
/// </remarks>
public void Update(Document document){
- Update((object)document);
+ Save((object)document);
}
/// <summary>
@@ -448,25 +447,8 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
/// the document then it is assumed that the document is new and an upsert is sent to the database
/// instead.
/// </remarks>
- public void Update(object document){
- //Try to generate a selector using _id for an existing document.
- //otherwise just set the upsert flag to 1 to insert and send onward.
- var selector = new Document();
- var upsert = UpdateFlags.Upsert;
-
- var descriptor = _serializationFactory.GetObjectDescriptor(typeof(T));
-
- var value = descriptor.GetPropertyValue(document, "_id");
-
- if (value != null) {
- selector["_id"] = value;
- } else {
- //Likely a new document
- descriptor.SetPropertyValue(document, "_id", Oid.NewOid());
- upsert = UpdateFlags.Upsert;
- }
-
- Update(document, selector, upsert);
+ public void Update(object document){
+ Save(document);
}
/// <summary>
@@ -631,7 +613,12 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
/// </summary>
/// <param name="document">The document.</param>
/// <param name="safemode">if set to <c>true</c> [safemode].</param>
- public void Save(Document document, bool safemode){
+ /// <remarks>
+ /// The document will contain the _id that is saved to the database. This is really just an alias
+ /// to Update(Document) to maintain consistency between drivers.
+ /// </remarks>
+ public void Save(Document document, bool safemode)
+ {
Save((object)document, safemode);
}
@@ -672,7 +659,12 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
/// </summary>
/// <param name="document">The document.</param>
/// <param name="safemode">if set to <c>true</c> [safemode].</param>
- public void Save(object document,bool safemode){
+ /// <remarks>
+ /// The document will contain the _id that is saved to the database. This is really just an alias
+ /// to Update(Document) to maintain consistency between drivers.
+ /// </remarks>
+ public void Save(object document, bool safemode)
+ {
Save(document);
CheckError(safemode);
}
@@ -256,6 +256,7 @@ public interface IMongoCollection<T> where T : class
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
+ [Obsolete("Use Save instead")]
void Update(Document document, bool safemode);
/// <summary>
@@ -265,23 +266,23 @@ public interface IMongoCollection<T> where T : class
/// <param name="document">The document.</param>
/// <param name="safemode">if set to <c>true</c> [safemode].</param>
/// <remarks>See the safemode description in the class description</remarks>
- [Obsolete("Use Save")]
+ [Obsolete("Use Save instead")]
void Update(object document, bool safemode);
/// <summary>
/// Inserts or updates a document in the database. If the document does not contain an _id one will be
/// generated and an upsert sent. Otherwise the document matching the _id of the document will be updated.
/// </summary>
/// <param name = "document">The document.</param>
- [Obsolete("Use Save")]
+ [Obsolete("Use Save instead")]
void Update(Document document);
/// <summary>
/// Inserts or updates a document in the database. If the document does not contain an _id one will be
/// generated and an upsert sent. Otherwise the document matching the _id of the document will be updated.
/// </summary>
/// <param name = "document">The document.</param>
- [Obsolete("Use Save")]
+ [Obsolete("Use Save instead")]
void Update(object document);
/// <summary>

0 comments on commit a292e29

Please sign in to comment.