Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use Save for Update(doc).

Add missing obsolete attribute.
  • Loading branch information...
commit a292e296ceebc8708929a148287d6c55a1cf076d 1 parent d909def
Steve Wagner authored March 22, 2010
44  MongoDBDriver/Generic/Collection.cs
@@ -413,7 +413,7 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
413 413
         /// <param name="document">The document.</param>
414 414
         /// <param name="safemode">if set to <c>true</c> [safemode].</param>
415 415
         public void Update(Document document, bool safemode){
416  
-            Update((object)document, safemode);
  416
+            Save((object)document, safemode);
417 417
         }
418 418
 
419 419
         /// <summary>
@@ -421,9 +421,8 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
421 421
         /// </summary>
422 422
         /// <param name="document">The document.</param>
423 423
         /// <param name="safemode">if set to <c>true</c> [safemode].</param>
424  
-        public void Update(object document, bool safemode){
425  
-            Update(document);
426  
-            CheckError(safemode);
  424
+        public void Update(object document, bool safemode){
  425
+            Save(document, safemode);
427 426
         }
428 427
 
429 428
         /// <summary>
@@ -436,7 +435,7 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
436 435
         /// instead.
437 436
         /// </remarks>
438 437
         public void Update(Document document){
439  
-            Update((object)document);
  438
+            Save((object)document);
440 439
         }
441 440
 
442 441
         /// <summary>
@@ -448,25 +447,8 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
448 447
         /// the document then it is assumed that the document is new and an upsert is sent to the database
449 448
         /// instead.
450 449
         /// </remarks>
451  
-        public void Update(object document){
452  
-            //Try to generate a selector using _id for an existing document.
453  
-            //otherwise just set the upsert flag to 1 to insert and send onward.
454  
-            var selector = new Document();
455  
-            var upsert = UpdateFlags.Upsert;
456  
-            
457  
-            var descriptor = _serializationFactory.GetObjectDescriptor(typeof(T));
458  
-            
459  
-            var value = descriptor.GetPropertyValue(document, "_id");
460  
-            
461  
-            if (value != null) {
462  
-                selector["_id"] = value;
463  
-            } else {
464  
-                //Likely a new document
465  
-                descriptor.SetPropertyValue(document, "_id", Oid.NewOid());
466  
-                upsert = UpdateFlags.Upsert;
467  
-            }
468  
-            
469  
-            Update(document, selector, upsert);
  450
+        public void Update(object document){
  451
+            Save(document);
470 452
         }
471 453
 
472 454
         /// <summary>
@@ -631,7 +613,12 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
631 613
         /// </summary>
632 614
         /// <param name="document">The document.</param>
633 615
         /// <param name="safemode">if set to <c>true</c> [safemode].</param>
634  
-        public void Save(Document document, bool safemode){
  616
+        /// <remarks>
  617
+        /// The document will contain the _id that is saved to the database.  This is really just an alias
  618
+        /// to Update(Document) to maintain consistency between drivers.
  619
+        /// </remarks>
  620
+        public void Save(Document document, bool safemode)
  621
+        {
635 622
             Save((object)document, safemode);
636 623
         }
637 624
 
@@ -672,7 +659,12 @@ public Collection(ISerializationFactory serializationFactory, Connection connect
672 659
         /// </summary>
673 660
         /// <param name="document">The document.</param>
674 661
         /// <param name="safemode">if set to <c>true</c> [safemode].</param>
675  
-        public void Save(object document,bool safemode){
  662
+        /// <remarks>
  663
+        /// The document will contain the _id that is saved to the database.  This is really just an alias
  664
+        /// to Update(Document) to maintain consistency between drivers.
  665
+        /// </remarks>
  666
+        public void Save(object document, bool safemode)
  667
+        {
676 668
             Save(document);
677 669
             CheckError(safemode);
678 670
         }
7  MongoDBDriver/Generic/IMongoCollection.cs
@@ -256,6 +256,7 @@ public interface IMongoCollection<T> where T : class
256 256
         /// </summary>
257 257
         /// <param name = "document">The document.</param>
258 258
         /// <param name = "safemode">if set to <c>true</c> [safemode].</param>
  259
+        [Obsolete("Use Save instead")]
259 260
         void Update(Document document, bool safemode);
260 261
 
261 262
         /// <summary>
@@ -265,7 +266,7 @@ public interface IMongoCollection<T> where T : class
265 266
         /// <param name="document">The document.</param>
266 267
         /// <param name="safemode">if set to <c>true</c> [safemode].</param>
267 268
         /// <remarks>See the safemode description in the class description</remarks>
268  
-        [Obsolete("Use Save")]
  269
+        [Obsolete("Use Save instead")]
269 270
         void Update(object document, bool safemode);
270 271
 
271 272
         /// <summary>
@@ -273,7 +274,7 @@ public interface IMongoCollection<T> where T : class
273 274
         /// generated and an upsert sent.  Otherwise the document matching the _id of the document will be updated.
274 275
         /// </summary>
275 276
         /// <param name = "document">The document.</param>
276  
-        [Obsolete("Use Save")]
  277
+        [Obsolete("Use Save instead")]
277 278
         void Update(Document document);
278 279
 
279 280
         /// <summary>
@@ -281,7 +282,7 @@ public interface IMongoCollection<T> where T : class
281 282
         /// generated and an upsert sent.  Otherwise the document matching the _id of the document will be updated.
282 283
         /// </summary>
283 284
         /// <param name = "document">The document.</param>
284  
-        [Obsolete("Use Save")]
  285
+        [Obsolete("Use Save instead")]
285 286
         void Update(object document);
286 287
 
287 288
         /// <summary>

0 notes on commit a292e29

Please sign in to comment.
Something went wrong with that request. Please try again.