Java Code Examples for org.eclipse.rdf4j.repository.RepositoryException#printStackTrace()

The following examples show how to use org.eclipse.rdf4j.repository.RepositoryException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnapshotTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_conflictInsert() throws Exception {
	a.add(PICASSO, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, PAINTS, NIGHTWATCH);
	b.add(REMBRANDT, PAINTS, ARTEMISIA);
	b.add(REMBRANDT, PAINTS, DANAE);
	a.begin(level);
	b.begin(level);
	// PICASSO *is* a known PAINTER
	a.add(PICASSO, PAINTS, GUERNICA);
	a.add(PICASSO, PAINTS, JACQUELINE);
	b.prepareUpdate(QueryLanguage.SPARQL,
			"INSERT { ?painting a <Painting> }\n" + "WHERE { [a <Painter>] <paints> ?painting }", NS).execute();
	a.commit();
	try {
		int size = size(b, null, PAINTS, null, false);
		b.commit();
		assertEquals(3, size);
		assertEquals(3, size(a, null, RDF.TYPE, PAINTING, false));
	} catch (RepositoryException e) {
		e.printStackTrace();
		assertTrue(e.getCause() instanceof SailConflictException);
		assertEquals(0, size(a, null, RDF.TYPE, PAINTING, false));
	}
}
 
Example 2
Source File: SnapshotTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_conflictOptionalInsert() throws Exception {
	a.add(PICASSO, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, PAINTS, NIGHTWATCH);
	b.add(REMBRANDT, PAINTS, ARTEMISIA);
	b.add(REMBRANDT, PAINTS, DANAE);
	a.begin(level);
	b.begin(level);
	// PICASSO *is* a known PAINTER
	a.add(PICASSO, PAINTS, GUERNICA);
	a.add(PICASSO, PAINTS, JACQUELINE);
	b.prepareUpdate(QueryLanguage.SPARQL, "INSERT { ?painting a <Painting> }\n" + "WHERE { ?painter a <Painter> "
			+ "OPTIONAL { ?painter <paints> ?painting } }", NS).execute();
	a.commit();
	try {
		int size = size(b, null, PAINTS, null, false);
		b.commit();
		assertEquals(3, size);
		assertEquals(10, size(a, null, null, null, false));
	} catch (RepositoryException e) {
		e.printStackTrace();
		assertTrue(e.getCause() instanceof SailConflictException);
		assertEquals(7, size(a, null, null, null, false));
	}
}
 
Example 3
Source File: SnapshotTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_conflictQuery() throws Exception {
	a.add(PICASSO, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, PAINTS, NIGHTWATCH);
	b.add(REMBRANDT, PAINTS, ARTEMISIA);
	b.add(REMBRANDT, PAINTS, DANAE);
	a.begin(level);
	b.begin(level);
	// PICASSO *is* a known PAINTER
	a.add(PICASSO, PAINTS, GUERNICA);
	a.add(PICASSO, PAINTS, JACQUELINE);
	List<Value> result = eval("painting", b, "SELECT ?painting " + "WHERE { [a <Painter>] <paints> ?painting }");
	for (Value painting : result) {
		b.add((Resource) painting, RDF.TYPE, PAINTING);
	}
	a.commit();
	try {
		int size = size(b, null, PAINTS, null, false);
		b.commit();
		assertEquals(3, size);
		assertEquals(3, size(a, null, RDF.TYPE, PAINTING, false));
	} catch (RepositoryException e) {
		e.printStackTrace();
		assertTrue(e.getCause() instanceof SailConflictException);
		assertEquals(0, size(a, null, RDF.TYPE, PAINTING, false));
	}
}
 
Example 4
Source File: SnapshotTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_conflictOptionalQuery() throws Exception {
	a.add(PICASSO, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, PAINTS, NIGHTWATCH);
	b.add(REMBRANDT, PAINTS, ARTEMISIA);
	b.add(REMBRANDT, PAINTS, DANAE);
	a.begin(level);
	b.begin(level);
	// PICASSO *is* a known PAINTER
	a.add(PICASSO, PAINTS, GUERNICA);
	a.add(PICASSO, PAINTS, JACQUELINE);
	List<Value> result = eval("painting", b,
			"SELECT ?painting " + "WHERE { ?painter a <Painter> " + "OPTIONAL { ?painter <paints> ?painting } }");
	for (Value painting : result) {
		if (painting != null) {
			b.add((Resource) painting, RDF.TYPE, PAINTING);
		}
	}
	a.commit();
	try {
		int size = size(b, null, PAINTS, null, false);
		b.commit();
		assertEquals(3, size);
		assertEquals(10, size(a, null, null, null, false));
	} catch (RepositoryException e) {
		e.printStackTrace();
		assertTrue(e.getCause() instanceof SailConflictException);
		assertEquals(7, size(a, null, null, null, false));
	}
}
 
