use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class ArbitraryLengthQueryTest method load.
/**
* Load the t-box and a-box turtle from strings defined within this class.
*
* @throws RepositoryException
* @throws RDFParseException
* @throws IOException
*/
private void load() throws RepositoryException, RDFParseException, IOException {
final RepositoryConnection conn = repository.getConnection();
// T-Box
String ttlString = MODEL_TTL;
InputStream stringInput = new ByteArrayInputStream(ttlString.getBytes());
conn.add(stringInput, "http://dragon-research.com/cham/model/model1", RDFFormat.TURTLE, new Resource[] {});
// A-Box
ttlString = BUCKET_TTL;
stringInput = new ByteArrayInputStream(ttlString.getBytes());
conn.add(stringInput, "http://dragon-research.com/cham/bucket/bucket1", RDFFormat.TURTLE, new Resource[] {});
conn.commit();
conn.close();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testDuplicateLiterals.
public void testDuplicateLiterals() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
Literal lit1 = vf.createLiteral(0.0);
Literal lit2 = vf.createLiteral(0.0);
Literal lit3 = vf.createLiteral(0.0);
conn.add(cpu, loadPerc, lit1);
conn.add(cpu, loadPerc, lit2);
conn.add(cpu, loadPerc, lit3);
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, lit1);
conn.close();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testNamedGraphLoad2.
public void testNamedGraphLoad2() throws Exception {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
assertNotNull(stream);
RepositoryConnection conn = repository.getConnection();
conn.add(stream, "", RDFFormat.TRIG);
conn.commit();
RepositoryResult<Statement> statements = conn.getStatements(null, vf.createURI("http://www.example.org/vocabulary#name"), null, true, vf.createURI("http://www.example.org/exampleDocument#G1"));
int count = 0;
while (statements.hasNext()) {
statements.next();
count++;
}
statements.close();
assertEquals(1, count);
conn.close();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testClearGraph.
public void testClearGraph() 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(new URIImpl("http://example/addresses#G2"));
tupleQuery.evaluate(tupleHandler);
assertEquals(2, tupleHandler.getCount());
tupleHandler = new CountTupleHandler();
conn.clear(new URIImpl("http://example/addresses#G1"));
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 testSPOPredRange.
public void testSPOPredRange() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc1");
URI loadPerc2 = vf.createURI(litdupsNS, "loadPerc2");
URI loadPerc3 = vf.createURI(litdupsNS, "loadPerc3");
URI loadPerc4 = vf.createURI(litdupsNS, "loadPerc4");
Literal six = vf.createLiteral("6");
Literal sev = vf.createLiteral("7");
Literal ten = vf.createLiteral("10");
conn.add(cpu, loadPerc, six);
conn.add(cpu, loadPerc2, sev);
conn.add(cpu, loadPerc4, ten);
conn.commit();
String query = "PREFIX org.apache: <" + NAMESPACE + ">\n" + "select * where {" + "<" + cpu.stringValue() + "> ?p ?o.\n" + "FILTER(org.apache:range(?p, <" + loadPerc.stringValue() + ">, <" + loadPerc3.stringValue() + ">))." + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
CountTupleHandler cth = new CountTupleHandler();
tupleQuery.evaluate(cth);
conn.close();
assertEquals(2, cth.getCount());
}
Aggregations