Esempio n. 1
0
        // Creates a new collection(name).
        public void CreateCollectionName(CollectionName collectionName)
        {
            using (var conn = CreateConnection())
            {
                try
                {
                    var cmd = new SqlCommand("app.usp_CreateCollectionName", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    // Here I'm creating the parameters that will be used.
                    cmd.Parameters.Add("@Collection", SqlDbType.VarChar, 60).Value = collectionName.CollectionNameText;

                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    throw new ApplicationException("An error occured when trying to add a collection to the database.");
                }
            }
        }
Esempio n. 2
0
        public void Delete(DocumentsOperationContext context, CollectionName collectionName, Slice loweredKey)
        {
            var configuration = GetVersioningConfiguration(collectionName);

            if (configuration.Active == false)
            {
                return;
            }

            if (configuration.PurgeOnDelete == false)
            {
                return;
            }

            var table        = context.Transaction.InnerTransaction.OpenTable(DocsSchema, RevisionDocuments);
            var prefixKeyMem = context.Allocator.Allocate(loweredKey.Size + 1);

            loweredKey.CopyTo(0, prefixKeyMem.Ptr, 0, loweredKey.Size);
            prefixKeyMem.Ptr[loweredKey.Size] = (byte)30; // the record separator
            var prefixSlice = new Slice(SliceOptions.Key, prefixKeyMem);

            table.DeleteForwardFrom(DocsSchema.Indexes[KeyAndEtagSlice], prefixSlice, long.MaxValue);
            DeleteCountOfRevisions(context, prefixSlice);
        }
Esempio n. 3
0
        public override void WriteTo(StringBuilder writer)
        {
            if (IndexName == null && CollectionName == null)
            {
                throw new NotSupportedException("Either IndexName or CollectionName must be specified");
            }

            if (IsDynamic)
            {
                writer
                .Append("FROM ");
                if (CollectionName.IndexOfAny(_whiteSpaceChars) != -1)
                {
                    if (CollectionName.IndexOf('"') != -1)
                    {
                        ThrowInvalidcollectionName();
                    }
                    writer.Append('"').Append(CollectionName).Append('"');
                }
                else
                {
                    WriteField(writer, CollectionName);
                }
                if (Alias != null)
                {
                    writer.Append(" as ").Append(Alias);
                }

                return;
            }

            writer
            .Append("FROM INDEX '")
            .Append(IndexName)
            .Append("'");
        }
Esempio n. 4
0
 /// <summary>
 ///     Gets the Reserve Units (RU) per second for a given collection from configuration or the default value (1000).
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <returns></returns>
 protected int GetRUsFor(CollectionName collection)
 {
     return(Configuration.Collections.FirstOrDefault(x => x.CollectionName.Equals(collection))?.ReserveUnits
            ?? Constants.DefaultReserveUnits);
 }