From 99123333a1b71f0e6757327bcac21d0cb00cca91 Mon Sep 17 00:00:00 2001 From: rstam Date: Mon, 6 Jun 2011 12:39:03 -0400 Subject: [PATCH] Delayed creation of default settings objects so that they are created with the latest lower level default values. Moved GuidByteOrder to its own file. MongoDefaults that have matching BsonDefaults are now aliases for the corresponding BsonDefaults (that way the values are always the same). --- Bson/Bson.csproj | 1 + Bson/IO/BsonBinaryReaderSettings.cs | 9 ++++-- Bson/IO/BsonBinaryWriterSettings.cs | 9 ++++-- Bson/IO/BsonDocumentReaderSettings.cs | 9 ++++-- Bson/IO/BsonDocumentWriterSettings.cs | 9 ++++-- Bson/IO/JsonReaderSettings.cs | 9 ++++-- Bson/IO/JsonWriterSettings.cs | 9 ++++-- Bson/ObjectModel/BsonBinaryData.cs | 22 -------------- Bson/ObjectModel/GuidByteOrder.cs | 43 +++++++++++++++++++++++++++ Driver/MongoDefaults.cs | 14 ++++----- 10 files changed, 92 insertions(+), 42 deletions(-) create mode 100644 Bson/ObjectModel/GuidByteOrder.cs diff --git a/Bson/Bson.csproj b/Bson/Bson.csproj index 857d40fadd..7241d11d7d 100644 --- a/Bson/Bson.csproj +++ b/Bson/Bson.csproj @@ -83,6 +83,7 @@ + diff --git a/Bson/IO/BsonBinaryReaderSettings.cs b/Bson/IO/BsonBinaryReaderSettings.cs index 4c1c6dae91..9b74ecc014 100644 --- a/Bson/IO/BsonBinaryReaderSettings.cs +++ b/Bson/IO/BsonBinaryReaderSettings.cs @@ -24,7 +24,7 @@ namespace MongoDB.Bson.IO { /// public class BsonBinaryReaderSettings { #region private static fields - private static BsonBinaryReaderSettings defaults = new BsonBinaryReaderSettings(); + private static BsonBinaryReaderSettings defaults = null; // delay creation to pick up the latest default values #endregion #region private fields @@ -67,7 +67,12 @@ namespace MongoDB.Bson.IO { /// Gets or sets the default settings for a BsonBinaryReader. /// public static BsonBinaryReaderSettings Defaults { - get { return defaults; } + get { + if (defaults == null) { + defaults = new BsonBinaryReaderSettings(); + } + return defaults; + } set { defaults = value; } } #endregion diff --git a/Bson/IO/BsonBinaryWriterSettings.cs b/Bson/IO/BsonBinaryWriterSettings.cs index 42c5819b3c..ffc354fda2 100644 --- a/Bson/IO/BsonBinaryWriterSettings.cs +++ b/Bson/IO/BsonBinaryWriterSettings.cs @@ -25,7 +25,7 @@ namespace MongoDB.Bson.IO { [Serializable] public class BsonBinaryWriterSettings { #region private static fields - private static BsonBinaryWriterSettings defaults = new BsonBinaryWriterSettings(); + private static BsonBinaryWriterSettings defaults = null; // delay creation to pick up the latest default values #endregion #region private fields @@ -68,7 +68,12 @@ namespace MongoDB.Bson.IO { /// Gets or sets the default BsonBinaryWriter settings. /// public static BsonBinaryWriterSettings Defaults { - get { return defaults; } + get { + if (defaults == null) { + defaults = new BsonBinaryWriterSettings(); + } + return defaults; + } set { defaults = value; } } #endregion diff --git a/Bson/IO/BsonDocumentReaderSettings.cs b/Bson/IO/BsonDocumentReaderSettings.cs index ff2c862eae..47888c7198 100644 --- a/Bson/IO/BsonDocumentReaderSettings.cs +++ b/Bson/IO/BsonDocumentReaderSettings.cs @@ -24,7 +24,7 @@ namespace MongoDB.Bson.IO { /// public class BsonDocumentReaderSettings { #region private static fields - private static BsonDocumentReaderSettings defaults = new BsonDocumentReaderSettings(); + private static BsonDocumentReaderSettings defaults = null; // delay creation to pick up the latest default values #endregion #region private fields @@ -55,7 +55,12 @@ namespace MongoDB.Bson.IO { /// Gets or sets the default settings for a BsonDocumentReader. /// public static BsonDocumentReaderSettings Defaults { - get { return defaults; } + get { + if (defaults == null) { + defaults = new BsonDocumentReaderSettings(); + } + return defaults; + } set { defaults = value; } } #endregion diff --git a/Bson/IO/BsonDocumentWriterSettings.cs b/Bson/IO/BsonDocumentWriterSettings.cs index 428da94252..1de679c8f7 100644 --- a/Bson/IO/BsonDocumentWriterSettings.cs +++ b/Bson/IO/BsonDocumentWriterSettings.cs @@ -25,7 +25,7 @@ namespace MongoDB.Bson.IO { [Serializable] public class BsonDocumentWriterSettings { #region private static fields - private static BsonDocumentWriterSettings defaults = new BsonDocumentWriterSettings(); + private static BsonDocumentWriterSettings defaults = null; // delay creation to pick up the latest default values #endregion #region private fields @@ -56,7 +56,12 @@ namespace MongoDB.Bson.IO { /// Gets or sets the default BsonDocumentWriter settings. /// public static BsonDocumentWriterSettings Defaults { - get { return defaults; } + get { + if (defaults == null) { + defaults = new BsonDocumentWriterSettings(); + } + return defaults; + } set { defaults = value; } } #endregion diff --git a/Bson/IO/JsonReaderSettings.cs b/Bson/IO/JsonReaderSettings.cs index 93686c7f83..9bec3a7419 100644 --- a/Bson/IO/JsonReaderSettings.cs +++ b/Bson/IO/JsonReaderSettings.cs @@ -24,7 +24,7 @@ namespace MongoDB.Bson.IO { /// public class JsonReaderSettings { #region private static fields - private static JsonReaderSettings defaults = new JsonReaderSettings(); + private static JsonReaderSettings defaults = null; // delay creation to pick up the latest default values #endregion #region private fields @@ -59,7 +59,12 @@ namespace MongoDB.Bson.IO { /// Gets or sets the default settings for a JsonReader. /// public static JsonReaderSettings Defaults { - get { return defaults; } + get { + if (defaults == null) { + defaults = new JsonReaderSettings(); + } + return defaults; + } set { defaults = value; } } #endregion diff --git a/Bson/IO/JsonWriterSettings.cs b/Bson/IO/JsonWriterSettings.cs index 1205215de7..2d7f46f651 100644 --- a/Bson/IO/JsonWriterSettings.cs +++ b/Bson/IO/JsonWriterSettings.cs @@ -25,7 +25,7 @@ namespace MongoDB.Bson.IO { [Serializable] public class JsonWriterSettings { #region private static fields - private static JsonWriterSettings defaults = new JsonWriterSettings(); + private static JsonWriterSettings defaults = null; // delay creation to pick up the latest default values #endregion #region private fields @@ -77,7 +77,12 @@ namespace MongoDB.Bson.IO { /// Gets or sets the default JsonWriterSettings. /// public static JsonWriterSettings Defaults { - get { return defaults; } + get { + if (defaults == null) { + defaults = new JsonWriterSettings(); + } + return defaults; + } set { defaults = value; } } #endregion diff --git a/Bson/ObjectModel/BsonBinaryData.cs b/Bson/ObjectModel/BsonBinaryData.cs index afc7d7835e..8c4de9ccc3 100644 --- a/Bson/ObjectModel/BsonBinaryData.cs +++ b/Bson/ObjectModel/BsonBinaryData.cs @@ -19,28 +19,6 @@ using System.Linq; using System.Text; namespace MongoDB.Bson { - /// - /// Represents the byte order to use when representing a Guid as a byte array. - /// - public enum GuidByteOrder { - /// - /// The byte order for Guids is unspecified, so no conversion between byte arrays and Guids is not possible. - /// - Unspecified, - /// - /// Use Microsoft's internal little endian format (this is the default for historical reasons, but is different from how the Java and other drivers store UUIDs). - /// - LittleEndian, - /// - /// Use the standard external high endian format (this is compatible with how the Java and other drivers store UUIDs). - /// - BigEndian, - /// - /// Use the byte order used by older versions of the Java driver (two 8 byte halves in little endian order). - /// - JavaHistorical - } - /// /// Represents BSON binary data. /// diff --git a/Bson/ObjectModel/GuidByteOrder.cs b/Bson/ObjectModel/GuidByteOrder.cs new file mode 100644 index 0000000000..681e82120a --- /dev/null +++ b/Bson/ObjectModel/GuidByteOrder.cs @@ -0,0 +1,43 @@ +/* Copyright 2010-2011 10gen Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MongoDB.Bson { + /// + /// Represents the byte order to use when representing a Guid as a byte array. + /// + public enum GuidByteOrder { + /// + /// The byte order for Guids is unspecified, so conversion between byte arrays and Guids is not possible. + /// + Unspecified, + /// + /// Use Microsoft's internal little endian format (this is the default for historical reasons, but is different from how the Java and other drivers store UUIDs). + /// + LittleEndian, + /// + /// Use the standard external high endian format (this is compatible with how the Java and other drivers store UUIDs). + /// + BigEndian, + /// + /// Use the byte order used by older versions of the Java driver (two 8 byte halves in little endian order). + /// + JavaHistorical + } +} diff --git a/Driver/MongoDefaults.cs b/Driver/MongoDefaults.cs index 3f4232ade6..2698533b60 100644 --- a/Driver/MongoDefaults.cs +++ b/Driver/MongoDefaults.cs @@ -29,11 +29,9 @@ namespace MongoDB.Driver { #region public static fields private static bool assignIdOnInsert = true; private static TimeSpan connectTimeout = TimeSpan.FromSeconds(30); - private static GuidByteOrder guidByteOrder = GuidByteOrder.LittleEndian; private static TimeSpan maxConnectionIdleTime = TimeSpan.FromMinutes(10); private static TimeSpan maxConnectionLifeTime = TimeSpan.FromMinutes(30); private static int maxConnectionPoolSize = 100; - private static int maxDocumentSize = BsonDefaults.MaxDocumentSize; private static int maxMessageLength = 16000000; // 16MB (not 16 MiB!) private static int minConnectionPoolSize = 0; private static SafeMode safeMode = SafeMode.False; @@ -76,11 +74,11 @@ namespace MongoDB.Driver { } /// - /// Gets or sets the byte order to use for Guids. + /// Gets or sets the byte order to use for Guids (this is an alias for BsonDefaults.GuidByteOrder). /// public static GuidByteOrder GuidByteOrder { - get { return guidByteOrder; } - set { guidByteOrder = value; } + get { return BsonDefaults.GuidByteOrder; } + set { BsonDefaults.GuidByteOrder = value; } } /// @@ -108,11 +106,11 @@ namespace MongoDB.Driver { } /// - /// Gets or sets the max document size. + /// Gets or sets the max document size (this is an alias for BsonDefaults.MaxDocumentSize). /// public static int MaxDocumentSize { - get { return maxDocumentSize; } - set { maxDocumentSize = value; } + get { return BsonDefaults.MaxDocumentSize; } + set { BsonDefaults.MaxDocumentSize = value; } } ///