public void SparqlUpdateInsertCommand2()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText  = "INSERT { ?s rdf:type ?class } USING <http://example.org/temp> WHERE { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } USING <http://example.org/temp> WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } USING <http://example.org/temp> WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } USING <http://example.org/temp> WHERE { ?s rdfs:subPropertyOf ?property };";

            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            FileLoader.Load(g, "resources\\InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/temp");
            store.Add(g);
            int origTriples = g.Triples.Count;

            SparqlUpdateParser       parser    = new SparqlUpdateParser();
            SparqlUpdateCommandSet   cmds      = parser.ParseFromString(command);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(cmds);

            Assert.Equal(origTriples, g.Triples.Count);

            IGraph def = store[null];

            TestTools.ShowGraph(def);
            Console.WriteLine();

            //Apply a RDFS reasoner over the original input and output it into another graph
            //Should be equivalent to the default Graph
            Graph        h        = new Graph();
            RdfsReasoner reasoner = new RdfsReasoner();

            reasoner.Apply(g, h);

            TestTools.ShowGraph(h);

            GraphDiffReport report = h.Difference(def);

            if (!report.AreEqual)
            {
                TestTools.ShowDifferences(report);

                Assert.True(report.RemovedTriples.Count() == 1, "Should have only 1 missing Triple (due to rdfs:domain inference which is hard to encode in an INSERT command)");
            }
        }
Beispiel #2
0
        private void TestInsertDataThenDeleteDataCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; DELETE 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.IsTrue(dataset[TestGraphUri].IsEmpty, "Graph should be empty as the Flush() should persist first the insert then the delete");
        }
Beispiel #3
0
        private void TestInsertDataSequenceCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { } }; 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.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should exist");
            Assert.AreEqual(1, dataset[TestGraphUri].Triples.Count, "Expected 1 Triple");
        }
Beispiel #4
0
        private void TestInsertDataThenDropCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subject> <ex:predicate> <ex:object> } }; DROP GRAPH <" + TestGraphUri.ToString() + ">";

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

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.IsFalse(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Flush() should cause it to be removed from the Dataset");
        }
Beispiel #5
0
        private void TestCreateDropSequenceCommit2()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "CREATE GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">";

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

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.IsFalse(dataset.HasGraph(TestGraphUri), "Graph should not exist");
        }
Beispiel #6
0
        private void TestLoadCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "LOAD <http://www.dotnetrdf.org/configuration#> INTO GRAPH <" + TestGraphUri.ToString() + ">";

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

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.IsTrue(dataset.HasGraph(TestGraphUri), "Graph should exist");
        }
Beispiel #7
0
        /// <summary>
        /// Processes a command set
        /// </summary>
        /// <param name="commands">Command Set</param>
        public void ProcessCommandSet(SparqlUpdateCommandSet commands)
        {
            DateTime start = DateTime.Now;

            commands.UpdateExecutionTime = null;
            try
            {
                _store.ExecuteUpdate(commands);
            }
            finally
            {
                TimeSpan elapsed = (DateTime.Now - start);
                commands.UpdateExecutionTime = elapsed;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Processes a command set
        /// </summary>
        /// <param name="commands">Command Set</param>
        public void ProcessCommandSet(SparqlUpdateCommandSet commands)
        {
            DateTime start = DateTime.Now;

            commands.UpdateExecutionTime = null;
            try
            {
                this._endpoint.Update(commands.ToString());
            }
            finally
            {
                TimeSpan elapsed = (DateTime.Now - start);
                commands.UpdateExecutionTime = elapsed;
            }
        }
Beispiel #9
0
        private void TestDropGraphCommit()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">";

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(updates);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Assert.False(dataset.HasGraph(TestGraphUri), "Graph should not exist");
        }
Beispiel #10
0
        public void SparqlUpdateInsertCommand()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText  = "INSERT { ?s rdf:type ?class } WHERE { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } WHERE { ?s rdfs:subPropertyOf ?property };";

            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            FileLoader.Load(g, "InferenceTest.ttl");
            g.Retract(g.Triples.Where(t => !t.IsGroundTriple).ToList());
            g.BaseUri = null;
            store.Add(g);

            SparqlUpdateParser       parser    = new SparqlUpdateParser();
            SparqlUpdateCommandSet   cmds      = parser.ParseFromString(command);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(cmds);

            TestTools.ShowGraph(g);
            Console.WriteLine();

            //Now reload the test data and apply an RDFS reasoner over it
            //This should give us a Graph equivalent to the one created by the previous INSERT commands
            Graph h = new Graph();

            FileLoader.Load(h, "InferenceTest.ttl");
            h.Retract(h.Triples.Where(t => !t.IsGroundTriple).ToList());
            RdfsReasoner reasoner = new RdfsReasoner();

            reasoner.Apply(h);

            GraphDiffReport diff = h.Difference(g);

            if (!diff.AreEqual)
            {
                TestTools.ShowDifferences(diff);
            }

            Assert.AreEqual(h, g, "Graphs should be equal");
        }
