示例#1
0
        public WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern, bool needResult)
        {
            var predicate = QueryCompiler.GetFunction(query.ToBsonDocument());

            int documentsAffected = 0;

            for (int i = 0; i < Documents.Count; ++i)
            {
                if (!predicate(Documents[i]))
                {
                    continue;
                }

                RemoveDocumentAt(i);

                ++documentsAffected;

                if ((flags & RemoveFlags.Single) > 0)
                {
                    break;
                }

                --i;
            }

            return(needResult ? new WriteConcernResult(NewResponse(documentsAffected, false, null, null)) : null);
        }
 // constructors
 internal MongoDeleteMessage(BsonBinaryWriterSettings writerSettings, string collectionFullName, RemoveFlags flags, IMongoQuery query)
     : base(MessageOpcode.Delete, null, writerSettings)
 {
     this.collectionFullName = collectionFullName;
     this.flags = flags;
     this.query = query;
 }
示例#3
0
 protected override void BeginProcessing()
 {
     if (One)
     {
         _Flags |= RemoveFlags.Single;
     }
 }
 // constructors
 internal MongoDeleteMessage(BsonBinaryWriterSettings writerSettings, string collectionFullName, RemoveFlags flags, IMongoQuery query)
     : base(MessageOpcode.Delete, null, writerSettings)
 {
     _collectionFullName = collectionFullName;
     _flags = flags;
     _query = query;
 }
 internal MongoDeleteMessage(
     string collectionFullName,
     RemoveFlags flags,
     object query
 )
     : base(MessageOpcode.Delete)
 {
     this.collectionFullName = collectionFullName;
     this.flags = flags;
     this.query = query;
 }
 internal MongoDeleteMessage(
     MongoServer server,
     string collectionFullName,
     RemoveFlags flags,
     IMongoQuery query
 ) :
     base(server, MessageOpcode.Delete) {
     this.collectionFullName = collectionFullName;
     this.flags = flags;
     this.query = query;
 }
示例#7
0
        public override SafeModeResult Remove(IMongoQuery query, RemoveFlags flags, SafeMode safeMode)
        {
            if (writer != null)
            {
                this.writer.WriteLine("Remove Query:");
                this.writer.WriteLine(query == null ? "Null" : query.ToString());
                this.writer.WriteLine();
                this.writer.Flush();
            }

            return(mCollection.Remove(query, flags, safeMode));
        }
示例#8
0
 internal MongoDeleteMessage(
     MongoConnection connection,
     string collectionFullName,
     RemoveFlags flags,
     IMongoQuery query
     ) :
     base(connection, MessageOpcode.Delete)
 {
     this.collectionFullName = collectionFullName;
     this.flags = flags;
     this.query = query;
 }
 public RemoveOperation(
     string databaseName,
     string collectionName,
     BsonBinaryReaderSettings readerSettings,
     BsonBinaryWriterSettings writerSettings,
     WriteConcern writeConcern,
     IMongoQuery query,
     RemoveFlags flags)
     : base(databaseName, collectionName, readerSettings, writerSettings, writeConcern)
 {
     _query = query;
     _flags = flags;
 }
 public RemoveOperation(
     string databaseName,
     string collectionName,
     BsonBinaryReaderSettings readerSettings,
     BsonBinaryWriterSettings writerSettings,
     WriteConcern writeConcern,
     IMongoQuery query,
     RemoveFlags flags)
     : base(databaseName, collectionName, readerSettings, writerSettings, writeConcern)
 {
     _query = query;
     _flags = flags;
 }
示例#11
0
 // constructors
 internal MongoDeleteMessage(
     BsonBinaryWriterSettings writerSettings,
     string collectionFullName,
     RemoveFlags flags,
     int maxDocumentSize,
     IMongoQuery query)
     : base(MessageOpcode.Delete, writerSettings)
 {
     _collectionFullName = collectionFullName;
     _flags           = flags;
     _maxDocumentSize = maxDocumentSize;
     _query           = query;
 }
