Package org.openrdf.repository.contextaware

Examples of org.openrdf.repository.contextaware.ContextAwareConnection


        }
    };

    @Test
    public void testSinglePattern() throws Exception {
        ContextAwareConnection con = new ContextAwareConnection(repository, repository.getConnection());
        try {
            con.setInsertContext(context1);
            con.setReadContexts(context1);
            con.setRemoveContexts(context1);

            Assert.assertTrue(con.hasStatement(subject,predicate1, object11));
            Assert.assertFalse(con.hasStatement(subject, predicate2, object21));

            String queryStr = "SELECT ?X ?Z WHERE { ?X ?Y ?Z }";

            TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStr);
            List<BindingSet> result = Iterations.asList(query.evaluate());
            Assert.assertEquals(2,result.size());
            con.commit();
        } finally {
            con.close();
        }
    }
View Full Code Here


        }
    }

    @Test
    public void testJoinPattern() throws Exception {
        ContextAwareConnection con = new ContextAwareConnection(repository, repository.getConnection());
        try {
            con.setInsertContext(context1);
            con.setReadContexts(context1);
            con.setRemoveContexts(context1);

            Assert.assertTrue(con.hasStatement(subject,predicate1, object11));
            Assert.assertFalse(con.hasStatement(subject, predicate2, object21));

            String queryStr = "SELECT ?X ?Z WHERE { ?X ?P ?Y . ?Y ?P ?Z }";

            TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStr);
            List<BindingSet> result = Iterations.asList(query.evaluate());
            Assert.assertEquals(1,result.size());
            con.commit();
        } finally {
            con.close();
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testNamedGraphQuery() throws Exception {
        ContextAwareConnection con = new ContextAwareConnection(repository, repository.getConnection());
        try {
            con.setInsertContext(context1);
            con.setReadContexts(context1);
            con.setRemoveContexts(context1);

            Assert.assertTrue(con.hasStatement(subject,predicate1, object11));
            Assert.assertFalse(con.hasStatement(subject, predicate2, object21));

            String queryStr1 = "SELECT * WHERE { GRAPH <"+context1.stringValue()+"> { ?X ?P ?Y } }";

            TupleQuery query1 = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStr1);

            // workaround for a bug in sesame
            DatasetImpl ds = new DatasetImpl();
            ds.addDefaultGraph(context1);
            ds.addNamedGraph(context1);
            ds.addDefaultRemoveGraph(context1);
            ds.setDefaultInsertGraph(context1);
            query1.setDataset(ds);


            List<BindingSet> result1 = Iterations.asList(query1.evaluate());
            Assert.assertEquals(2, result1.size());

            String queryStr2 = "SELECT * WHERE { GRAPH <"+context2.stringValue()+"> { ?X ?P ?Y  } }";

            TupleQuery query2 = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStr2);
            List<BindingSet> result2 = Iterations.asList(query2.evaluate());
            Assert.assertEquals(0, result2.size());

            con.commit();
        } finally {
            con.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.openrdf.repository.contextaware.ContextAwareConnection

Copyright © 2018 www.massapicom. 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.