public void SparqlDefaultGraphExists3() { SqlDataset dataset = new SqlDataset(new MicrosoftSqlStoreManager("localhost", "unit_test", "example", "password")); //Create Default Graph only if required if (!dataset.HasGraph(null)) { Graph g = new Graph(); g.Assert(g.CreateUriNode(new Uri("http://example.org/subject")), g.CreateUriNode(new Uri("http://example.org/predicate")), g.CreateUriNode(new Uri("http://example.org/object"))); dataset.AddGraph(g); dataset.Flush(); } SparqlQueryParser parser = new SparqlQueryParser(); SparqlQuery q = parser.ParseFromString("ASK WHERE { GRAPH ?g { ?s ?p ?o }}"); LeviathanQueryProcessor lvn = new LeviathanQueryProcessor(dataset); Object results = lvn.ProcessQuery(q); if (results is SparqlResultSet) { Assert.IsTrue(((SparqlResultSet)results).Result); } else { Assert.Fail("ASK Query did not return a SPARQL Result Set as expected"); } dataset.Flush(); }
/// <summary> /// Tries to load a SPARQL Dataset 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; switch (targetType.FullName) { case InMemoryDataset: INode storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeNode == null) { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:usingStore"); } else { Object temp = ConfigurationLoader.LoadObject(g, storeNode); if (temp is IInMemoryQueryableStore) { obj = new InMemoryDataset((IInMemoryQueryableStore)temp); return(true); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:usingStore property could not be loaded as an object which implements the IInMemoryQueryableStore interface"); } } #if !NO_DATA && !NO_STORAGE case SqlDataset: INode sqlManager = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertySqlManager)); if (sqlManager == null) { throw new DotNetRdfConfigurationException("Unable to load the SQL Dataset identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:sqlManager"); } else { Object temp = ConfigurationLoader.LoadObject(g, sqlManager); if (temp is IDotNetRDFStoreManager) { obj = new SqlDataset((IDotNetRDFStoreManager)temp); return(true); } else { throw new DotNetRdfConfigurationException("Unable to load the SQL Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:sqlManager property could not be laoded as an object which implements the IDotNetRDFStoreManager interface"); } } #endif } return(false); }
/// <summary> /// Tries to load a SPARQL Dataset 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; switch (targetType.FullName) { case InMemoryDataset: INode storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeNode == null) { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:usingStore"); } else { Object temp = ConfigurationLoader.LoadObject(g, storeNode); if (temp is IInMemoryQueryableStore) { obj = new InMemoryDataset((IInMemoryQueryableStore)temp); return true; } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:usingStore property could not be loaded as an object which implements the IInMemoryQueryableStore interface"); } } #if !NO_DATA && !NO_STORAGE case SqlDataset: INode sqlManager = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertySqlManager)); if (sqlManager == null) { throw new DotNetRdfConfigurationException("Unable to load the SQL Dataset identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:sqlManager"); } else { Object temp = ConfigurationLoader.LoadObject(g, sqlManager); if (temp is IDotNetRDFStoreManager) { obj = new SqlDataset((IDotNetRDFStoreManager)temp); return true; } else { throw new DotNetRdfConfigurationException("Unable to load the SQL Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:sqlManager property could not be laoded as an object which implements the IDotNetRDFStoreManager interface"); } } #endif } return false; }