use of org.openrdf.sail.SailException in project blueprints by tinkerpop.
the class SailTest method testBlankNodes.
// blank nodes /////////////////////////////////////////////////////////////
@Test
public void testBlankNodes() throws Throwable {
URI uriA = sail.getValueFactory().createURI("http://example.org/test/S_POG#a");
URI uriB = sail.getValueFactory().createURI("http://example.org/test/S_POG#b");
SailConnection sc = sail.getConnection();
try {
sc.begin();
ValueFactory factory = sail.getValueFactory();
BNode bNode = factory.createBNode();
try {
sc.addStatement(uriA, uriA, bNode);
} catch (SailException se) {
// FIXME: not supporting blank nodes ATM
assertTrue(se.getCause() instanceof UnsupportedOperationException);
}
sc.commit();
} finally {
sc.rollback();
sc.close();
}
}
use of org.openrdf.sail.SailException in project blueprints by tinkerpop.
the class SailTest method showNamespaces.
private void showNamespaces(final SailConnection c) throws SailException {
System.out.println("namespaces:");
CloseableIteration<? extends Namespace, SailException> iter = c.getNamespaces();
try {
while (iter.hasNext()) {
Namespace n = iter.next();
System.out.println("\t" + n.getPrefix() + ":\t" + n.getName());
}
} finally {
iter.close();
}
}
use of org.openrdf.sail.SailException in project blueprints by tinkerpop.
the class GraphSailTest method testCodePlay.
@Test
public void testCodePlay() throws Exception {
Sail sail = new GraphSail(new TinkerGraph());
sail.initialize();
try {
SailConnection sc = sail.getConnection();
try {
sc.begin();
ValueFactory vf = sail.getValueFactory();
sc.addStatement(vf.createURI("http://tinkerpop.com#1"), vf.createURI("http://tinkerpop.com#knows"), vf.createURI("http://tinkerpop.com#3"), vf.createURI("http://tinkerpop.com"));
sc.addStatement(vf.createURI("http://tinkerpop.com#1"), vf.createURI("http://tinkerpop.com#name"), vf.createLiteral("marko"), vf.createURI("http://tinkerpop.com"));
sc.addStatement(vf.createURI("http://tinkerpop.com#3"), vf.createURI("http://tinkerpop.com#name"), vf.createLiteral("josh"), vf.createURI("http://tinkerpop.com"));
CloseableIteration<? extends Statement, SailException> results = sc.getStatements(null, null, null, false);
try {
System.out.println("get statements: ?s ?p ?o ?g");
while (results.hasNext()) {
System.out.println(results.next());
}
} finally {
results.close();
}
System.out.println("\nget statements: http://tinkerpop.com#3 ?p ?o ?g");
results = sc.getStatements(vf.createURI("http://tinkerpop.com#3"), null, null, false);
try {
while (results.hasNext()) {
System.out.println(results.next());
}
} finally {
results.close();
}
SPARQLParser parser = new SPARQLParser();
CloseableIteration<? extends BindingSet, QueryEvaluationException> sparqlResults;
String queryString = "SELECT ?x ?y WHERE { ?x <http://tinkerpop.com#knows> ?y }";
ParsedQuery query = parser.parseQuery(queryString, "http://tinkerPop.com");
System.out.println("\nSPARQL: " + queryString);
sparqlResults = sc.evaluate(query.getTupleExpr(), query.getDataset(), new EmptyBindingSet(), false);
try {
while (sparqlResults.hasNext()) {
System.out.println(sparqlResults.next());
}
} finally {
sparqlResults.close();
}
Graph graph = ((GraphSail) sail).getBaseGraph();
System.out.println();
for (Vertex v : graph.getVertices()) {
System.out.println("------");
System.out.println(v);
for (String key : v.getPropertyKeys()) {
System.out.println(key + "=" + v.getProperty(key));
}
}
for (Edge e : graph.getEdges()) {
System.out.println("------");
System.out.println(e);
for (String key : e.getPropertyKeys()) {
System.out.println(key + "=" + e.getProperty(key));
}
}
} finally {
sc.rollback();
sc.close();
}
} finally {
sail.shutDown();
}
}
use of org.openrdf.sail.SailException in project blueprints by tinkerpop.
the class SailTest method testClearNamespaces.
// namespaces //////////////////////////////////////////////////////////////
@Test
public void testClearNamespaces() throws Exception {
SailConnection sc = sail.getConnection();
try {
CloseableIteration<? extends Namespace, SailException> namespaces;
int count;
count = 0;
namespaces = sc.getNamespaces();
while (namespaces.hasNext()) {
namespaces.next();
count++;
}
namespaces.close();
assertTrue(count > 0);
// TODO: actually clear namespaces (but this wipes them out for
// subsequent tests)
} finally {
sc.rollback();
sc.close();
}
}
use of org.openrdf.sail.SailException in project backstage by zepheira.
the class Database method computeCachedInformation.
private void computeCachedInformation() {
if (_propertyRecords == null || _typeRecords == null) {
getRepository();
SailConnection sc = null;
try {
sc = _sail.getConnection();
} catch (SailException e) {
_logger.error("Failed to open sail connection in order to compute cached information", e);
} catch (Exception e) {
} finally {
}
if (sc != null) {
try {
internalBuildPropertyRecords(sc);
internalBuildTypeRecords(sc);
} finally {
try {
sc.close();
} catch (SailException e) {
_logger.warn("Failed to close sail connection", e);
}
}
}
}
}
Aggregations