Examples of SailConnection


Examples of org.openrdf.sail.SailConnection

        }
    }

    @Test
    public void testGetNamespaces() throws Exception {
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            CloseableIteration<? extends Namespace, SailException> namespaces;
            int before = 0, during = 0, after = 0;
            // just iterate through all namespaces
            namespaces = sc.getNamespaces();
            while (namespaces.hasNext()) {
                Namespace ns = namespaces.next();
                before++;
                // System.out.println("namespace: " + ns);
            }
            namespaces.close();
            // Note: assumes that these namespace prefixes are unused.
            int nTests = 10;
            String prefixPrefix = "testns";
            String namePrefix = "http://example.org/test";
            for (int i = 0; i < nTests; i++) {
                sc.setNamespace(prefixPrefix + i, namePrefix + i);
            }
            sc.commit();
            sc.begin();
            namespaces = sc.getNamespaces();
            while (namespaces.hasNext()) {
                Namespace ns = namespaces.next();
                during++;
                String prefix = ns.getPrefix();
                String name = ns.getName();
                if (prefix.startsWith(prefixPrefix)) {
                    assertEquals(name, namePrefix + prefix.substring(prefixPrefix.length()));
                }
            }
            namespaces.close();
            for (int i = 0; i < nTests; i++) {
                sc.removeNamespace(prefixPrefix + i);
            }
            sc.commit();
            sc.begin();
            namespaces = sc.getNamespaces();
            while (namespaces.hasNext()) {
                namespaces.next();
                after++;
            }
            namespaces.close();
            assertEquals(during, before + nTests);
            assertEquals(after, before);
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

        }
    }

    @Test
    public void testSetNamespace() throws Exception {
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            String prefix = "foo";
            String emptyPrefix = "";
            String name = "http://example.org/foo";
            String otherName = "http://example.org/bar";

            sc.removeNamespace(prefix);
            sc.removeNamespace(emptyPrefix);
            sc.commit();
            sc.begin();

            // Namespace initially absent?
            assertNull(sc.getNamespace(prefix));
            assertNull(sc.getNamespace(emptyPrefix));

            // Can we set the namespace?
            sc.setNamespace(prefix, name);
            sc.commit();
            sc.begin();
            assertEquals(sc.getNamespace(prefix), name);

            // Can we reset the namespace?
            sc.setNamespace(prefix, otherName);
            sc.commit();
            sc.begin();
            assertEquals(sc.getNamespace(prefix), otherName);

            // Can we use an empty namespace prefix?
            sc.setNamespace(emptyPrefix, name);
            sc.commit();
            sc.begin();
            assertEquals(sc.getNamespace(emptyPrefix), name);
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

        }
    }

    @Test
    public void testRemoveNamespace() throws Exception {
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            String prefix = "foo";
            String emptyPrefix = "";
            String name = "http://example.org/foo";

            // Set namespace initially.
            sc.setNamespace(prefix, name);
            sc.commit();
            sc.begin();
            assertEquals(sc.getNamespace(prefix), name);

            // Remove the namespace and make sure it's gone.
            sc.removeNamespace(prefix);
            sc.commit();
            sc.begin();
            assertNull(sc.getNamespace(prefix));

            // Same thing for the default namespace.
            sc.setNamespace(emptyPrefix, name);
            sc.commit();
            sc.begin();
            assertEquals(sc.getNamespace(emptyPrefix), name);
            sc.removeNamespace(emptyPrefix);
            sc.commit();
            sc.begin();
            assertNull(sc.getNamespace(emptyPrefix));
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

    // connections and transactions ////////////////////////////////////////////

    @Test
    public void testPersistentCommits() throws Exception {
        SailConnection sc;
        int count;
        URI uriA = sail.getValueFactory().createURI("http://example.org/test/persistentCommits#a");
        URI uriB = sail.getValueFactory().createURI("http://example.org/test/persistentCommits#b");
        URI uriC = sail.getValueFactory().createURI("http://example.org/test/persistentCommits#c");
        sc = sail.getConnection();
        try {
            sc.begin();
            count = countStatements(sc, uriA, null, null, false);
            assertEquals(0, count);
            sc.rollback();
            sc.close();

            sc = sail.getConnection();
            sc.begin();
            sc.addStatement(uriA, uriB, uriC);
            count = countStatements(sc, uriA, null, null, false);
            assertEquals(1, count);
            sc.commit();
            sc.close();

            sc = sail.getConnection();
            sc.begin();
            count = countStatements(sc, uriA, null, null, false);
            assertEquals(1, count);
            sc.rollback();
            sc.close();

            sc = sail.getConnection();
            sc.begin();
            sc.removeStatements(uriA, null, null);
            count = countStatements(sc, uriA, null, null, false);
            assertEquals(0, count);
            sc.commit();
            sc.close();

            sc = sail.getConnection();
            sc.begin();
            count = countStatements(sc, uriA, null, null, false);
            assertEquals(0, count);
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

        URI uriA = sail.getValueFactory().createURI("http://example.org/test/nullContext#a");
        URI uriB = sail.getValueFactory().createURI("http://example.org/test/nullContext#b");
        URI uriC = sail.getValueFactory().createURI("http://example.org/test/nullContext#c");
        int count = 0;

        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            count = countStatements(sc, uriA, null, null, false);
            assertEquals(0, count);
            sc.addStatement(uriA, uriB, uriC);
            Statement statement = sc.getStatements(uriA, uriB, uriC, false, new Resource[]{null}).next();
            Resource context = statement.getContext();
            assertNull(context);
            sc.removeStatements(uriA, null, null);
            sc.commit();
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

            URI uriA = sail.getValueFactory().createURI("http://example.org/uriA");
            URI uriB = sail.getValueFactory().createURI("http://example.org/uriB");
            URI classX = sail.getValueFactory().createURI("http://example.org/classX");
            URI classY = sail.getValueFactory().createURI("http://example.org/classY");

            SailConnection sc = inferencer.getConnection();
            try {
                sc.clear();

                sc.addStatement(classX, RDFS.SUBCLASSOF, classY);
                sc.addStatement(uriA, RDF.TYPE, classX);
                sc.addStatement(uriB, RDF.TYPE, classY);
                sc.commit();

                //showStatements(sc, uriA, RDF.TYPE, null);

                assertEquals(3, countStatements(sc, uriA, RDF.TYPE, null, true));
                assertEquals(1, countStatements(sc, uriA, RDF.TYPE, null, false));
                assertEquals(2, countStatements(sc, uriB, RDF.TYPE, null, true));
                assertEquals(1, countStatements(sc, uriB, RDF.TYPE, null, false));

                if (uniqueStatements) {
                    sc.addStatement(uriA, RDF.TYPE, classY);
                    sc.commit();

                    //showStatements(sc, uriA, RDF.TYPE, null);
                    assertEquals(3, countStatements(sc, uriA, RDF.TYPE, null, true));
                    assertEquals(2, countStatements(sc, uriA, RDF.TYPE, null, false));

                    sc.removeStatements(uriA, RDF.TYPE, classY);
                    sc.commit();

                    assertEquals(3, countStatements(sc, uriA, RDF.TYPE, null, true));
                    assertEquals(2, countStatements(sc, uriA, RDF.TYPE, null, false));

                    //sc.removeStatements(uriA, RDF.TYPE, classX);
                    //sc.commit();
                    //assertEquals(1, countStatements(sc, uriA, RDF.TYPE, null));
                }
            } finally {
                sc.rollback();
                sc.close();
            }
        }
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

     *                        Files must be named with a format-appropriate extension, e.g. *.rdf, *.ttl, *.nt
     *                        or a format-appropriate extension followed by .gz if they are compressed with Gzip.
     */
    public synchronized void load(final File fileOrDirectory) throws Exception {
        LOGGER.info("loading from " + fileOrDirectory);
        SailConnection c = sail.getConnection();
        try {
            c.begin();
            long startTime = System.currentTimeMillis();

            long count = loadFile(fileOrDirectory, c);

            // commit leftover statements
            c.commit();

            long endTime = System.currentTimeMillis();

            LOGGER.info("loaded " + count + " statements in " + (endTime - startTime) + "ms");
        } finally {
            c.rollback();
            c.close();
        }
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

        before();
        this.sail = createSail();
        sail.initialize();

        if (sail instanceof NotifyingSail) {
            SailConnection sc = sail.getConnection();
            try {
                if (sc instanceof InferencerConnection) {
                    inferencer = new ForwardChainingRDFSInferencer((NotifyingSail) sail);
                }
            } finally {
                sc.rollback();
                sc.close();
            }
        }

        addFile(SailTest.class.getResourceAsStream("graph-example-sail-test.trig"), RDFFormat.TRIG);
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

    // statement manipulation //////////////////////////////////////////////////

    @Test
    public void testGetStatementsS_POG() throws Exception {
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            URI uriA = sail.getValueFactory().createURI("http://example.org/test/S_POG#a");
            URI uriB = sail.getValueFactory().createURI("http://example.org/test/S_POG#b");
            URI uriC = sail.getValueFactory().createURI("http://example.org/test/S_POG#c");
            URI uriD = sail.getValueFactory().createURI("http://example.org/test/S_POG#d");
            int before, after;

            // default context, different S,P,O
            sc.removeStatements(uriA, null, null);
            sc.commit();
            sc.begin();
            before = countStatements(sc, uriA, null, null, false);
            sc.addStatement(uriA, uriB, uriC);
            sc.commit();
            sc.begin();
            after = countStatements(sc, uriA, null, null, false);
            assertEquals(0, before);
            System.out.flush();
            assertEquals(1, after);

            // one specific context, different S,P,O
            sc.removeStatements(uriA, null, null, uriD);
            sc.commit();
            sc.begin();
            before = countStatements(sc, uriA, null, null, false, uriD);
            sc.addStatement(uriA, uriB, uriC, uriD);
            sc.commit();
            sc.begin();
            after = countStatements(sc, uriA, null, null, false, uriD);
            assertEquals(0, before);
            assertEquals(1, after);

            // one specific context, same S,P,O,G
            sc.removeStatements(uriA, null, null, uriA);
            sc.commit();
            sc.begin();
            before = countStatements(sc, uriA, null, null, false, uriA);
            sc.addStatement(uriA, uriB, uriC, uriA);
            sc.commit();
            sc.begin();
            after = countStatements(sc, uriA, null, null, false, uriA);
            assertEquals(0, before);
            assertEquals(1, after);

            // default context, same S,P,O
            sc.removeStatements(uriA, null, null);
            sc.commit();
            sc.begin();
            before = countStatements(sc, uriA, null, null, false);
            sc.addStatement(uriA, uriB, uriC);
            sc.commit();
            sc.begin();
            after = countStatements(sc, uriA, null, null, false);
            assertEquals(0, before);
            assertEquals(1, after);
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here

Examples of org.openrdf.sail.SailConnection

        }
    }

    @Test
    public void testGetStatementsSP_OG() throws Exception {
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            URI uriA = sail.getValueFactory().createURI("http://example.org/test/SP_OG#a");
            URI uriB = sail.getValueFactory().createURI("http://example.org/test/SP_OG#b");
            URI uriC = sail.getValueFactory().createURI("http://example.org/test/SP_OG#c");
            int before, after;

            // Add statement to the implicit null context.
            sc.removeStatements(null, null, null);
            before = countStatements(sc, uriA, uriB, null, false);
            sc.addStatement(uriA, uriB, uriC);
            sc.commit();
            sc.begin();
            after = countStatements(sc, uriA, uriB, null, false);
            assertEquals(0, before);
            assertEquals(1, after);
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.