/// <summary>
 /// Adds a Graph to the Collection.
 /// </summary>
 /// <param name="g">Graph to add.</param>
 /// <param name="mergeIfExists">Whether to merge the given Graph with any existing Graph with the same URI.</param>
 /// <exception cref="RdfException">Thrown if a Graph with the given URI already exists and the <paramref name="mergeIfExists">mergeIfExists</paramref> is set to false.</exception>
 protected internal override bool Add(IGraph g, bool mergeIfExists)
 {
     if (Contains(g.BaseUri))
     {
         if (mergeIfExists)
         {
             IGraph temp = _dataset.GetModifiableGraph(g.BaseUri);
             temp.Merge(g);
             temp.Dispose();
             _dataset.Flush();
             return(true);
         }
         else
         {
             throw new RdfException("Cannot add this Graph as a Graph with the URI '" + g.BaseUri.ToSafeString() + "' already exists in the Collection and mergeIfExists was set to false");
         }
     }
     else
     {
         // Safe to add a new Graph
         if (_dataset.AddGraph(g))
         {
             _dataset.Flush();
             RaiseGraphAdded(g);
             return(true);
         }
         return(false);
     }
 }
Exemple #2
0
        private void TestDeleteDataThenInsertDataRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();
            IGraph         g       = dataset.GetModifiableGraph(TestGraphUri);

            g.Assert(new Triple(g.CreateUriNode(new Uri("ex:subj")), g.CreateUriNode(new Uri("ex:pred")), g.CreateUriNode(new Uri("ex:obj"))));

            String updates = "DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.True(false, "Did not thrown a SparqlUpdateException as expected");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx);
            }

            Assert.False(dataset[TestGraphUri].IsEmpty, "Graph should not be empty as the Discard() should reverse first the insert then the delete so the end results should be the triple still being in the Graph");
        }
Exemple #3
0
        /// <summary>
        /// Updates a Graph in the Store.
        /// </summary>
        /// <param name="graphUri">URI of the Graph to Update.</param>
        /// <param name="additions">Triples to be added.</param>
        /// <param name="removals">Triples to be removed.</param>
        public override void UpdateGraph(Uri graphUri, IEnumerable <Triple> additions, IEnumerable <Triple> removals)
        {
            if (!_dataset.HasGraph(graphUri))
            {
                Graph temp = new Graph();
                temp.BaseUri = graphUri;
                _dataset.AddGraph(temp);
            }

            if ((additions != null && additions.Any()) || (removals != null && removals.Any()))
            {
                IGraph g = _dataset.GetModifiableGraph(graphUri);
                if (additions != null && additions.Any())
                {
                    g.Assert(additions.ToList());
                }
                if (removals != null && removals.Any())
                {
                    g.Retract(removals.ToList());
                }
            }

            _dataset.Flush();
        }
Exemple #4
0
        private void TestDeleteDataThenInsertDataCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();
            IGraph         g       = dataset.GetModifiableGraph(TestGraphUri);

            g.Assert(new Triple(g.CreateUriNode(new Uri("ex:subj")), g.CreateUriNode(new Uri("ex:pred")), g.CreateUriNode(new Uri("ex:obj"))));
            dataset.Flush();

            String updates = "DELETE DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlUpdateCommandSet cmds = this._parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.False(dataset[TestGraphUri].IsEmpty, "Graph should not be empty as the Flush() should persist first the delete then the insert so the end results should be the triple still being in the Graph");
        }
Exemple #5
0
 /// <summary>
 /// Gets a modifiable graph from the dataset.
 /// </summary>
 /// <param name="graphUri">Graph URI.</param>
 /// <returns></returns>
 public virtual IGraph GetModifiableGraph(Uri graphUri)
 {
     return(_dataset.GetModifiableGraph(graphUri));
 }