use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testPersistentCommits.
// 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();
}
}
use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testGetStatementsPO_SG.
@Test
public void testGetStatementsPO_SG() throws Exception {
SailConnection sc = sail.getConnection();
try {
sc.begin();
URI uriA = sail.getValueFactory().createURI("http://example.org/test/PO_SG#a");
URI uriB = sail.getValueFactory().createURI("http://example.org/test/PO_SG#b");
URI foo = sail.getValueFactory().createURI("http://example.org/ns#foo");
URI firstName = sail.getValueFactory().createURI("http://example.org/ns#firstName");
Literal plainLitA = sail.getValueFactory().createLiteral("arbitrary plain literal 8765675");
Literal fooLabel = sail.getValueFactory().createLiteral("foo", XMLSchema.STRING);
int before, after;
// Add statement to the implicit null context.
sc.removeStatements(null, null, null, uriA);
sc.commit();
sc.begin();
before = countStatements(sc, null, uriA, uriB, false);
sc.addStatement(uriA, uriA, uriB);
sc.commit();
sc.begin();
after = countStatements(sc, null, uriA, uriB, false);
assertEquals(0, before);
assertEquals(1, after);
// Add plain literal statement to the default context.
sc.removeStatements(null, null, plainLitA);
sc.commit();
sc.begin();
before = countStatements(sc, null, uriA, plainLitA, false);
sc.addStatement(uriA, uriA, plainLitA);
sc.addStatement(uriA, uriB, plainLitA);
sc.addStatement(uriB, uriB, plainLitA);
sc.commit();
sc.begin();
after = countStatements(sc, null, uriA, plainLitA, false);
assertEquals(0, before);
assertEquals(1, after);
// Add string-typed literal statement to the default context.
sc.removeStatements(null, null, fooLabel);
sc.commit();
sc.begin();
before = countStatements(sc, null, firstName, fooLabel, false);
sc.addStatement(foo, firstName, fooLabel);
sc.commit();
sc.begin();
after = countStatements(sc, null, firstName, fooLabel, false);
assertEquals(0, before);
assertEquals(1, after);
assertEquals(foo, toSet(sc.getStatements(null, firstName, fooLabel, false)).iterator().next().getSubject());
} finally {
sc.rollback();
sc.close();
}
}
use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testGetStatementsWithVariableContexts.
@Test
public void testGetStatementsWithVariableContexts() throws Exception {
SailConnection sc = sail.getConnection();
try {
sc.begin();
URI uriA = sail.getValueFactory().createURI("http://example.org/uriA");
URI uriB = sail.getValueFactory().createURI("http://example.org/uriB");
URI uriC = sail.getValueFactory().createURI("http://example.org/uriC");
int count;
sc.clear();
//sc.removeStatements(uriA, uriA, uriA);
sc.commit();
sc.begin();
Resource[] contexts = { uriA, null };
sc.addStatement(uriA, uriB, uriC, contexts);
sc.commit();
sc.begin();
// Get statements from all contexts.
count = countStatements(sc, uriA, null, null, false);
assertEquals(2, count);
// Get statements from a specific partition context.
count = countStatements(sc, null, null, null, false, uriA);
assertEquals(1, count);
// Get statements from the null context.
Resource[] c = { null };
count = countStatements(sc, null, null, null, false, c);
//assertTrue(count > 0);
assertEquals(1, count);
int countLast = count;
// Get statements from more than one context.
count = countStatements(sc, null, null, null, false, contexts);
assertEquals(1 + countLast, count);
} finally {
sc.rollback();
sc.close();
}
}
use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testGetStatementsSP_OG.
@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();
}
}
use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testRemoveNamespace.
@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();
}
}
Aggregations