Beispiel #11
0
        public void SparqlUpdateGenericCreateAndInsertData()
        {
            IStorageProvider       manager   = this.GetManager();
            GenericUpdateProcessor processor = new GenericUpdateProcessor(manager);
            SparqlUpdateCommandSet cmds      = this._parser.ParseFromString("CREATE GRAPH <http://example.org/sparqlUpdate/created>; INSERT DATA { GRAPH <http://example.org/sparqlUpdate/created> { <http://example.org/s> <http://example.org/p> <http://example.org/o> } }");

            processor.ProcessCommandSet(cmds);

            Graph g = new Graph();

            manager.LoadGraph(g, "http://example.org/sparqlUpdate/created");

            TestTools.ShowGraph(g);

            Assert.IsFalse(g.IsEmpty, "[" + manager.ToString() + "] Graph should not be empty");
            Assert.AreEqual(1, g.Triples.Count, "[" + manager.ToString() + "] Graph should have 1 Triple");
        }
Beispiel #12
0
        public void SparqlUpdateLoadQuads2()
        {
            var tripleStore             = new TripleStore();
            SparqlUpdateCommandSet cmds = this._parser.ParseFromFile(@"resources\core-421\test2.ru");

            tripleStore.ExecuteUpdate(cmds);
            Assert.That(tripleStore.Triples.ToList(), Has.Count.EqualTo(3));
            Assert.That(tripleStore.Graphs, Has.Count.EqualTo(3));

            tripleStore.SaveToFile("core-421.nq", new NQuadsWriter());

            var newStore = new TripleStore();

            newStore.LoadFromFile("core-421.nq", new NQuadsParser());

            Assert.That(newStore.Triples.ToList(), Has.Count.EqualTo(3));
            Assert.That(newStore.Graphs, Has.Count.EqualTo(2));
        }
Beispiel #13
0
        public void SparqlUpdateWithCustomQueryProcessor()
        {
            Graph g = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = null;
            TripleStore store = new TripleStore();

            store.Add(g);
            InMemoryDataset dataset = new InMemoryDataset(store);

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString("DELETE { ?s a ?type } WHERE { ?s a ?type }");

            ISparqlUpdateProcessor processor = new ExplainUpdateProcessor(dataset, ExplanationLevel.Full);

            processor.ProcessCommandSet(cmds);
        }
Beispiel #14
0
        public void SparqlUpdateLoadQuads3()
        {
            var tripleStore             = new TripleStore();
            SparqlUpdateCommandSet cmds = this._parser.ParseFromFile(@"resources\core-421\test3.ru");

            tripleStore.ExecuteUpdate(cmds);
            Assert.Equal(3, tripleStore.Triples.Count());
            Assert.Equal(3, tripleStore.Graphs.Count);

            tripleStore.SaveToFile("core-421.nq", new NQuadsWriter());

            var newStore = new TripleStore();

            newStore.LoadFromFile("core-421.nq", new NQuadsParser());

            Assert.Equal(3, newStore.Triples.Count());
            Assert.Equal(2, newStore.Graphs.Count);
        }
Beispiel #15
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");
        }
