use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testNotDuplicateUris.
public void testNotDuplicateUris() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
URI uri1 = vf.createURI(litdupsNS, "uri1");
URI uri2 = vf.createURI(litdupsNS, "uri1");
URI uri3 = vf.createURI(litdupsNS, "uri1");
conn.add(cpu, loadPerc, uri1);
conn.add(cpu, loadPerc, uri2);
conn.add(cpu, loadPerc, uri3);
conn.commit();
RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true, new Resource[0]);
int count = 0;
while (result.hasNext()) {
count++;
result.next();
}
result.close();
assertEquals(1, count);
// clean up
conn.remove(cpu, loadPerc, uri1);
conn.close();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testMMRTS152.
public void testMMRTS152() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "testPred");
URI uri1 = vf.createURI(litdupsNS, "uri1");
conn.add(cpu, loadPerc, uri1);
conn.commit();
RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, false, new Resource[0]);
while (result.hasNext()) {
assertTrue(result.hasNext());
assertNotNull(result.next());
}
conn.close();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testClearAllGraph.
public void testClearAllGraph() throws Exception {
RepositoryConnection conn = repository.getConnection();
String insert = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "PREFIX ex: <http://example/addresses#>\n" + "INSERT DATA\n" + "{ GRAPH ex:G1 {\n" + "<http://example/book3> dc:title \"A new book\" ;\n" + " dc:creator \"A.N.Other\" .\n" + "}\n" + "}";
Update update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
update.execute();
insert = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "PREFIX ex: <http://example/addresses#>\n" + "INSERT DATA\n" + "{ GRAPH ex:G2 {\n" + "<http://example/book3> dc:title \"A new book\" ;\n" + " dc:creator \"A.N.Other\" .\n" + "}\n" + "}";
update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
update.execute();
String query = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "select * where { <http://example/book3> ?p ?o. }";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(4, tupleHandler.getCount());
tupleHandler = new CountTupleHandler();
conn.clear();
tupleQuery.evaluate(tupleHandler);
assertEquals(0, tupleHandler.getCount());
conn.close();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testSymmPropOf.
public void testSymmPropOf() throws Exception {
if (internalInferenceEngine == null) {
// infer not supported;
return;
}
RepositoryConnection conn = repository.getConnection();
conn.add(new StatementImpl(vf.createURI(litdupsNS, "friendOf"), RDF.TYPE, OWL.SYMMETRICPROPERTY));
conn.add(new StatementImpl(vf.createURI(litdupsNS, "Bob"), vf.createURI(litdupsNS, "friendOf"), vf.createURI(litdupsNS, "Jeff")));
conn.add(new StatementImpl(vf.createURI(litdupsNS, "James"), vf.createURI(litdupsNS, "friendOf"), vf.createURI(litdupsNS, "Jeff")));
conn.commit();
conn.close();
internalInferenceEngine.refreshGraph();
conn = repository.getConnection();
String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:friendOf lit:Bob.}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(1, tupleHandler.getCount());
query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:friendOf lit:James.}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(1, tupleHandler.getCount());
query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:friendOf lit:Jeff.}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(2, tupleHandler.getCount());
conn.close();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testEvaluate.
// public void testAddAuth() throws Exception {
// RepositoryConnection conn = repository.getConnection();
// URI cpu = vf.createURI(litdupsNS, "cpu");
// URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
// URI uri1 = vf.createURI(litdupsNS, "uri1");
// URI uri2 = vf.createURI(litdupsNS, "uri2");
// URI uri3 = vf.createURI(litdupsNS, "uri3");
// URI auth1 = vf.createURI(RdfCloudTripleStoreConstants.AUTH_NAMESPACE, "1");
// URI auth2 = vf.createURI(RdfCloudTripleStoreConstants.AUTH_NAMESPACE, "2");
// URI auth3 = vf.createURI(RdfCloudTripleStoreConstants.AUTH_NAMESPACE, "3");
// conn.add(cpu, loadPerc, uri1, auth1, auth2, auth3);
// conn.add(cpu, loadPerc, uri2, auth2, auth3);
// conn.add(cpu, loadPerc, uri3, auth3);
// conn.commit();
//
// //query with no auth
// RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true);
// int count = 0;
// while (result.hasNext()) {
// count++;
// result.next();
// }
// assertEquals(0, count);
// result.close();
//
// String query = "select * where {" +
// "<" + cpu.toString() + "> ?p ?o1." +
// "}";
// TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
// tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
// CountTupleHandler cth = new CountTupleHandler();
// tupleQuery.evaluate(cth);
// assertEquals(2, cth.getCount());
//
// conn.close();
// }
public void testEvaluate() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
URI uri1 = vf.createURI(litdupsNS, "uri1");
conn.add(cpu, loadPerc, uri1);
conn.commit();
String query = "select * where {" + "?x <" + loadPerc.stringValue() + "> ?o1." + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
CountTupleHandler cth = new CountTupleHandler();
tupleQuery.evaluate(cth);
assertEquals(cth.getCount(), 1);
conn.close();
}
Aggregations