示例#12
0
        public override WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern)
        {
            var sw = new Stopwatch();

            sw.Start();
            var result = base.Remove(query, flags, writeConcern);

            sw.Stop();

            var commandStringBuilder = new StringBuilder(1024);

            commandStringBuilder.AppendFormat("db.{0}.remove", Name);

            if (query == null)
            {
                if ((flags & RemoveFlags.None) == RemoveFlags.None)
                {
                    commandStringBuilder.Append("()");
                }
                else if ((flags & RemoveFlags.Single) == RemoveFlags.Single)
                {
                    commandStringBuilder.Append("({}, true)");
                }
            }
            else
            {
                commandStringBuilder.Append("(");
                commandStringBuilder.AppendFormat("query");

                if ((flags & RemoveFlags.Single) == RemoveFlags.Single)
                {
                    commandStringBuilder.Append(", true");
                }

                commandStringBuilder.Append(")");

                commandStringBuilder.AppendFormat("\nquery = {0}", query.ToBsonDocument());
            }

            string commandString = commandStringBuilder.ToString();

            ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Create);

            return(result);
        }
示例#13
0
        public void Remove(Txn txn, RemoveFlags flags)
        {
            DbRetVal ret;

            if (txn != null)
            {
                lock (txn.rscLock) {
                    DB_TXN *txp = txn.CheckDisposed();
                    ret = Remove(txp, flags);
                }
            }
            else
            {
                ret = Remove((DB_TXN *)null, flags);
            }
            GC.SuppressFinalize(this);
            Util.CheckRetVal(ret);
        }
示例#14
0
        DbRetVal Remove(DB_TXN *txp, RemoveFlags flags)
        {
            DbRetVal ret;

            // always lock Db first, to avoid deadlock
            lock (db.rscLock) {
                lock (rscLock) {
                    RuntimeHelpers.PrepareConstrainedRegions();
                    try { }
                    finally {
                        DB_SEQUENCE *seqp = CheckDisposed();
                        // DB_SEQUENCE->Remove() could be a lengthy call, so we call Disposed() first, and the
                        // CER ensures that we reach DB_SEQUENCE->Remove() without external interruption.
                        // This is OK because one must not use the handle after DB_SEQUENCE->Remove() was called,
                        // regardless of the return value.
                        Disposed();
                        ret = seqp->Remove(seqp, txp, unchecked ((UInt32)flags));
                    }
                }
            }
            return(ret);
        }
示例#15
0
 /// <summary>
 /// Delete
 /// </summary>
 /// <typeparam name="T">Date Type</typeparam>
 /// <param name="query">Query information</param>
 /// <param name="removeFlag">remove flag</param>
 public SafeModeResult Remove <T>(IMongoQuery query, RemoveFlags removeFlag) where T : class, new()
 {
     return(this.GetCollection <T>().Remove(query, removeFlag, this._SafeMode));
 }
示例#16
0
        /// <summary>
        /// Note:  Before/After delete do not get called with this method
        /// </summary>
        /// <param name="query"></param>
        /// <param name="flags"></param>
        /// <param name="writeConcern"></param>
        /// <returns></returns>
        public WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.Remove(fixedQuery, flags, writeConcern));
        }
 public void Remove(Txn txn, RemoveFlags flags) {
   DbRetVal ret;
   if (txn != null) {
     lock (txn.rscLock) {
       DB_TXN* txp = txn.CheckDisposed();
       ret = Remove(txp, flags);
     }
   }
   else
     ret = Remove((DB_TXN*)null, flags);
   GC.SuppressFinalize(this);
   Util.CheckRetVal(ret);
 }
示例#18
0
 protected override void BeginProcessing()
 {
     if (One)
         _Flags |= RemoveFlags.Single;
 }
示例#19
0
    public void Remove(string home, RemoveFlags flags) {
      byte[] hBytes = null;
      Util.StrToUtf8(home, ref hBytes);

      DbRetVal ret;
      lock (rscLock) {
        RuntimeHelpers.PrepareConstrainedRegions();
        try { }
        finally {
          DB_ENV* evp = CheckDisposed();
          DisposeDependents(true);
          // DB_ENV->Remove() could be a lengthy call, so we call Disposed() first, and the
          // CER ensures that we reach DB_ENV->Remove() without external interruption.
          // This is OK because one must not use the handle after DB_ENV->Remove() was called,
          // regardless of the return value.
          Disposed();
          fixed (byte* hp = hBytes) {
            ret = evp->Remove(evp, hp, unchecked((UInt32)flags));
          }
        }
      }
      GC.SuppressFinalize(this);
      Util.CheckRetVal(ret);
    }