Beispiel #16
0
        public void SparqlUpdateDeleteDataCombination()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();

            command.Namespaces.AddNamespace("ex", new Uri("http://example.org/"));
            command.CommandText = "DELETE DATA { ex:a ex:b ex:c GRAPH <http://example.org/graph> { ex:a ex:b ex:c } }";

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(command);

            Assert.IsFalse(cmds.Commands.All(cmd => cmd.AffectsSingleGraph), "Commands should report that they do not affect a single Graph");
            Assert.IsTrue(cmds.Commands.All(cmd => cmd.AffectsGraph(null)), "Commands should report that they affect the Default Graph");
            Assert.IsTrue(cmds.Commands.All(cmd => cmd.AffectsGraph(new Uri("http://example.org/graph"))), "Commands should report that they affect the named Graph");

            InMemoryDataset dataset = new InMemoryDataset();
            IGraph          def     = new Graph();

            def.NamespaceMap.Import(command.Namespaces);
            def.Assert(new Triple(def.CreateUriNode("ex:a"), def.CreateUriNode("ex:b"), def.CreateUriNode("ex:c")));
            dataset.AddGraph(def);
            IGraph ex = new Graph();

            ex.BaseUri = new Uri("http://example.org/graph");
            ex.NamespaceMap.Import(command.Namespaces);
            ex.Assert(new Triple(ex.CreateUriNode("ex:a"), ex.CreateUriNode("ex:b"), ex.CreateUriNode("ex:c")));
            dataset.AddGraph(ex);

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            processor.ProcessCommandSet(cmds);

            Graph g = new Graph();

            g.NamespaceMap.Import(command.Namespaces);
            Triple t = new Triple(g.CreateUriNode("ex:a"), g.CreateUriNode("ex:b"), g.CreateUriNode("ex:c"));

            def = dataset[null];
            Assert.AreEqual(0, def.Triples.Count, "Should be 0 Triples in the Default Graph");
            Assert.IsFalse(def.ContainsTriple(t), "Should not have the deleted Triple in the Default Graph");

            ex = dataset[new Uri("http://example.org/graph")];
            Assert.AreEqual(0, ex.Triples.Count, "Should be 0 Triples in the Named Graph");
            Assert.IsFalse(ex.ContainsTriple(t), "Should not have the deleted Triple in the Named Graph");
        }
Beispiel #17
0
        public void SparqlUpdateModify()
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            FileLoader.Load(g, "resources\\InferenceTest.ttl");
            g.BaseUri = null;
            store.Add(g);

            IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));

            Assert.NotEmpty(store.GetTriplesWithPredicate(rdfType));

            String                 update = "DELETE {?s a ?type} WHERE {?s a ?type}";
            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(update);

            store.ExecuteUpdate(cmds);

            Assert.Empty(store.GetTriplesWithPredicate(rdfType));
        }
Beispiel #18
0
        public void SparqlUpdateModify()
        {
            TripleStore store = new TripleStore();
            Graph       g     = new Graph();

            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = null;
            store.Add(g);

            IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));

            Assert.AreNotEqual(0, store.GetTriplesWithPredicate(rdfType).Count(), "Store should contain some rdf:type Triples");

            String                 update = "DELETE {?s a ?type} WHERE {?s a ?type}";
            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(update);

            store.ExecuteUpdate(cmds);

            Assert.AreEqual(0, store.GetTriplesWithPredicate(rdfType).Count(), "Store should contain no rdf:type Triples after DELETE command executes");
        }
Beispiel #19
0
        private void TestCreateGraphRollback()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "CREATE GRAPH <" + TestGraphUri.ToString() + ">; 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.HasGraph(TestGraphUri), "Graph should not exist as the Discard() should cause it to be removed from the Dataset");
        }
Beispiel #20
0
        private void TestInsertDataThenDeleteDataRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subj> <ex:pred> <ex:obj> } }; DELETE 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.True(dataset[TestGraphUri].IsEmpty, "Graph should be empty as the Discard() should reverse first the delete then the insert");
        }
Beispiel #21
0
        private void TestCreateDropSequenceRollback2()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">; CREATE GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">; DROP GRAPH <" + TestGraphUri.ToString() + ">";

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

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

            try
            {
                processor.ProcessCommandSet(cmds);
                Assert.True(false, "Expected SPARQL Update Exception was not thrown");
            }
            catch (SparqlUpdateException upEx)
            {
                TestTools.ReportError("Update Exception", upEx);
            }

            Assert.True(dataset.HasGraph(TestGraphUri), "Graph should not exist");
        }
Beispiel #22
0
        private void TestDropGraphRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">; DROP 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.True(dataset.HasGraph(TestGraphUri), "Graph should exist as the Discard() should ensure it was still in the Dataset");
        }
