示例#1
0
        public void SparqlUpdateCreateDrop()
        {
            TripleStore store = new TripleStore();

            Console.WriteLine("Store has " + store.Graphs.Count + " Graphs");

            //Create a couple of Graphs using Create Commands
            CreateCommand create1 = new CreateCommand(new Uri("http://example.org/1"));
            CreateCommand create2 = new CreateCommand(new Uri("http://example.org/2"));

            store.ExecuteUpdate(create1);
            store.ExecuteUpdate(create2);

            Assert.AreEqual(3, store.Graphs.Count, "Store should have now had three Graphs");
            Assert.AreEqual(0, store.Triples.Count(), "Store should have no triples at this point");

            //Trying the same Create again should cause an error
            try
            {
                store.ExecuteUpdate(create1);
                Assert.Fail("Executing a CREATE command twice without the SILENT modifier should error");
            }
            catch (SparqlUpdateException)
            {
                Console.WriteLine("Executing a CREATE command twice without the SILENT modifier errored as expected");
            }

            //Equivalent Create with SILENT should not error
            CreateCommand create3 = new CreateCommand(new Uri("http://example.org/1"), true);
            try
            {
                store.ExecuteUpdate(create3);
                Console.WriteLine("Executing a CREATE for an existing Graph with the SILENT modifier suppressed the error as expected");
            }
            catch (SparqlUpdateException)
            {
                Assert.Fail("Executing a CREATE for an existing Graph with the SILENT modifier should not error");
            }

            DropCommand drop1 = new DropCommand(new Uri("http://example.org/1"));
            store.ExecuteUpdate(drop1);
            Assert.AreEqual(2, store.Graphs.Count, "Store should have only 2 Graphs after we executed the DROP command");

            try
            {
                store.ExecuteUpdate(drop1);
                Assert.Fail("Trying to DROP a non-existent Graph should error");
            }
            catch (SparqlUpdateException)
            {
                Console.WriteLine("Trying to DROP a non-existent Graph produced an error as expected");
            }

            DropCommand drop2 = new DropCommand(new Uri("http://example.org/1"), ClearMode.Graph, true);
            try
            {
                store.ExecuteUpdate(drop2);
                Console.WriteLine("Trying to DROP a non-existent Graph with the SILENT modifier suppressed the error as expected");
            }
            catch (SparqlUpdateException)
            {
                Assert.Fail("Trying to DROP a non-existent Graph with the SILENT modifier should suppress the error");
            }
        }
 /// <summary>
 /// Processes a DROP command
 /// </summary>
 /// <param name="cmd">Drop Command</param>
 public void ProcessDropCommand(DropCommand cmd)
 {
     this.ProcessCommand(cmd);
 }
