コード例 #1
0
        public void StorageStorageSqlIOManagerDispose()
        {
            ISqlIOManager manager = new NonNativeVirtuosoManager("test", "test", "test");
            Console.WriteLine("Created a Manager which we will now dipose of twice, second dispose should throw an error");

            manager.Dispose();
            try
            {
                manager.Dispose();
                Assert.Fail("Second dispose should have thrown an error");
            }
            catch (RdfStorageException ex)
            {
                Console.WriteLine("Error thrown as expected: " + ex.Message);
            }

            Console.WriteLine();
            Console.WriteLine("If we try and save a Triple we should also now get an error");
            try
            {
                manager.SaveTriple(null, "id");
                Assert.Fail("Trying to save a Triple once the Manager is disposed of should fail");
            }
            catch (RdfStorageException ex)
            {
                Console.WriteLine("Error thrown as expected: " + ex.Message);
            }

            manager = new NonNativeVirtuosoManager("test", "test", "test");
            Console.WriteLine();
            Console.WriteLine("Repeating the test but this time setting the PreserveState property to true");

            manager.PreserveState = true;
            manager.Dispose();
            try
            {
                manager.Dispose();
                manager.Dispose();
                Console.WriteLine("Subsequent Dispose() calls did not throw errors as expected since PreserveState is set to true");
            }
            catch (RdfStorageException)
            {
                Assert.Fail("Subsequent Dispose() calls should not error if PreserveState is set to true");
            }

            manager.PreserveState = false;
            manager.Dispose();
        }
コード例 #2
0
        public static void Main(String[] args)
        {
            StreamWriter output = new StreamWriter("VirtuosoTest.txt");
            Console.SetOut(output);
            try
            {
                Console.WriteLine("##Virtuoso Test Suite");
                Console.WriteLine();

                //Do some basic operations
                Console.WriteLine("# Basic Read and Write of normal Graphs");

                //Read in a Test Graph from a Turtle File
                Graph g = new Graph();
                g.BaseURI = new Uri("http://www.dotnetrdf.org/Tests/SQLStore/");
                TurtleParser ttlparser = new TurtleParser();
                ttlparser.Load(g, "InferenceTest.ttl");

                Console.WriteLine("Loaded the InferenceTest.ttl file as the Test Graph");
                Console.WriteLine("Attempting to save into the SQL Store");

                //Get the Non Native Virtuoso Manager
                NonNativeVirtuosoManager manager = new NonNativeVirtuosoManager("localhost", 1111, "dotnetrdf_experimental", "dba", "20sQl09");

                //Save to a Store using SqlWriter
                SqlWriter sqlwriter = new SqlWriter(manager);
                sqlwriter.Save(g, false);

                Console.WriteLine("Saved to the SQL Store");

                //Read back from the Store using SqlReader
                Graph h = new Graph();
                Console.WriteLine("Trying to read the Graph back from the SQL Store");
                SqlReader sqlreader = new SqlReader(manager);
                h = sqlreader.Load("http://www.dotnetrdf.org/Tests/SQLStore/");

                Console.WriteLine("Read from SQL Store OK");

                foreach (String prefix in h.NamespaceMap.Prefixes)
                {
                    Console.WriteLine(prefix + ": <" + h.NamespaceMap.GetNamespaceURI(prefix).ToString() + ">");
                }
                Console.WriteLine();
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Console.WriteLine("# Test Passed");
                Console.WriteLine();

                //Demonstrate that the SqlGraph persists stuff to the Store
                Console.WriteLine("# Advanced Read and Write with a SQLGraph");

                SqlGraph s = new SqlGraph(new Uri("http://www.dotnetrdf.org/Tests/SQLStore"), manager);
                Console.WriteLine("Opened the SQL Graph OK");

                INode type = s.CreateURINode("rdf:type");

                s.Assert(new Triple(type, type, type));

                Console.WriteLine("Asserted something");

                s.NamespaceMap.AddNamespace("ex", new Uri("http://www.example.org/"));
                Console.WriteLine("Added a Namespace");

                s.NamespaceMap.AddNamespace("ex", new Uri("http://www.example.org/changedNamespace/"));
                Console.WriteLine("Changed a Namespace");

                Console.WriteLine("Reopening to see if stuff gets loaded correctly");
                s = new SqlGraph(new Uri("http://www.dotnetrdf.org/Tests/SQLStore"), "dotnetrdf_experimental", "sa", "20sQl08");

                foreach (String prefix in s.NamespaceMap.Prefixes)
                {
                    Console.WriteLine(prefix + ": <" + s.NamespaceMap.GetNamespaceURI(prefix).ToString() + ">");
                }
                Console.WriteLine();
                foreach (Triple t in s.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                s.Retract(new Triple(type, type, type));
                Console.WriteLine("Retracted something");

                foreach (Triple t in s.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
            }
            catch (OpenLink.Data.Virtuoso.VirtuosoException virtEx)
            {
                reportError(output, "Virtuoso Exception", virtEx);
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                reportError(output, "SQL Exception", sqlEx);
            }
            catch (IOException ioEx)
            {
                reportError(output, "IO Exception", ioEx);
            }
            catch (RDFParseException parseEx)
            {
                reportError(output, "Parsing Exception", parseEx);
            }
            catch (RDFException rdfEx)
            {
                reportError(output, "RDF Exception", rdfEx);
            }
            catch (Exception ex)
            {
                reportError(output, "Other Exception", ex);
            }
            finally
            {
                output.Close();
            }
        }
コード例 #3
0
        /// <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;

                case NonNativeVirtuosoManager:
                    if (user != null && pwd != null)
                    {
                        int p = -1;
                        port = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPort));
                        if (port != null)
                        {
                            if (!Int32.TryParse(port, out p)) break;
                            manager = new NonNativeVirtuosoManager(server, p, db, user, pwd);
                        }
                        else
                        {
                            manager = new NonNativeVirtuosoManager(server, db, user, pwd);
                        }
                    }
                    break;

            }
            obj = manager;
            return (manager != null);
        }
コード例 #4
0
        /// <summary>
        /// Attempts to load an Object of the given type identified by the given Node and returned as the Type that this loader generates
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        /// <param name="targetType">Target Type</param>
        /// <param name="obj">Created Object</param>
        /// <returns>True if the loader succeeded in creating an Object</returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            obj = null;

            String server, port, db, user, pwd;
            int p = -1;

            //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) db = VirtuosoManager.DefaultDB;

            //Get Port
            port = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPort));
            if (!Int32.TryParse(port, out p)) p = VirtuosoManager.DefaultPort;

            //Get user credentials
            ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
            if (user == null || pwd == null) return false;

            //Based on this information create a Manager if possible
            switch (targetType.FullName)
            {
                case NonNativeVirtuosoManager:
                    obj = new NonNativeVirtuosoManager(server, p, db, user, pwd);
                    break;

                case Virtuoso:
                    //Get Server settings
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;

                    obj = new VirtuosoManager(server, p, db, user, pwd);

                    break;
            }

            return (obj != null);
        }