use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testGetStatementsS_POG.
// 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();
}
}
use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testSailChangedListeners.
@Test
public void testSailChangedListeners() throws Exception {
if (sail instanceof NotifyingSail) {
final Collection<SailChangedEvent> events = new LinkedList<SailChangedEvent>();
SailChangedListener listener = new SailChangedListener() {
public void sailChanged(final SailChangedEvent event) {
events.add(event);
}
};
((NotifyingSail) sail).addSailChangedListener(listener);
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");
SailConnection sc = sail.getConnection();
try {
sc.begin();
sc.clear();
sc.commit();
sc.begin();
events.clear();
assertEquals(0, events.size());
sc.addStatement(uriA, uriB, uriC, uriA);
sc.addStatement(uriB, uriC, uriA, uriA);
// Events are buffered until the commit
assertEquals(0, events.size());
sc.commit();
sc.begin();
// Only one SailChangedEvent per commit
assertEquals(1, events.size());
SailChangedEvent event = events.iterator().next();
assertTrue(event.statementsAdded());
assertFalse(event.statementsRemoved());
events.clear();
assertEquals(0, events.size());
sc.removeStatements(uriA, uriB, uriC, uriA);
sc.commit();
sc.begin();
assertEquals(1, events.size());
event = events.iterator().next();
assertFalse(event.statementsAdded());
assertTrue(event.statementsRemoved());
events.clear();
assertEquals(0, events.size());
sc.clear();
sc.commit();
sc.begin();
assertEquals(1, events.size());
event = events.iterator().next();
assertFalse(event.statementsAdded());
assertTrue(event.statementsRemoved());
} finally {
sc.rollback();
sc.close();
}
}
}
use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testNullContext.
/*
// TODO: restore me... but only for ACID-compliant stores
@Ignore
@Test
public void testVisibilityOfChanges() throws Exception {
SailConnection sc1, sc2;
int count;
URI uriA = sail.getValueFactory().createURI(
"http://example.org/test/visibilityOfChanges#a");
sc1 = sail.getConnection();
sc2 = sail.getConnection();
try {
sc1.clear();
sc2.clear();
// Statement doesn't exist for either connection.
count = countStatements(sc1, uriA, null, null);
assertEquals(0, count);
count = countStatements(sc2, uriA, null, null);
assertEquals(0, count);
// First connection adds a statement. It is visible to the first
// connection, but not to the second.
sc1.addStatement(uriA, uriA, uriA);
count = countStatements(sc1, null, null, null);
assertEquals(1, count);
count = countStatements(sc2, uriA, null, null);
assertEquals(0, count);
// ...
}
finally {
sc2.close();
sc1.close();
}
}
*/
@Test
public void testNullContext() throws Exception {
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();
}
}
use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.
the class SailTest method testGetStatementsO_SPG.
@Test
public void testGetStatementsO_SPG() throws Exception {
SailConnection sc = sail.getConnection();
try {
sc.begin();
URI uriA = sail.getValueFactory().createURI("http://example.org/test/O_SPG#a");
URI uriB = sail.getValueFactory().createURI("http://example.org/test/O_SPG#b");
URI uriC = sail.getValueFactory().createURI("http://example.org/test/O_SPG#c");
Literal plainLitA = sail.getValueFactory().createLiteral("arbitrary plain literal 9548734867");
Literal stringLitA = sail.getValueFactory().createLiteral("arbitrary string literal 8765", XMLSchema.STRING);
int before, after;
// Add statement to a specific context.
sc.removeStatements(null, null, uriA, uriA);
sc.commit();
sc.begin();
before = countStatements(sc, null, null, uriA, false);
sc.addStatement(uriB, uriC, uriA);
sc.commit();
sc.begin();
after = countStatements(sc, null, null, uriA, 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, null, plainLitA, false);
sc.addStatement(uriA, uriA, plainLitA);
sc.commit();
sc.begin();
after = countStatements(sc, null, null, plainLitA, false);
assertEquals(0, before);
assertEquals(1, after);
// Add string-typed literal statement to the default context.
sc.removeStatements(null, null, plainLitA);
sc.commit();
sc.begin();
before = countStatements(sc, null, null, stringLitA, false);
sc.addStatement(uriA, uriA, stringLitA);
sc.commit();
sc.begin();
after = countStatements(sc, null, null, stringLitA, 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 testRemoveStatements.
@Test
public void testRemoveStatements() 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");
Resource[] contexts = { uriA, null };
int count;
// Remove from all contexts.
sc.removeStatements(uriA, null, null);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(0, count);
sc.addStatement(uriA, uriB, uriC, contexts);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(2, count);
sc.removeStatements(uriA, null, null);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(0, count);
// Remove from one partition context.
sc.removeStatements(uriA, null, null);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(0, count);
sc.addStatement(uriA, uriB, uriC, contexts);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(2, count);
Resource[] oneContext = { uriA };
sc.removeStatements(uriA, null, null, oneContext);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(1, count);
// Remove from the null context.
sc.removeStatements(uriA, null, null);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(0, count);
sc.addStatement(uriA, uriB, uriC, contexts);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(2, count);
Resource[] nullContext = { null };
sc.removeStatements(uriA, null, null, nullContext);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(1, count);
// Remove from more than one context.
sc.removeStatements(uriA, null, null);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(0, count);
sc.addStatement(uriA, uriB, uriC, contexts);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false);
assertEquals(2, count);
sc.removeStatements(uriA, null, null);
sc.commit();
sc.begin();
count = countStatements(sc, uriA, null, null, false, contexts);
assertEquals(0, count);
} finally {
sc.rollback();
sc.close();
}
}
Aggregations