Ejemplo n.º 1
0
        /// <summary>
        /// Insert a new entity into the database and return the modified entity
        /// </summary>
        public virtual void Insert(Entity entity)
        {
            string type = EntityUtils.GetEntityStringType(entity.GetType());

            if (!string.IsNullOrEmpty(entity.EntityKey))
            {
                throw new ArgumentException(
                          "Provided entity has already been inserted"
                          );
            }

            try
            {
                AttemptInsert(type, entity);
            }
            catch (ArangoException e) when(e.ErrorNumber == 1203)
            {
                // collection not found -> create it
                arango.CreateCollection(
                    EntityUtils.CollectionFromType(type),
                    CollectionType.Document
                    );

                AttemptInsert(type, entity);
            }
        }
        /// <summary>
        /// Creates the sessions collection
        /// </summary>
        private void CreateCollection()
        {
            arango.CreateCollection(CollectionName, CollectionType.Document);

            log.Info(
                $"[Unisave] {CollectionName} collection has been created. " +
                "This collection is used for storing session data."
                );

            arango.CreateIndex(
                CollectionName,
                IndexType.TTL,
                new string[] { "expiresAt" },
                new JsonObject()
                .Add("expireAfter", 0)
                );

            log.Info(
                $"[Unisave] TTL index on collection {CollectionName} has " +
                "been created. It makes sure that old sessions get deleted."
                );
        }