示例#3
0
        /// <summary>
        /// Processes a DROP command
        /// </summary>
        /// <param name="cmd">Drop Command</param>
        public void ProcessDropCommand(DropCommand cmd)
        {
            if (this._manager is IUpdateableGenericIOManager)
            {
                ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString());
            }
            else
            {
                try
                {
                    Graph g;
                    switch (cmd.Mode)
                    {
                        case ClearMode.Graph:
                        case ClearMode.Default:
                            if (this._manager.DeleteSupported)
                            {
                                //If available use DeleteGraph()
                                this._manager.DeleteGraph(cmd.TargetUri);
                            }
                            else if ((cmd.TargetUri == null && (this._manager.IOBehaviour & IOBehaviour.OverwriteDefault) != 0) || (cmd.TargetUri != null && (this._manager.IOBehaviour & IOBehaviour.OverwriteNamed) != 0))
                            {
                                //Can approximate by saving an empty Graph over the existing Graph
                                g = new Graph();
                                g.BaseUri = cmd.TargetUri;
                                this._manager.SaveGraph(g);
                            }
                            else if (this._manager.UpdateSupported && (this._manager.IOBehaviour & IOBehaviour.CanUpdateDeleteTriples) != 0)
                            {
                                //Can approximate by loading the Graph and then deleting all Triples from it
                                g = new NonIndexedGraph();
                                this._manager.LoadGraph(g, cmd.TargetUri);
                                this._manager.UpdateGraph(cmd.TargetUri, null, g.Triples);
                            }
                            else
                            {
                                throw new SparqlUpdateException("Unable to evaluate a DROP command as the underlying store does not provide appropriate IO Behaviour to approximate this command");
                            }
                            break;

                        case ClearMode.All:
                        case ClearMode.Named:
                            if (this._manager.ListGraphsSupported)
                            {
                                List<Uri> graphs = this._manager.ListGraphs().ToList();
                                foreach (Uri u in graphs)
                                {
                                    if (this._manager.DeleteSupported)
                                    {
                                        //If available use DeleteGraph()
                                        this._manager.DeleteGraph(u);
                                    }
                                    else if ((u == null && (this._manager.IOBehaviour & IOBehaviour.OverwriteDefault) != 0) || (u != null && (this._manager.IOBehaviour & IOBehaviour.OverwriteNamed) != 0))
                                    {
                                        //Can approximate by saving an empty Graph over the existing Graph
                                        g = new Graph();
                                        g.BaseUri = u;
                                        this._manager.SaveGraph(g);
                                    }
                                    else if (this._manager.UpdateSupported && (this._manager.IOBehaviour & IOBehaviour.CanUpdateDeleteTriples) != 0)
                                    {
                                        //Can approximate by loading the Graph and then deleting all Triples from it
                                        g = new NonIndexedGraph();
                                        this._manager.LoadGraph(g, u);
                                        this._manager.UpdateGraph(u, null, g.Triples);
                                    }
                                    else
                                    {
                                        throw new SparqlUpdateException("Unable to evaluate a DROP command as the underlying store does not provide appropriate IO Behaviour to approximate this command");
                                    }
                                }
                            }
                            else
                            {
                                throw new NotSupportedException("The Generic Update processor does not support this form of the DROP command");
                            }
                            break;
                    }
                }
                catch
                {
                    if (!cmd.Silent) throw;
                }
            }
        }
        /// <summary>
        /// Processes a DROP command
        /// </summary>
        /// <param name="cmd">Drop Command</param>
        public void ProcessDropCommand(DropCommand cmd)
        {
            if (this._manager is IUpdateableGenericIOManager)
            {
                ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString());
            }
            else
            {
                try
                {
                    Graph g;
                    switch (cmd.Mode)
                    {
                        case ClearMode.Graph:
                        case ClearMode.Default:
                            g = new Graph();
                            g.BaseUri = cmd.TargetUri;
                            this._manager.SaveGraph(g);
                            break;

                        case ClearMode.All:
                        case ClearMode.Named:
                            if (this._manager.ListGraphsSupported)
                            {
                                List<Uri> graphs = this._manager.ListGraphs().ToList();
                                foreach (Uri u in graphs)
                                {
                                    g = new Graph();
                                    g.BaseUri = u;
                                    this._manager.SaveGraph(g);
                                }
                            }
                            else
                            {
                                throw new NotSupportedException("The Generic Update processor does not support this form of the DROP command");
                            }
                            break;
                    }
                }
                catch
                {
                    if (!cmd.Silent) throw;
                }
            }
        }
示例#5
0
 /// <summary>
 /// Processes a DROP command
 /// </summary>
 /// <param name="cmd">Drop Command</param>
 /// <param name="context">SPARQL Update Evaluation Context</param>
 protected virtual void ProcessDropCommandInternal(DropCommand cmd, SparqlUpdateEvaluationContext context)
 {
     cmd.Evaluate(context);
 }
示例#6
0
 /// <summary>
 /// Processes a DROP command
 /// </summary>
 /// <param name="cmd">Drop Command</param>
 public void ProcessDropCommand(DropCommand cmd)
 {
     this.ProcessDropCommandInternal(cmd, this.GetContext());
 }
        private void TryParseDropCommand(SparqlUpdateParserContext context)
        {
            bool silent = false;

            //May possibly have a SILENT Keyword
            IToken next = context.Tokens.Dequeue();
            if (next.TokenType == Token.SILENT)
            {
                silent = true;
                next = context.Tokens.Dequeue();
            }

            //Then expect a GRAPH followed by a URI or one of the DEFAULT/NAMED/ALL keywords
            if (next.TokenType == Token.GRAPH)
            {
                Uri u = this.TryParseGraphRef(context);
                DropCommand cmd = new DropCommand(u, ClearMode.Graph, silent);
                context.CommandSet.AddCommand(cmd);
            }
            else if (next.TokenType == Token.DEFAULT)
            {
                context.CommandSet.AddCommand(new DropCommand(ClearMode.Default, silent));
            } 
            else if (next.TokenType == Token.NAMED)
            {
                context.CommandSet.AddCommand(new DropCommand(ClearMode.Named, silent));
            }
            else if (next.TokenType == Token.ALLWORD)
            {
                context.CommandSet.AddCommand(new DropCommand(ClearMode.All, silent));
            }
            else
            {
                throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a GRAPH <URI> to specify the Graph to DROP or one of the DEFAULT/NAMED/ALL keywords", next);
            }
        }