Example #1
0
  @Before
  public void setUp() throws Exception {
    sail = createSail();

    con = sail.getConnection();

    // Create values
    vf = sail.getValueFactory();

    painter = vf.createURI(EXAMPLE_NS, PAINTER);
    paints = vf.createURI(EXAMPLE_NS, PAINTS);
    painting = vf.createURI(EXAMPLE_NS, PAINTING);
    picasso = vf.createURI(EXAMPLE_NS, PICASSO);
    guernica = vf.createURI(EXAMPLE_NS, GUERNICA);
    rembrandt = vf.createURI(EXAMPLE_NS, REMBRANDT);
    nightwatch = vf.createURI(EXAMPLE_NS, NIGHTWATCH);

    context1 = vf.createURI(EXAMPLE_NS, CONTEXT_1);
    context2 = vf.createURI(EXAMPLE_NS, CONTEXT_2);
  }
Example #2
0
 @After
 public void tearDown() throws Exception {
   try {
     if (con.isOpen()) {
       con.rollback();
       con.close();
     }
   } finally {
     sail.shutDown();
     sail = null;
   }
 }
Example #3
0
  @Test
  public void testDualConnections() throws Exception {
    SailConnection con2 = sail.getConnection();
    try {
      assertEquals(0, countAllElements());
      con.begin();
      con.addStatement(painter, RDF.TYPE, RDFS.CLASS);
      con.addStatement(painting, RDF.TYPE, RDFS.CLASS);
      con.addStatement(picasso, RDF.TYPE, painter, context1);
      con.addStatement(guernica, RDF.TYPE, painting, context1);
      con.commit();
      assertEquals(4, countAllElements());
      con2.begin();
      con2.addStatement(RDF.NIL, RDF.TYPE, RDF.LIST);
      String query = "SELECT S, P, O FROM {S} P {O}";
      ParsedTupleQuery tupleQuery =
          QueryParserUtil.parseTupleQuery(QueryLanguage.SERQL, query, null);
      assertEquals(
          5,
          countElements(
              con2.evaluate(
                  tupleQuery.getTupleExpr(), null, EmptyBindingSet.getInstance(), false)));
      Runnable clearer =
          new Runnable() {

            public void run() {
              try {
                con.begin();
                con.clear();
                con.commit();
              } catch (SailException e) {
                throw new RuntimeException(e);
              }
            }
          };
      Thread thread = new Thread(clearer);
      thread.start();
      Thread.yield();
      Thread.yield();
      con2.commit();
      thread.join();
    } finally {
      con2.close();
    }
  }