Beispiel #23
0
        private void TestCreateGraphRollbackWithoutAutoCommit()
        {
            ISparqlDataset dataset = this.GetEmptyDataset();

            String updates = "CREATE GRAPH <" + TestGraphUri.ToString() + ">; CREATE GRAPH <" + TestGraphUri.ToString() + ">";

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

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);

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

            Assert.True(dataset.HasGraph(TestGraphUri), "Graph should exist as the Transaction has not been committed yet as Auto-Commit is off");

            //Try to Flush() which should error
            try
            {
                processor.Flush();
                Assert.True(false, "Did not throw a SparqlUpdateException as expected on call to Flush()");
            }
            catch (SparqlUpdateException upEx)
            {
                Console.WriteLine("Threw error when attempting to Flush() as expected");
                TestTools.ReportError("Update Exception", upEx);
            }

            //Now discard
            processor.Discard();
            Assert.False(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Discard() should cause it to be removed from the Dataset");
        }
Beispiel #24
0
        private void TestDropThenInsertDataRollback()
        {
            ISparqlDataset dataset = this.GetNonEmptyDataset();

            String updates = "DROP GRAPH <" + TestGraphUri.ToString() + ">; INSERT DATA { GRAPH <" + TestGraphUri.ToString() + "> { <ex:subject> <ex:predicate> <ex:object> } }; 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.True(dataset.HasGraph(TestGraphUri), "Graph should not exist as the Discard() should cause it to be removed from the Dataset");
            Assert.True(dataset[TestGraphUri].IsEmpty, "Graph should be empty as the Discard() should have reversed the INSERT DATA");
        }
Beispiel #25
0
        public void SparqlUpdateMoveCommand3()
        {
            IGraph g = new Graph();

            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = null;

            IGraph h = new Graph();

            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = new Uri("http://example.org/destination");

            TripleStore store = new TripleStore();

            store.Add(g);
            store.Add(h);

            Assert.AreNotEqual(g, h, "Graphs should not be equal");

            SparqlUpdateParser     parser   = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("MOVE DEFAULT TO GRAPH <http://example.org/destination>");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(commands);

            g = store.HasGraph(null) ? store[null] : null;
            h = store[new Uri("http://example.org/destination")];
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.IsFalse(g == null, "Default Graph should still exist");
            Assert.IsTrue(g.IsEmpty, "Source Graph (the Default Graph) should be Empty");

            Graph orig = new Graph();

            FileLoader.Load(orig, "InferenceTest.ttl");
            Assert.AreEqual(orig, h, "Destination Graph should be equal to the original contents of the Source Graph");
        }
