/// <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); }
/// <summary> /// Tries to load a SPARQL Query Processor 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; ISparqlQueryProcessor processor = null; INode storeObj; Object temp; switch (targetType.FullName) { case LeviathanQueryProcessor: 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 LeviathanQueryProcessor((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Query 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 { //If no dnr:usingDataset try dnr:usingStore instead 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 LeviathanQueryProcessor((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Query 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 SimpleQueryProcessor: storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeObj == null) return false; temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is INativelyQueryableStore) { processor = new SimpleQueryProcessor((INativelyQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Simple Query 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 INativelyQueryableStore interface"); } break; #if !NO_STORAGE case GenericQueryProcessor: INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); if (managerObj == null) return false; temp = ConfigurationLoader.LoadObject(g, managerObj); if (temp is IQueryableGenericIOManager) { processor = new GenericQueryProcessor((IQueryableGenericIOManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Generic Query 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 IQueryableGenericIOManager interface"); } break; #endif #if !SILVERLIGHT case RemoteQueryProcessor: INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpoint)); if (endpointObj == null) return false; temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { processor = new RemoteQueryProcessor((SparqlRemoteEndpoint)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Remote Query Processor identified by the Node '" + objNode.ToSafeString() + "' as the value given for the dnr:endpoint property points to an Object that cannot be loaded as an object which is a SparqlRemoteEndpoint"); } break; case PelletQueryProcessor: String server = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer)); if (server == null) return false; String kb = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore)); if (kb == null) return false; processor = new PelletQueryProcessor(new Uri(server), kb); break; #endif } obj = processor; return (processor != null); }