コード例 #1
0
        /// <summary>
        /// Generates the identity value
        /// </summary>
        /// <param name="db">MongoDatabase instance</param>
        /// <param name="collectionName">Collection Name</param>
        /// <returns>Generated identity</returns>
        public long GenerateId(IMongoDatabase db, string collectionName)
        {
            SequenceIdGenerator value;

            lock (_generatorLock)
            {
                if (_keyGeneratorsByTag.TryGetValue(collectionName, out value))
                    return value.GenerateId(collectionName, db);

                value = new SequenceIdGenerator();
                // doing it this way for thread safety
                _keyGeneratorsByTag = new Dictionary<string, SequenceIdGenerator>(_keyGeneratorsByTag)
                {
                    {collectionName, value}
                };
            }

            return value.GenerateId(collectionName, db);
        }
コード例 #2
0
        /// <summary>
        /// Generates the identity value
        /// </summary>
        /// <param name="db">MongoDatabase instance</param>
        /// <param name="collectionName">Collection Name</param>
        /// <returns>Generated identity</returns>
        public long GenerateId(IMongoDatabase db, string collectionName)
        {
            SequenceIdGenerator value;

            lock (_generatorLock)
            {
                if (_keyGeneratorsByTag.TryGetValue(collectionName, out value))
                {
                    return(value.GenerateId(collectionName, db));
                }

                value = new SequenceIdGenerator();
                // doing it this way for thread safety
                _keyGeneratorsByTag = new Dictionary <string, SequenceIdGenerator>(_keyGeneratorsByTag)
                {
                    { collectionName, value }
                };
            }

            return(value.GenerateId(collectionName, db));
        }