Beispiel #26
0
        public void SparqlUpdateMoveCommand2()
        {
            IGraph g = new Graph();

            FileLoader.Load(g, "resources\\InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/source");

            IGraph h = new Graph();

            FileLoader.Load(h, "resources\\Turtle.ttl");
            h.BaseUri = null;

            TripleStore store = new TripleStore();

            store.Add(g);
            store.Add(h);

            Assert.NotEqual(g, h);

            SparqlUpdateParser     parser   = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("MOVE GRAPH <http://example.org/source> TO DEFAULT");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);

            processor.ProcessCommandSet(commands);

            g = store.HasGraph(new Uri("http://example.org/source")) ? store[new Uri("http://example.org/source")] : null;
            h = store[null];
            Assert.False(h.IsEmpty, "Destination Graph should not be empty");
            Assert.True(g == null || g.IsEmpty, "Source Graph should be Deleted/Empty");

            Graph orig = new Graph();

            FileLoader.Load(orig, "resources\\InferenceTest.ttl");
            Assert.Equal(orig, h);
        }
        /// <summary>
        /// Processes a command set
        /// </summary>
        /// <param name="commands">Command Set</param>
        /// <remarks>
        /// Invokes <see cref="LeviathanUpdateProcessor.ProcessCommand">ProcessCommand()</see> on each command in turn
        /// </remarks>
        public void ProcessCommandSet(SparqlUpdateCommandSet commands)
        {
            commands.UpdateExecutionTime = null;

            //Firstly check what Transaction mode we are running in
            bool autoCommit = this._autoCommit;

            //Then create an Evaluation Context
            SparqlUpdateEvaluationContext context = this.GetContext(commands);

            //Remember to handle the Thread Safety
            //If the Dataset is Thread Safe use its own lock otherwise use our local lock
            #if !NO_RWLOCK
            ReaderWriterLockSlim currLock = (this._dataset is IThreadSafeDataset) ? ((IThreadSafeDataset)this._dataset).Lock : this._lock;
            #endif
            try
            {
            #if !NO_RWLOCK
                currLock.EnterWriteLock();
            #else
                //Have to make do with a Monitor if ReaderWriterLockSlim is not available
                Monitor.Enter(this._dataset);
            #endif

                //Regardless of the Transaction Mode we turn auto-commit off for a command set so that individual commands
                //don't try and commit after each one is applied i.e. either we are in auto-commit mode and all the
                //commands must be evaluated before flushing/discarding the changes OR we are not in auto-commit mode
                //so turning it off doesn't matter as it is already turned off
                this._autoCommit = false;

                if (autoCommit)
                {
                    //Do a Flush() before we start to ensure changes from any previous commands are persisted
                    this._dataset.Flush();
                }

                //Start the operation
                context.StartExecution();
                for (int i = 0; i < commands.CommandCount; i++)
                {
                    this.ProcessCommandInternal(commands[i], context);

                    //Check for Timeout
                    context.CheckTimeout();
                }

                if (autoCommit)
                {
                    //Do a Flush() when command set completed successfully to persist the changes
                    this._dataset.Flush();
                }

                //Set Update Times
                context.EndExecution();
                commands.UpdateExecutionTime = new TimeSpan(context.UpdateTimeTicks);
            }
            catch
            {
                if (autoCommit)
                {
                    //Do a Discard() when a command set fails to discard the changes
                    this._dataset.Discard();
                }
                else
                {
                    this._canCommit = false;
                }

                //Set Update Times
                context.EndExecution();
                commands.UpdateExecutionTime = new TimeSpan(context.UpdateTimeTicks);
                throw;
            }
            finally
            {
                //Reset auto-commit setting and release our write lock
                this._autoCommit = autoCommit;
            #if !NO_RWLOCK
                currLock.ExitWriteLock();
            #else
                Monitor.Exit(this._dataset);
            #endif
            }
        }
Beispiel #28
0
 /// <summary>
 /// Determines whether the Optimiser can be applied to a given Update Command Set
 /// </summary>
 /// <param name="cmds">Command Set</param>
 /// <returns></returns>
 public abstract bool IsApplicable(SparqlUpdateCommandSet cmds);
 /// <summary>
 /// Executes a SPARQL Update on the Virtuoso store
 /// </summary>
 /// <param name="updates">SPARQL Updates</param>
 /// <remarks>
 /// <para>
 /// <strong>Warning:</strong> In rare cases we have been able to crash Virtuoso by issuing malformed Sparql Update commands to it, this appears to be an issue with Virtuoso.
 /// </para>
 /// </remarks>
 public void ExecuteUpdate(SparqlUpdateCommandSet updates)
 {
     this._manager.Update(updates.ToString());
 }
 /// <summary>
 /// Creates a new Evaluation Context
 /// </summary>
 /// <param name="cmds">Update Commands</param>
 /// <returns></returns>
 protected SparqlUpdateEvaluationContext GetContext(SparqlUpdateCommandSet cmds)
 {
     return new SparqlUpdateEvaluationContext(cmds, this._dataset, this.GetQueryProcessor());
 }
 /// <summary>
 /// Creates a new SPARQL Update Evaluation Context.
 /// </summary>
 /// <param name="commands">Command Set.</param>
 /// <param name="data">SPARQL Dataset.</param>
 /// <param name="processor">Query Processor for WHERE clauses.</param>
 public SparqlUpdateEvaluationContext(SparqlUpdateCommandSet commands, ISparqlDataset data, ISparqlQueryAlgebraProcessor <BaseMultiset, SparqlEvaluationContext> processor)
     : this(commands, data)
 {
     QueryProcessor = processor;
 }
 /// <summary>
 /// Processes a command set
 /// </summary>
 /// <param name="commands">Command Set</param>
 public void ProcessCommandSet(SparqlUpdateCommandSet commands)
 {
     DateTime start = DateTime.Now;
     commands.UpdateExecutionTime = null;
     try
     {
         this._store.ExecuteUpdate(commands);
     }
     finally
     {
         TimeSpan elapsed = (DateTime.Now - start);
         commands.UpdateExecutionTime = elapsed;
     }
 }
