/// <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);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Flushes any outstanding changes to the underlying dataset.
 /// </summary>
 public void Flush()
 {
     if (!_canCommit)
     {
         throw new SparqlUpdateException("Unable to commit since one/more Commands executed in the current Transaction failed");
     }
     _dataset.Flush();
 }
Esempio n. 3
0
 /// <summary>
 /// Saves a Graph to the Store.
 /// </summary>
 /// <param name="g">Graph.</param>
 public override void SaveGraph(IGraph g)
 {
     if (_dataset.HasGraph(g.BaseUri))
     {
         _dataset.RemoveGraph(g.BaseUri);
     }
     _dataset.AddGraph(g);
     _dataset.Flush();
 }
Esempio n. 4
0
 /// <summary>
 /// Creates a new Leviathan Update Processor.
 /// </summary>
 /// <param name="data">SPARQL Dataset.</param>
 public LeviathanUpdateProcessor(ISparqlDataset data)
 {
     _dataset = data;
     if (!_dataset.HasGraph(null))
     {
         // Create the Default unnamed Graph if it doesn't exist and then Flush() the change
         _dataset.AddGraph(new Graph());
         _dataset.Flush();
     }
 }
Esempio n. 5
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");
        }
Esempio n. 6
0
 /// <summary>
 /// Flushes any changes to the dataset.
 /// </summary>
 public virtual void Flush()
 {
     _dataset.Flush();
 }