示例#20
0
 public Task <WriteConcernResult> RemoveAsync <T>(string collectionName, IMongoQuery query, RemoveFlags removeFlags, WriteConcern writeConcern)
 {
     return(_asyncUpdater.RemoveAsync <T>(collectionName, query, removeFlags, writeConcern));
 }
 public void RemoveAsync <T>(string collectionName, IMongoQuery query, RemoveFlags removeFlags, WriteConcern writeConcern)
 {
     new Func <string, IMongoQuery, RemoveFlags, WriteConcern, WriteConcernResult>(_updater.Remove <T>).BeginInvoke(collectionName, query, removeFlags, writeConcern, CallbackwriteConcernResult, null);
 }
示例#22
0
        public WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern, bool needResult)
        {
            var predicate = QueryCompiler.GetFunction((IConvertibleToBsonDocument)query);

            int documentsAffected = 0;

            for (int i = 0; i < Documents.Count; ++i)
            {
                if (!predicate(Documents[i]))
                    continue;

                RemoveDocumentAt(i);

                ++documentsAffected;

                if ((flags & RemoveFlags.Single) > 0)
                    break;

                --i;
            }

            return needResult ? new WriteConcernResult(NewResponse(documentsAffected, false, null, null)) : null;
        }
示例#23
0
 public WriteConcernResult Remove <T>(string collectionName, IMongoQuery query, RemoveFlags removeFlags, WriteConcern writeConcern)
 {
     return(_updater.Remove <T>(collectionName, query, removeFlags, writeConcern));
 }
 DbRetVal Remove(DB_TXN* txp, RemoveFlags flags) {
   DbRetVal ret;
   // always lock Db first, to avoid deadlock
   lock (db.rscLock) {
     lock (rscLock) {
       RuntimeHelpers.PrepareConstrainedRegions();
       try { }
       finally {
         DB_SEQUENCE* seqp = CheckDisposed();
         // DB_SEQUENCE->Remove() could be a lengthy call, so we call Disposed() first, and the
         // CER ensures that we reach DB_SEQUENCE->Remove() without external interruption.
         // This is OK because one must not use the handle after DB_SEQUENCE->Remove() was called,
         // regardless of the return value.
         Disposed();
         ret = seqp->Remove(seqp, txp, unchecked((UInt32)flags));
       }
     }
   }
   return ret;
 }
示例#25
0
 public WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern, bool needResult)
 {
     return(_this.Remove(query, flags, writeConcern));
 }
示例#26
0
 public WriteConcernResult Remove <T>(IMongoQuery query, RemoveFlags removeFlags)
 {
     return(_databaseUpdater.Remove <T>(_collectionName, query, removeFlags));
 }
示例#27
0
        public WriteConcernResult Remove <T>(string collectionName, IMongoQuery query, RemoveFlags removeFlags, WriteConcern writeConcern)
        {
            var collection = GetCollection <T>(collectionName);

            return(collection.Remove(query, removeFlags, writeConcern));
        }
示例#28
0
 public Task <WriteConcernResult> RemoveAsync <T>(IMongoQuery query, RemoveFlags removeFlags, WriteConcern writeConcern)
 {
     return(_databaseUpdater.RemoveAsync <T>(_collectionName, query, removeFlags, writeConcern));
 }
示例#29
0
        public static Task <SafeModeResult> RemoveAsync(this MongoCollection collection, IMongoQuery query, RemoveFlags flags, SafeMode safeMode)
        {
            var tcs = new TaskCompletionSource <SafeModeResult>();

            ThreadPool.QueueUserWorkItem(_ =>
            {
                try
                {
                    var result = collection.Remove(query, flags, safeMode);
                    tcs.SetResult(result);
                }
                catch (Exception exc)
                {
                    tcs.SetException(exc);
                }
            });
            return(tcs.Task);
        }
示例#30
0
 public Task <WriteConcernResult> RemoveAsync <T>(string collectionName, IMongoQuery query, RemoveFlags removeFlags)
 {
     return(Task.Run(() => { return _updater.Remove <T>(collectionName, query, removeFlags); }));
 }
示例#31
0
 public WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern, bool needResult)
 {
     return _this.Remove(query, flags, writeConcern);
 }
示例#32
0
 public SafeModeResult Remove(IMongoQuery query, RemoveFlags flags, SafeMode safeMode)
 {
     return(_collection.Remove(query, flags, safeMode));
 }