Beispiel #33
0
 /// <summary>
 /// Creates a new Evaluation Context.
 /// </summary>
 /// <param name="cmds">Update Commands.</param>
 /// <returns></returns>
 protected SparqlUpdateEvaluationContext GetContext(SparqlUpdateCommandSet cmds)
 {
     return(new SparqlUpdateEvaluationContext(cmds, _dataset, GetQueryProcessor()));
 }
 /// <summary>
 /// Creates a new SPARQL Update Evaluation Context
 /// </summary>
 /// <param name="commands">Command Set</param>
 /// <param name="data">SPARQL Dataset</param>
 /// <param name="processor">Query Processor for WHERE clauses</param>
 public SparqlUpdateEvaluationContext(SparqlUpdateCommandSet commands, ISparqlDataset data, ISparqlQueryAlgebraProcessor<BaseMultiset, SparqlEvaluationContext> processor)
     : this(commands, data)
 {
     this.QueryProcessor = processor;
 }
Beispiel #35
0
 /// <summary>
 /// Processes a command set
 /// </summary>
 /// <param name="commands">Command Set</param>
 /// <remarks>
 /// <para>
 /// If the provided manager also implements the <see cref="IUpdateableGenericIOManager">IUpdateableGenericIOManager</see> interface then the managers native SPARQL Update implementation will be used.
 /// </para>
 /// </remarks>
 public virtual void ProcessCommandSet(SparqlUpdateCommandSet commands)
 {
     DateTime start = DateTime.Now;
     commands.UpdateExecutionTime = null;
     try
     {
         if (this._manager is IUpdateableGenericIOManager)
         {
             ((IUpdateableGenericIOManager)this._manager).Update(commands.ToString());
         }
         else
         {
             for (int i = 0; i < commands.CommandCount; i++)
             {
                 this.ProcessCommand(commands[i]);
             }
         }
     }
     finally
     {
         TimeSpan elapsed = (DateTime.Now - start);
         commands.UpdateExecutionTime = elapsed;
     }
 }
 /// <summary>
 /// Executes a set of SPARQL Update commands on the Store
 /// </summary>
 /// <param name="updates">SPARQL Update Commands</param>
 /// <remarks>
 /// <para>
 /// If the underlying Manager is an <see cref="IUpdateableGenericIOManager">IUpdateableGenericIOManager</see> then the managers own Update implementation will be used, otherwise dotNetRDF's approximated implementation for generic stores will be used.  In the case of approximation exact feature support will vary depending on the underlying manager being used.
 /// </para>
 /// </remarks>
 public void ExecuteUpdate(SparqlUpdateCommandSet updates)
 {
     GenericUpdateProcessor processor = new GenericUpdateProcessor(this._manager);
     processor.ProcessCommandSet(updates);
 }
        private void ExecuteCommandSet(SparqlUpdateCommandSet commands)
        {
            var store = _store as IUpdateableTripleStore;
            if (store == null)
            {
                throw new InvalidOperationException(string.Format("Store doesn't implement {0}", typeof(IUpdateableTripleStore)));
            }

            store.ExecuteUpdate(commands);
        }
 /// <inheritdoc />
 public new void ExecuteUpdate(SparqlUpdateCommandSet updates)
 {
     ((IUpdateableTripleStore)this).ExecuteUpdate(updates);
 }
 /// <inheritdoc />
 void IUpdateableTripleStore.ExecuteUpdate(SparqlUpdateCommandSet updates)
 {
     lock (Locker)
     {
         LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(this);
         processor.ProcessCommandSet(updates);
         Write();
     }
 }
Beispiel #40
0
 public bool IsApplicable(SparqlUpdateCommandSet cmds)
 {
     return true;
 }
