/// <summary> /// Opens a SQL Triple Store using the provided Store Manager, automatically loads all data contained in that Store /// </summary> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen backing SQL Store</param> public SqlTripleStore(ISqlIOManager manager) : base() { this._manager = manager; this._storeInferencesExternally = true; this.LoadInternal(); }
/// <summary> /// Opens an On Demand SQL Triple Store using the provided Store Manager /// </summary> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen backing SQL Store</param> /// <param name="defaultGraphUri">A Uri for the Default Graph which should be loaded from the backing Store</param> public OnDemandTripleStore(ISqlIOManager manager, Uri defaultGraphUri) : this(manager) { //Call Contains() which will try to load the Graph if it exists in the Store if (!this._graphs.Contains(defaultGraphUri)) { throw new RdfStorageException("Cannot load the requested Default Graph since a Graph with that URI does not exist in the Triple Store"); } }
/// <summary> /// Tries to load a SQL IO Manager 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) { ISqlIOManager manager = null; String server, port, db, user, pwd; //Create the URI Nodes we're going to use to search for things INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer), propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase); //Get Server and Database details server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { server = "localhost"; } db = ConfigurationLoader.GetConfigurationString(g, objNode, propDb); if (db == null) { obj = null; return(false); } //Get user credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); //Based on this information create a Manager if possible switch (targetType.FullName) { case MicrosoftSqlManager: if (user == null || pwd == null) { manager = new MicrosoftSqlStoreManager(server, db); } else { manager = new MicrosoftSqlStoreManager(server, db, user, pwd); } break; case MySqlManager: if (user != null && pwd != null) { manager = new MySqlStoreManager(server, db, user, pwd); } break; } obj = manager; return(manager != null); }
public fclsSQLGraphManager(Uri graphUri, ISqlIOManager manager) { InitializeComponent(); this._manager = manager; this._graphUri = graphUri; if (this._manager.Exists(this._graphUri)) { this._graphID = this._manager.GetGraphID(this._graphUri); } else { throw new RdfStorageException("The specified Graph does not exist in this dotNetRDF Store"); } }
/// <summary> /// Creates a new instance of a Graph which is automatically saved to the given SQL Store /// </summary> /// <param name="graphUri">Uri of the Graph</param> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen underlying Store</param> public WriteOnlySqlGraph(Uri graphUri, ISqlIOManager manager) { //Set Database Mananger this._manager = manager; //Base Uri is the Graph Uri this.BaseUri = graphUri; //Get the Graph ID and then Load only the Namespaces this._graphID = this._manager.GetGraphID(graphUri); this._manager.LoadNamespaces(this, this._graphID); //Subscribe to Namespace Map Events //This has to happen after we load from the Database as otherwise the Loading will fire off all the //Namespace Map events creating unecessary overhead this._nsmapper.NamespaceAdded += this.HandleNamespaceAdded; this._nsmapper.NamespaceModified += this.HandleNamespaceModified; this._nsmapper.NamespaceRemoved += this.HandleNamespaceRemoved; }
/// <summary> /// Creates a new instance of a Graph which is automatically saved to the given SQL Store /// </summary> /// <param name="graphUri">Uri of the Graph</param> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen underlying Store</param> public WriteOnlySqlGraph(Uri graphUri, ISqlIOManager manager) { //Set Database Mananger this._manager = manager; //Base Uri is the Graph Uri this.BaseUri = graphUri; //Get the Graph ID and then Load only the Namespaces this._graphID = this._manager.GetGraphID(graphUri); this._manager.LoadNamespaces(this, this._graphID); //Subscribe to Namespace Map Events //This has to happen after we load from the Database as otherwise the Loading will fire off all the //Namespace Map events creating unecessary overhead this._nsmapper.NamespaceAdded += this.HandleNamespaceAdded; this._nsmapper.NamespaceModified += this.HandleNamespaceModified; this._nsmapper.NamespaceRemoved += this.HandleNamespaceRemoved; }
/// <summary> /// Creates a new set of Parameters /// </summary> /// <param name="manager">SQL IO Manager</param> /// <param name="clearIfExists">Whether existing Graphs of the same Uri should be removed from the Store before saving a Graph</param> public SqlIOParams(ISqlIOManager manager, bool clearIfExists) : this(manager) { this._clearIfExists = clearIfExists; }
/// <summary> /// Creates a new set of Parameters /// </summary> /// <param name="manager">SQL IO Manager</param> public SqlIOParams(ISqlIOManager manager) { this._manager = manager; }
/// <summary> /// Creates a new set of Parameters /// </summary> /// <param name="manager">SQL IO Manager</param> /// <param name="clearIfExists">Whether existing Graphs of the same Uri should be removed from the Store before saving a Graph</param> public SqlIOParams(ISqlIOManager manager, bool clearIfExists) : this(manager) { this._clearIfExists = clearIfExists; }
/// <summary> /// Creates a new set of Parameters /// </summary> /// <param name="manager">SQL IO Manager</param> public SqlIOParams(ISqlIOManager manager) { this._manager = manager; }
/// <summary> /// Creates a new instance of the SqlWriter which will use the SQL Store accessed using the given <see cref="ISqlIOManager">ISqlIOManager</see> which allows writing to arbitrary SQL Stores /// </summary> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen underlying store</param> public SqlWriter(ISqlIOManager manager) { this._manager = manager; }
/// <summary> /// Creates a new instance of the SqlWriter which will use the SQL Store accessed using the given <see cref="ISqlIOManager">ISqlIOManager</see> which allows writing to arbitrary SQL Stores /// </summary> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen underlying store</param> public SqlWriter(ISqlIOManager manager) { this._manager = manager; }
/// <summary> /// Opens an On Demand SQL Triple Store using the provided Store Manager /// </summary> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen backing SQL Store</param> public OnDemandTripleStore(ISqlIOManager manager) : base(new OnDemandGraphCollection(manager)) { }
/// <summary> /// Creates a new On Demand Graph Collection which loads Graphs from a backing SQL Store on demand /// </summary> /// <param name="manager">Manager for the SQL Store</param> public OnDemandGraphCollection(ISqlIOManager manager) { this._manager = manager; this._manager.PreserveState = true; this._sqlreader = new SqlReader(this._manager); }
/// <summary> /// Opens a SQL Triple Store using the provided Store Manager, automatically loads all data contained in that Store /// </summary> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen backing SQL Store</param> public SqlTripleStore(ISqlIOManager manager) : base() { this._manager = manager; this._storeInferencesExternally = true; this.LoadInternal(); }
/// <summary> /// Creates a new instance of the SqlReader which will use the SQL Store accessed using the given <see cref="ISqlIOManager">ISqlIOManager</see> which allows writing to arbitrary SQL Stores /// </summary> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen underlying store</param> public SqlReader(ISqlIOManager manager) { this._manager = manager; }
/// <summary> /// Creates a new instance of the SqlReader which will use the SQL Store accessed using the given <see cref="ISqlIOManager">ISqlIOManager</see> which allows writing to arbitrary SQL Stores /// </summary> /// <param name="manager">An <see cref="ISqlIOManager">ISqlIOManager</see> for your chosen underlying store</param> public SqlReader(ISqlIOManager manager) { this._manager = manager; }
public override void Run(string[] args) { if (args.Length < 2) { this.ShowUsage(); return; } //Check Configuration File is OK String config = args[1]; if (args[1].Equals("-help")) { this.ShowUsage(); return; } if (!File.Exists(config)) { Console.Error.WriteLine("rdfSqlStorage: Error: Specified migration configuration file '" + config + "' does not exist!"); return; } //Check for other options this.CheckOptions(args); try { Graph g = new Graph(); g.LoadFromFile(config); Console.WriteLine("rdfSqlStorage: Read migration configuration file OK..."); ConfigurationLoader.AutoDetectObjectFactories(g); INode sourceNode = g.GetUriNode(new Uri("dotnetrdf:migration:source")); if (sourceNode == null) { Console.Error.WriteLine("rdfSqlStorage: Error: Expected to find the source for the migration specified by the special URI <dotnetrdf:migration:source> but it does not exist in the given Configuration File!"); return; } INode targetNode = g.GetUriNode(new Uri("dotnetrdf:migration:target")); if (targetNode == null) { Console.Error.WriteLine("rdfSqlStorage: Error: Expected to find the target for the migration specified by the special URI <dotnetrdf:migration:target> but it does not exist in the given Configuration File!"); return; } //Try to load the Objects Object sourceObj = ConfigurationLoader.LoadObject(g, sourceNode); if (!(sourceObj is ISqlIOManager)) { Console.Error.WriteLine("rdfSqlStorage: Error: Expected the migration source to be loadable as an object of type ISqlIOManager!"); return; } Object targetObj = ConfigurationLoader.LoadObject(g, targetNode); if (!(targetObj is IGenericIOManager)) { Console.Error.WriteLine("rdfSqlStorage: Error: Expected the migration target to be loadable as an object of type IGenericIOManager!"); return; } Console.WriteLine("rdfSqlStorage: Loaded migration source and target OK..."); //Retrieve Graph list from Migration Source ISqlIOManager source = (ISqlIOManager)sourceObj; Console.WriteLine("rdfSqlStorage: Retrieving Graph URIs from migration source..."); try { source.Open(true); List <Uri> uris = source.GetGraphUris(); Console.WriteLine("rdfSqlStorage: Migration source has " + uris.Count + " Graph URIs"); //Start migrating Graphs IGenericIOManager target = (IGenericIOManager)targetObj; for (int i = 0; i < uris.Count; i++) { Console.WriteLine("rdfSqlStorage: Migrating Graph '" + uris[i].ToSafeString() + "' (" + (i + 1) + " of " + uris.Count + ")..."); String id = source.GetGraphID(uris[i]); using (Graph temp = new Graph()) { temp.BaseUri = uris[i]; Console.WriteLine("rdfSqlStorage: Loading Graph into memory..."); source.LoadTriples(temp, id); Console.WriteLine("rdfSqlStorage: Loaded " + temp.Triples.Count + " Triple(s)"); Console.WriteLine("rdfSqlStorage: Saving Graph to migration target..."); target.SaveGraph(temp); Console.WriteLine("rdfSqlStorage: Saved Graph OK"); if (this._verify) { Console.WriteLine("rdfSqlStorage: Retrieving newly saved Graph from migration target to verify data migration..."); using (Graph temp2 = new Graph()) { target.LoadGraph(temp2, uris[i]); Console.WriteLine("rdfSqlStorage: Retrieved newly saved Graph OK, proceeding to verify data..."); GraphDiffReport report = temp.Difference(temp2); if (!report.AreEqual) { Console.Error.WriteLine("rdfSqlStorage: Warning: Data Verification failed: " + report.AddedTriples.Count() + " incorrect Ground Triple(s) and " + report.AddedMSGs.Count() + " incorrect MSGs containing " + report.AddedMSGs.Sum(x => x.Triples.Count) + " non-Ground Triple(s)"); if (this._halt) { Console.Error.WriteLine("rdfSqlStorage: Error: Halting due to data verification failure!"); return; } } else { Console.WriteLine("rdfSqlStorage: Data Verified OK!"); } temp2.Dispose(); } } temp.Dispose(); } GC.GetTotalMemory(true); Console.WriteLine(); } Console.WriteLine("rdfSqlStorage: Finishing Migrating Graphs!"); } finally { source.Close(true); } } catch (RdfParserSelectionException selEx) { Console.Error.WriteLine("rdfSqlStorage: Error: Specified migration configuration file is not in a RDF format that the tool understands!"); this.PrintErrorTrace(selEx); } catch (RdfParseException parseEx) { Console.Error.WriteLine("rdfSqlStorage: Error: Specified migration configuration file is not valid RDF!"); this.PrintErrorTrace(parseEx); } catch (DotNetRdfConfigurationException configEx) { Console.Error.WriteLine("rdfSqlStorage: Error: Specified migration configuration file contains malformed configuration information!"); this.PrintErrorTrace(configEx); } }