public void SparqlUpdateGenericCreateInsertDeleteData()
        {
            IGenericIOManager 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");

            cmds = this._parser.ParseFromString("DELETE DATA { GRAPH <http://example.org/sparqlUpdate/created> { <http://example.org/s> <http://example.org/p> <http://example.org/o> } }");
            processor.ProcessCommandSet(cmds);

            Graph h = new Graph();
            manager.LoadGraph(h, "http://example.org/sparqlUpdate/created");

            TestTools.ShowGraph(h);

            Assert.IsTrue(h.IsEmpty, "[" + manager.ToString() + "] Graph should be empty");
        }
        /// <summary>
        /// Return a new <see cref="IDataObjectStore"/> instance that wraps the specified DotNetRDF IStorageProvider instance
        /// </summary>
        /// <param name="namespaceMappings">Namespace mappings to apply to the data object store</param>
        /// <param name="optimisticLockingEnabled">Boolean flag indicating if optimistic locking is to be enabled on the store</param>
        /// <param name="updateGraph">The URI of the graph to be modified by update operations</param>
        /// <param name="defaultDataSet">The URI of the graph(s) to be accessed by read and query operations</param>
        /// <param name="versionTrackingGraph">The URI of the graph to use to track entity version numbers for optimistic locking</param>
        /// <param name="storageProvider">The DotNetRDF IStorageProvider instance that manages the RDF graphs</param>
        /// <returns>A <see cref="IDataObjectStore"/> instance that wraps access to the <paramref name="storageProvider"/></returns>
        protected IDataObjectStore CreateDataObjectStore(Dictionary<string, string> namespaceMappings, bool? optimisticLockingEnabled,
                                                         string updateGraph, IEnumerable<string> defaultDataSet,
                                                         string versionTrackingGraph, IStorageProvider storageProvider)
        {
            if (!(storageProvider is IQueryableStorage))
            {
                throw new BrightstarClientException(Strings.DotNetRdf_StoreMustImplementIQueryableStorage);
            }
            var queryProcessor = new GenericQueryProcessor(storageProvider as IQueryableStorage);
            ISparqlUpdateProcessor updateProcessor = null;
            if (storageProvider is IUpdateableStorage && !storageProvider.IsReadOnly)
            {
                updateProcessor = new GenericUpdateProcessor(storageProvider);
            }

            return new SparqlDataObjectStore(queryProcessor, updateProcessor, namespaceMappings,
                                             optimisticLockingEnabled.HasValue
                                                 ? optimisticLockingEnabled.Value
                                                 : OptimisticLockingEnabled,
                                             updateGraph, defaultDataSet, versionTrackingGraph);
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Execute insert or delete SPARQL queries against Stardog;
    /// separate multiple statements with a semicolon
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    public static bool Update(string command)
    {
        using (StardogConnector dog = new StardogConnector(ConnectionString(), ConnectionDatabase(), ConnectionUser(), ConnectionPassword()))
        {

            try
            {

                dog.Begin(); // wrap all the statements in this command into one transaction; otherwise stardog will run them as separate transactions

                GenericUpdateProcessor processor = new GenericUpdateProcessor(dog);

                SparqlUpdateParser parser = new SparqlUpdateParser();

                processor.ProcessCommandSet(parser.ParseFromString(Prefixes() + command));

                dog.Commit();

                return true;

            }
            catch (Exception err)
            {

                try
                {
                    dog.Rollback();
                }
                catch { }

                throw err;

            }

        }
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Tries to load a SPARQL Update based on information from the Configuration Graph
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        /// <param name="targetType">Target Type</param>
        /// <param name="obj">Output Object</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            obj = null;
            ISparqlUpdateProcessor processor = null;
            INode storeObj;
            Object temp;

            switch (targetType.FullName)
            {
                case LeviathanUpdateProcessor:
                    INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingDataset));
                    if (datasetObj != null)
                    {
                        temp = ConfigurationLoader.LoadObject(g, datasetObj);
                        if (temp is ISparqlDataset)
                        {
                            processor = new LeviathanUpdateProcessor((ISparqlDataset)temp);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the Leviathan Update Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface");
                        }
                    }
                    else
                    {
                        storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore));
                        if (storeObj == null) return false;
                        temp = ConfigurationLoader.LoadObject(g, storeObj);
                        if (temp is IInMemoryQueryableStore)
                        {
                            processor = new LeviathanUpdateProcessor((IInMemoryQueryableStore)temp);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the Leviathan Update Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface");
                        }
                    }
                    break;

                case SimpleUpdateProcessor:
                    storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore));
                    if (storeObj == null) return false;
                    temp = ConfigurationLoader.LoadObject(g, storeObj);
                    if (temp is IUpdateableTripleStore)
                    {
                        processor = new SimpleUpdateProcessor((IUpdateableTripleStore)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Simple Update Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IUpdateableTripleStore interface");
                    }
                    break;

#if !NO_STORAGE

                case GenericUpdateProcessor:
                    INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager));
                    if (managerObj == null) return false;
                    temp = ConfigurationLoader.LoadObject(g, managerObj);
                    if (temp is IGenericIOManager)
                    {
                        processor = new GenericUpdateProcessor((IGenericIOManager)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Generic Update Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object that cannot be loaded as an object which implements the IGenericIOManager interface");
                    }

                    break;
#endif
            }

            obj = processor;
            return (processor != null);
        }
Ejemplo n.º 5
0
 /// <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);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Executes an Update against the Triple Store
        /// </summary>
        /// <param name="update">SPARQL Update Command(s)</param>
        /// <remarks>
        /// As per the SPARQL 1.1 Update specification the command string may be a sequence of commands
        /// </remarks>
        public void ExecuteUpdate(string update)
        {
            if (this._manager is IUpdateableGenericIOManager)
            {
                if (!((PersistentGraphCollection)this._graphs).IsSynced)
                {
                    throw new SparqlUpdateException("Unable to execute a SPARQL Update as the in-memory view of the store is not synced with the underlying store, please invoked Flush() or Discard() and try again.  Alternatively if you do not want to see in-memory changes reflected in update results you can invoke the Update() method directly on the underlying store by accessing it through the UnderlyingStore property.");
                }

                ((IUpdateableGenericIOManager)this._manager).Update(update);
            }
            else
            {
                if (this._updateProcessor == null) this._updateProcessor = new GenericUpdateProcessor(this._manager);
                if (this._updateParser == null) this._updateParser = new SparqlUpdateParser();
                SparqlUpdateCommandSet cmds = this._updateParser.ParseFromString(update);
                this._updateProcessor.ProcessCommandSet(cmds);
            }
        }
Ejemplo n.º 7
0
    /// <summary>
    /// Execute insert or delete SPARQL queries against Stardog;
    /// separate multiple statements with a semicolon
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    public static bool Update(string command)
    {
        using (StardogConnector dog = new StardogConnector(ConnectionString(), ConnectionDatabase(), ConnectionUser(), ConnectionPassword()))
        {

            GenericUpdateProcessor processor = new GenericUpdateProcessor(dog);

            SparqlUpdateParser parser = new SparqlUpdateParser();

            processor.ProcessCommandSet(parser.ParseFromString(Prefixes() + command));

        }

        return true;
    }