Beispiel #41
0
        /// <summary>
        /// Processes a command set.
        /// </summary>
        /// <param name="commands">Command Set.</param>
        /// <remarks>
        /// Invokes <see cref="LeviathanUpdateProcessor.ProcessCommand">ProcessCommand()</see> on each command in turn.
        /// </remarks>
        public void ProcessCommandSet(SparqlUpdateCommandSet commands)
        {
            commands.UpdateExecutionTime = null;

            // Firstly check what Transaction mode we are running in
            bool autoCommit = _autoCommit;

            // Then create an Evaluation Context
            SparqlUpdateEvaluationContext context = GetContext(commands);

            // Remember to handle the Thread Safety
            // If the Dataset is Thread Safe use its own lock otherwise use our local lock
            ReaderWriterLockSlim currLock = (_dataset is IThreadSafeDataset) ? ((IThreadSafeDataset)_dataset).Lock : _lock;

            try
            {
                currLock.EnterWriteLock();

                // Regardless of the Transaction Mode we turn auto-commit off for a command set so that individual commands
                // don't try and commit after each one is applied i.e. either we are in auto-commit mode and all the
                // commands must be evaluated before flushing/discarding the changes OR we are not in auto-commit mode
                // so turning it off doesn't matter as it is already turned off
                _autoCommit = false;

                if (autoCommit)
                {
                    // Do a Flush() before we start to ensure changes from any previous commands are persisted
                    _dataset.Flush();
                }

                // Start the operation
                context.StartExecution();
                for (int i = 0; i < commands.CommandCount; i++)
                {
                    ProcessCommandInternal(commands[i], context);

                    // Check for Timeout
                    context.CheckTimeout();
                }

                if (autoCommit)
                {
                    // Do a Flush() when command set completed successfully to persist the changes
                    _dataset.Flush();
                }

                // Set Update Times
                context.EndExecution();
                commands.UpdateExecutionTime = new TimeSpan(context.UpdateTimeTicks);
            }
            catch
            {
                if (autoCommit)
                {
                    // Do a Discard() when a command set fails to discard the changes
                    _dataset.Discard();
                }
                else
                {
                    _canCommit = false;
                }

                // Set Update Times
                context.EndExecution();
                commands.UpdateExecutionTime = new TimeSpan(context.UpdateTimeTicks);
                throw;
            }
            finally
            {
                // Reset auto-commit setting and release our write lock
                _autoCommit = autoCommit;
                currLock.ExitWriteLock();
            }
        }
Beispiel #42
0
        /// <summary>
        /// Executes a set of Update Commands against the Triple Store
        /// </summary>
        /// <param name="updates">SPARQL Update Command Set</param>
        public void ExecuteUpdate(SparqlUpdateCommandSet updates)
        {
            SparqlUpdateEvaluationContext context = new SparqlUpdateEvaluationContext(new InMemoryDataset(this));

            for (int i = 0; i < updates.CommandCount; i++)
            {
                updates[i].Evaluate(context);
            }
        }
 private void RunUpdate(SparqlUpdateCommandSet cmds, ISparqlUpdateProcessor processor)
 {
     processor.ProcessCommandSet(cmds);
 }
 /// <summary>
 /// Processes SPARQL Updates
 /// </summary>
 /// <param name="cmds">Update Command Set</param>
 /// <remarks>
 /// <para>
 /// Implementations should override this method if their behaviour requires more than just invoking the configured Update processor
 /// </para>
 /// </remarks>
 protected virtual void ProcessUpdates(SparqlUpdateCommandSet cmds)
 {
     this._config.Processor.ProcessCommandSet(cmds);
 }
 /// <summary>
 /// Creates a new SPARQL Update Evaluation Context
 /// </summary>
 /// <param name="commands">Command Set</param>
 /// <param name="data">SPARQL Dataset</param>
 public SparqlUpdateEvaluationContext(SparqlUpdateCommandSet commands, ISparqlDataset data)
     : this(data)
 {
     this._commands = commands;
 }
 /// <summary>
 /// Creates a new SPARQL Update Evaluation Context.
 /// </summary>
 /// <param name="commands">Command Set.</param>
 /// <param name="data">SPARQL Dataset.</param>
 public SparqlUpdateEvaluationContext(SparqlUpdateCommandSet commands, ISparqlDataset data)
     : this(data)
 {
     _commands = commands;
 }
Beispiel #47
0
 /// <summary>
 /// Returns that the optimiser does not apply to SPARQL Updates
 /// </summary>
 /// <param name="cmds">Updates</param>
 /// <returns></returns>
 public override bool IsApplicable(SparqlUpdateCommandSet cmds)
 {
     return false;
 }