Example 5
Source File: SnapshotTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_conflictOptionalFilterInsert() throws Exception {
	a.add(PICASSO, RDF.TYPE, PAINTER);
	a.add(PICASSO, PAINTS, GUERNICA);
	a.add(PICASSO, PAINTS, JACQUELINE);
	b.add(REMBRANDT, RDF.TYPE, PAINTER);
	b.add(REMBRANDT, PAINTS, NIGHTWATCH);
	b.add(REMBRANDT, PAINTS, ARTEMISIA);
	b.add(REMBRANDT, PAINTS, DANAE);
	a.begin(level);
	b.begin(level);
	a.add(GUERNICA, RDF.TYPE, PAINTING);
	a.add(JACQUELINE, RDF.TYPE, PAINTING);
	b.prepareUpdate(QueryLanguage.SPARQL,
			"INSERT { ?painting a <Painting> }\n" + "WHERE { [a <Painter>] <paints> ?painting "
					+ "OPTIONAL { ?painting a ?type  } FILTER (!bound(?type)) }",
			NS).execute();
	a.commit();
	try {
		int size = size(b, null, RDF.TYPE, PAINTING, false);
		b.commit();
		assertEquals(5, size);
		assertEquals(12, size(a, null, null, null, false));
	} catch (RepositoryException e) {
		e.printStackTrace();
		assertTrue(e.getCause() instanceof SailConflictException);
		assertEquals(9, size(a, null, null, null, false));
	}
}
 
Example 6
Source File: SnapshotTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_conflictRangeQuery() throws Exception {
	a.add(REMBRANDT, RDF.TYPE, PAINTER);
	a.add(REMBRANDT, PAINTS, NIGHTWATCH);
	a.add(REMBRANDT, PAINTS, ARTEMISIA);
	a.add(REMBRANDT, PAINTS, DANAE);
	a.add(REMBRANDT, PAINTS, JACOB);
	a.add(REMBRANDT, PAINTS, ANATOMY);
	a.add(ARTEMISIA, YEAR, lf.createLiteral(1634));
	a.add(NIGHTWATCH, YEAR, lf.createLiteral(1642));
	a.add(DANAE, YEAR, lf.createLiteral(1636));
	a.add(JACOB, YEAR, lf.createLiteral(1632));
	a.add(ANATOMY, YEAR, lf.createLiteral(1632));
	a.begin(level);
	b.begin(level);
	List<Value> result = eval("painting", b,
			"SELECT ?painting " + "WHERE { <rembrandt> <paints> ?painting . ?painting <year> ?year "
					+ "FILTER  (1631 <= ?year && ?year <= 1635) }");
	for (Value painting : result) {
		b.add((Resource) painting, PERIOD, lf.createLiteral("First Amsterdam period"));
	}
	a.add(REMBRANDT, PAINTS, BELSHAZZAR);
	a.add(BELSHAZZAR, YEAR, lf.createLiteral(1635));
	a.commit();
	try {
		int size = size(b, REMBRANDT, PAINTS, null, false);
		b.commit();
		assertEquals(5, size);
		assertEquals(16, size(a, null, null, null, false));
	} catch (RepositoryException e) {
		e.printStackTrace();
		assertTrue(e.getCause() instanceof SailConflictException);
		assertEquals(13, size(a, null, null, null, false));
	}
}
 
Example 7
Source File: SnapshotTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_conflictRangeInsert() throws Exception {
	a.add(REMBRANDT, RDF.TYPE, PAINTER);
	a.add(REMBRANDT, PAINTS, NIGHTWATCH);
	a.add(REMBRANDT, PAINTS, ARTEMISIA);
	a.add(REMBRANDT, PAINTS, DANAE);
	a.add(REMBRANDT, PAINTS, JACOB);
	a.add(REMBRANDT, PAINTS, ANATOMY);
	a.add(ARTEMISIA, YEAR, lf.createLiteral(1634));
	a.add(NIGHTWATCH, YEAR, lf.createLiteral(1642));
	a.add(DANAE, YEAR, lf.createLiteral(1636));
	a.add(JACOB, YEAR, lf.createLiteral(1632));
	a.add(ANATOMY, YEAR, lf.createLiteral(1632));
	a.begin(level);
	b.begin(level);
	b.prepareUpdate(QueryLanguage.SPARQL,
			"INSERT { ?painting <period> \"First Amsterdam period\" }\n"
					+ "WHERE { <rembrandt> <paints> ?painting . ?painting <year> ?year "
					+ "FILTER  (1631 <= ?year && ?year <= 1635) }",
			NS).execute();
	a.add(REMBRANDT, PAINTS, BELSHAZZAR);
	a.add(BELSHAZZAR, YEAR, lf.createLiteral(1635));
	a.commit();
	try {
		int size = size(b, REMBRANDT, PAINTS, null, false);
		b.commit();
		assertEquals(5, size);
		assertEquals(16, size(a, null, null, null, false));
	} catch (RepositoryException e) {
		e.printStackTrace();
		assertTrue(e.getCause() instanceof SailConflictException);
		assertEquals(13, size(a, null, null, null, false));
	}
}
 
Example 8
Source File: IsolationLevelTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Query results must not include statements added after the first result is read
 */
private void snapshotRead(IsolationLevel level) throws RepositoryException {
	clear(store);
	try (RepositoryConnection con = store.getConnection();) {
		con.begin(level);
		int size = 1;
		for (int i = 0; i < size; i++) {
			insertTestStatement(con, i);
		}
		int counter = 0;
		try (CloseableIteration<? extends Statement, RepositoryException> stmts = con.getStatements(null, null,
				null, false);) {
			while (stmts.hasNext()) {
				Statement st = stmts.next();
				counter++;
				if (counter < size) {
					// remove observed statement to force new state
					con.remove(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext());
					insertTestStatement(con, size + counter);
					insertTestStatement(con, size + size + counter);
				}
			}
		}
		try {
			con.commit();
		} catch (RepositoryException e) {
			// it is okay to abort after a dirty read
			e.printStackTrace();
			return;
		}
		assertEquals(size, counter);
	}
}