@Override @Deprecated public void setAutocommit(boolean autocommit) { assertModel(); if (autocommit == false) { try { this.connection.begin(); } catch (RepositoryException e) { throw new RuntimeException(e); } } else { try { this.connection.commit(); } catch(RepositoryException e) { throw new RuntimeException(e); } } }
@Test public void testAutoCommit() throws Exception { testCon.begin(); testCon.add(alice, name, nameAlice); assertTrue("Uncommitted update should be visible to own connection", testCon.hasStatement(alice, name, nameAlice, false)); testCon.commit(); assertTrue("Repository should contain statement after commit", testCon.hasStatement(alice, name, nameAlice, false)); }
@Test public void testContextHandling() throws Exception { connection.add(SUBJECT_4, PREDICATE_1, new LiteralImpl("sfourponecone"), CONTEXT_1); connection.add(SUBJECT_4, PREDICATE_2, new LiteralImpl("sfourptwocone"), CONTEXT_1); connection.add(SUBJECT_5, PREDICATE_1, new LiteralImpl("sfiveponecone"), CONTEXT_1); connection.add(SUBJECT_5, PREDICATE_1, new LiteralImpl("sfiveponectwo"), CONTEXT_2); connection.add(SUBJECT_5, PREDICATE_2, new LiteralImpl("sfiveptwoctwo"), CONTEXT_2); connection.commit(); // connection.close(); // connection = repository.getConnection(); // connection.setAutoCommit(false); // test querying assertQueryResult("sfourponecone", PREDICATE_1, SUBJECT_4); assertQueryResult("sfourptwocone", PREDICATE_2, SUBJECT_4); assertQueryResult("sfiveponecone", PREDICATE_1, SUBJECT_5); assertQueryResult("sfiveponectwo", PREDICATE_1, SUBJECT_5); assertQueryResult("sfiveptwoctwo", PREDICATE_2, SUBJECT_5); // blind test to see if this method works: assertNoQueryResult("johannesgrenzfurthner"); // remove a context connection.clear(CONTEXT_1); connection.commit(); assertNoQueryResult("sfourponecone"); assertNoQueryResult("sfourptwocone"); assertNoQueryResult("sfiveponecone"); assertQueryResult("sfiveponectwo", PREDICATE_1, SUBJECT_5); assertQueryResult("sfiveptwoctwo", PREDICATE_2, SUBJECT_5); }
@Test public void testDuplicateFilter() throws Exception { testCon.begin(); testCon.add(bob, name, nameBob); testCon.add(bob, name, nameBob, context1); testCon.add(bob, name, nameBob, context2); testCon.commit(); RepositoryResult<Statement> result = testCon.getStatements(bob, name, null, true); result.enableDuplicateFilter(); int count = 0; while (result.hasNext()) { result.next(); count++; } assertThat(count, is(equalTo(1))); }
@Test public void testNullContextHandling() throws Exception connection.add(SUBJECT_4, PREDICATE_1, new LiteralImpl("sfourponecone")); connection.add(SUBJECT_4, PREDICATE_2, new LiteralImpl("sfourptwocone")); connection.add(SUBJECT_5, PREDICATE_1, new LiteralImpl("sfiveponecone")); connection.add(SUBJECT_5, PREDICATE_1, new LiteralImpl("sfiveponectwo"), CONTEXT_2); connection.add(SUBJECT_5, PREDICATE_2, new LiteralImpl("sfiveptwoctwo"), CONTEXT_2); connection.commit(); connection.commit(); assertNoQueryResult("sfourponecone"); assertNoQueryResult("sfourptwocone");
@Test @SuppressWarnings("unchecked") public void testNamespaces() throws RepositoryException { RepositoryConnection connection = repository.getConnection(); connection.begin(); connection.setNamespace("ns1","http://localhost/ns1/"); connection.setNamespace("ns2","http://localhost/ns2/"); connection.commit(); connection.begin(); connection.setNamespace("ns1","http://localhost/ns3/"); connection.commit(); connection.begin(); connection.removeNamespace("ns2"); connection.commit(); connection.begin(); connection.commit(); connection.close();
RepositoryConnection conn = rep.getConnection(); try { conn.begin(); // start a transaction conn.add(f.createURI("http://example.org/", "Turin"),RDF.PREDICATE,f.createURI("http://example.org/", "Timon")); conn.add(f.createURI("http://example.org/", "Turin"),RDF.PREDICATE,f.createURI("http://example.org/", "Timon")); conn.add(f.createURI("http://example.org/", "Timon"),RDF.PREDICATE, f.createURI("http://example.org/", "eddy")); conn.add(f.createURI("http://example.org/", "Pumba"),RDF.PREDICATE, f.createURI("http://example.org/", "Timon")); conn.commit(); } finally { conn.close(); }
/** * Note: Overridden to turn off autocommit and commit after the data are * loaded. */ protected void loadDataset(String datasetFile) throws RDFParseException, RepositoryException, IOException { logger.debug("loading dataset..."); InputStream dataset = SPARQLUpdateTest.class.getResourceAsStream(datasetFile); try { // con.setAutoCommit(false); con.add(dataset, "", RDFFormat.forFileName(datasetFile));//RDFFormat.TRIG); con.commit(); } finally { dataset.close(); } logger.debug("dataset loaded."); }
@Override public Query parseQuery(QueryLanguage language, String query) throws RepositoryException, MalformedQueryException { Query sparqlQuery = null; RepositoryConnection connection = sesameService.getConnection(); try { connection.begin(); sparqlQuery = connection.prepareQuery(language, query); connection.commit(); } finally { connection.close(); } return sparqlQuery; }
@Test public void testTransactionIsolation() throws Exception { testCon.begin(); testCon.add(bob, name, nameBob); assertThat(testCon.hasStatement(bob, name, nameBob, false), is(equalTo(true))); assertThat(testCon2.hasStatement(bob, name, nameBob, false), is(equalTo(false))); testCon.commit(); testCon2.close(); testCon2 = testRepository.getConnection(); assertThat(testCon.hasStatement(bob, name, nameBob, false), is(equalTo(true))); assertThat(testCon2.hasStatement(bob, name, nameBob, false), is(equalTo(true))); }
@Test public void testConcurrentReadingAndWriting() throws Exception connection.add(SUBJECT_1, PREDICATE_1, new LiteralImpl("sfourponecone"), CONTEXT_1); connection.add(SUBJECT_2, PREDICATE_1, new LiteralImpl("sfourponecone"), CONTEXT_1); connection.commit(); BindingSet bindings = result.next(); connection.add(SUBJECT_3, PREDICATE_1, new LiteralImpl("sfourponecone"), CONTEXT_1); connection.commit(); connection.add(SUBJECT_3, PREDICATE_1, new LiteralImpl("blubbb"), CONTEXT_1); connection.commit();
@Test public void testDummyProvider() throws Exception { ClientResponse resp1 = ldclient.retrieveResource("http://localhost/resource1"); RepositoryConnection con1 = ModelCommons.asRepository(resp1.getData()).getConnection(); try { con1.begin(); Assert.assertEquals(3, con1.size()); con1.commit(); } finally { con1.close(); } ClientResponse resp2 = ldclient.retrieveResource("http://localhost/resource2"); RepositoryConnection con2 = ModelCommons.asRepository(resp2.getData()).getConnection(); try { con2.begin(); Assert.assertEquals(2, con2.size()); con2.commit(); } finally { con2.close(); } ClientResponse resp3 = ldclient.retrieveResource("http://localhost/resource3"); RepositoryConnection con3 = ModelCommons.asRepository(resp3.getData()).getConnection(); try { con3.begin(); Assert.assertEquals(2, con3.size()); con3.commit(); } finally { con3.close(); } }
/** * Handles a statement. * * The statements will be added up until chunk size is reached. * After a chunk of statements is added the transaction will be committed * and new transaction will be started. * @param stmnt * @throws RDFHandlerException */ @Override public void handleStatement(Statement stmnt) throws RDFHandlerException { try { // check if triple should be added to a specific graph if (dctx != null) { conn.add(stmnt, dctx); } else { conn.add(stmnt); } // check if chunk size is reached and transaction should be // committed count++; if (count >= size) { count = 0; conn.commit(); conn.begin(); } } catch (RepositoryException ex) { throw new RDFHandlerException(ex); } }
/** * Note: Overridden to turn off autocommit and commit after the data are * loaded. */ @Override protected void loadDataset(String datasetFile) throws RDFParseException, RepositoryException, IOException { logger.debug("loading dataset..."); InputStream dataset = SPARQLUpdateTest.class.getResourceAsStream(datasetFile); try { // con.setAutoCommit(false); con.add(dataset, "", RDFFormat.forFileName(datasetFile));//RDFFormat.TRIG); con.commit(); } finally { dataset.close(); } logger.debug("dataset loaded."); }
@Override public Query parseQuery(QueryLanguage language, String query) throws RepositoryException, MalformedQueryException { Query sparqlQuery = null; RepositoryConnection connection = sesameService.getConnection(); try { connection.begin(); sparqlQuery = connection.prepareQuery(language, query); connection.commit(); } finally { connection.close(); } return sparqlQuery; }