コード例 #1
0
  @Test
  public void testFullQueryWorks() {
    ReconnectingDatasetGraph toQuery =
        (ReconnectingDatasetGraph)
            ((Dataset) AssemblerUtils.build("basic.ttl", SDBConnect.TYPE)).asDatasetGraph();
    toQuery.getDatasetGraph().getStore().getTableFormatter().format();
    Dataset ds = DatasetImpl.wrap(toQuery);
    // Dataset ds = new DatasetImpl(toQuery);
    QueryExecution qe = QueryExecutionFactory.create("SELECT * { ?s ?p ?o }", ds);
    ResultSet r = qe.execSelect();
    assertTrue("Querying works", !r.hasNext());
    qe.close();

    qe = QueryExecutionFactory.create("SELECT * { graph ?g { ?s ?p ?o } }", ds);
    r = qe.execSelect();
    assertTrue("Querying with named graphs works", !r.hasNext());
    qe.close();
  }
コード例 #2
0
  @Test
  public void testReconnectWorks() {
    ReconnectingDatasetGraph toQuery =
        (ReconnectingDatasetGraph)
            ((Dataset) AssemblerUtils.build("basic.ttl", SDBConnect.TYPE)).asDatasetGraph();
    toQuery.getDatasetGraph().getStore().getTableFormatter().format();
    Dataset ds = DatasetImpl.wrap(toQuery);
    // Dataset ds = new DatasetImpl(toQuery);
    QueryExecution qe = QueryExecutionFactory.create("ASK { ?s ?p ?o }", ds);
    assertTrue("Querying still works", !qe.execAsk());

    // Haha! Say goodbye!
    toQuery.getDatasetGraph().getStore().getConnection().close();

    qe = QueryExecutionFactory.create("ASK { ?s ?p ?o }", ds);
    assertTrue("Reconnected query still works", !qe.execAsk());

    qe = QueryExecutionFactory.create("ASK { ?s ?p ?o }", ds);
    assertTrue("Reconnected query works with test", !qe.execAsk());
  }
コード例 #3
0
  @Test
  public void testUnionWorks() {
    Dataset ds = (Dataset) AssemblerUtils.build("union.ttl", SDBConnect.TYPE);
    ReconnectingDatasetGraph toQuery = (ReconnectingDatasetGraph) ds.asDatasetGraph();
    toQuery.getDatasetGraph().getStore().getTableFormatter().format();
    UpdateRequest ur =
        UpdateFactory.create(
            "insert data {"
                + "graph <http://example.com/a> { <http://example.com/1> <http://example.com/prop> 1 }"
                + "graph <http://example.com/b> { <http://example.com/2> <http://example.com/prop> 2 }"
                + "}");
    UpdateProcessor u = UpdateExecutionFactory.create(ur, toQuery);
    u.execute();

    QueryExecution qe = QueryExecutionFactory.create("SELECT * { ?s ?p ?o }", ds);
    ResultSetRewindable r = ResultSetFactory.makeRewindable(qe.execSelect());

    assertEquals("We have a union!", 2, r.size());
  }