예제 #1
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Adds the element.
        /// </summary>
        /// <param name="id">
        ///  .
        /// </param>
        /// <param name="schemaEntity">
        ///  The meta class.
        /// </param>
        /// <returns>
        ///  The new entity.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public virtual GraphNode CreateEntity(Identity id, ISchemaEntity schemaEntity)
        {
            DebugContract.Requires(id, "id");
            DebugContract.Requires(schemaEntity);

            if (Session.Current == null)
            {
                throw new SessionRequiredException();
            }

            Session.Current.AcquireLock(LockType.Exclusive, id);

            _trace.WriteTrace(TraceCategory.Hypergraph, "Add element {0}", id);

            using (var tx = BeginTransaction())
            {
                if (CurrentTransaction != null)
                {
                    CurrentTransaction.UpdateProfiler(p => p.NodesCreated.Incr());
                    CurrentTransaction.UpdateProfiler(p => p.NumberOfNodes.Incr());
                }

                var node = new GraphNode(id, schemaEntity.Id, NodeType.Node);
                _storage.AddNode(node);

                tx.Commit();
                return(node);
            }
        }
        public override ISchemaEntity RemoveEntity(Identity id, bool throwExceptionIfNotExists)
        {
            var schema = base.RemoveEntity(id, false);

            if (schema != null)
            {
                _deletedElements.AddNode(new GraphNode(id, schema.Id, NodeType.Node));
            }
            return(schema);
        }