use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestUpdateOperations method delete_insert_where_01.
// Check constant and template quads
@Test
public void delete_insert_where_01() {
DatasetGraph dsg0 = DatasetGraphFactory.create();
UpdateRequest req = UpdateFactory.create("INSERT DATA { <x> <p> 2 . <z> <q> 2 . <z> <q> 3 . }");
UpdateAction.execute(req, dsg0);
assertEquals(3, dsg0.getDefaultGraph().size());
AtomicLong counterIns = new AtomicLong(0);
AtomicLong counterDel = new AtomicLong(0);
DatasetGraph dsg = new DatasetGraphWrapper(dsg0) {
@Override
public void add(Quad quad) {
counterIns.incrementAndGet();
super.add(quad);
}
@Override
public void delete(Quad quad) {
counterDel.incrementAndGet();
super.delete(quad);
}
};
// WHERE clause doubles the effect.
String s = "DELETE { ?x <p> 2 . <z> <q> 2 } INSERT { ?x <p> 1 . <x> <q> 1 } WHERE { ?x <p> ?o {} UNION {} }";
req = UpdateFactory.create(s);
UpdateAction.execute(req, dsg);
// 3 : 1 constant, 2 from template.
assertEquals(3, counterIns.get());
assertEquals(3, counterIns.get());
assertEquals(3, dsg.getDefaultGraph().size());
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractTestUpdateGraph method testModify1.
@Test
public void testModify1() {
DatasetGraph gStore = getEmptyDatasetGraph();
defaultGraphData(gStore, data2());
namedGraphData(gStore, graphIRI, Factory.createDefaultGraph());
UpdateModify modify = new UpdateModify();
Element element = QueryFactory.createElement("{ ?s <http://example/p> ?o }");
modify.setElement(element);
modify.getInsertAcc().addQuad(new Quad(graphIRI, triple1));
modify.getDeleteAcc().addTriple(SSE.parseTriple("(?s <http://example/p> ?o)"));
modify.getDeleteAcc().addQuad(SSE.parseQuad("(<http://example/graph> ?s <http://example/p> ?o)"));
UpdateAction.execute(modify, gStore);
assertFalse(graphEmpty(gStore.getGraph(graphIRI)));
assertTrue(graphEmpty(gStore.getDefaultGraph()));
assertTrue(graphContains(gStore.getGraph(graphIRI), triple1));
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractJenaConnectionTests method connection_prepared_statement_select_03.
/**
* Tests use of prepared statements
*
* @throws SQLException
*/
@Test
public void connection_prepared_statement_select_03() throws SQLException {
// Prepare a dataset
Dataset ds = DatasetFactory.createTxnMem();
ds.asDatasetGraph().add(new Quad(NodeFactory.createURI("http://example/graph"), NodeFactory.createURI("http://example/subject"), NodeFactory.createURI("http://example/predicate"), NodeFactory.createLiteral("value")));
// Work with the connection
JenaConnection conn = this.getConnection(ds);
conn.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { GRAPH ?g { ?s ?p ? } }");
ParameterMetaData metadata = stmt.getParameterMetaData();
Assert.assertEquals(1, metadata.getParameterCount());
stmt.setNString(1, "value");
ResultSet rset = stmt.executeQuery();
Assert.assertNotNull(rset);
Assert.assertFalse(rset.isClosed());
Assert.assertTrue(rset.isBeforeFirst());
// Check result set metadata
checkSelectMetadata(rset, 3);
// Should have a row
Assert.assertTrue(rset.next());
Assert.assertTrue(rset.isFirst());
Assert.assertEquals(1, rset.getRow());
// Should be no further rows
Assert.assertFalse(rset.next());
Assert.assertTrue(rset.isAfterLast());
Assert.assertFalse(rset.isClosed());
// Close things
rset.close();
Assert.assertTrue(rset.isClosed());
stmt.close();
Assert.assertTrue(stmt.isClosed());
conn.close();
Assert.assertTrue(conn.isClosed());
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractJenaConnectionTests method connection_prepared_statement_select_02.
/**
* Tests use of prepared statements
*
* @throws SQLException
*/
@Test
public void connection_prepared_statement_select_02() throws SQLException {
// Prepare a dataset
Dataset ds = DatasetFactory.createTxnMem();
ds.asDatasetGraph().add(new Quad(NodeFactory.createURI("http://example/graph"), NodeFactory.createURI("http://example/subject"), NodeFactory.createURI("http://example/predicate"), NodeFactory.createLiteral("value")));
// Work with the connection
JenaConnection conn = this.getConnection(ds);
conn.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { GRAPH ?g { ?s ?p ? } }");
ParameterMetaData metadata = stmt.getParameterMetaData();
Assert.assertEquals(1, metadata.getParameterCount());
stmt.setString(1, "value");
ResultSet rset = stmt.executeQuery();
Assert.assertNotNull(rset);
Assert.assertFalse(rset.isClosed());
Assert.assertTrue(rset.isBeforeFirst());
// Check result set metadata
checkSelectMetadata(rset, 3);
// Should have a row
Assert.assertTrue(rset.next());
Assert.assertTrue(rset.isFirst());
Assert.assertEquals(1, rset.getRow());
// Should be no further rows
Assert.assertFalse(rset.next());
Assert.assertTrue(rset.isAfterLast());
Assert.assertFalse(rset.isClosed());
// Close things
rset.close();
Assert.assertTrue(rset.isClosed());
stmt.close();
Assert.assertTrue(stmt.isClosed());
conn.close();
Assert.assertTrue(conn.isClosed());
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractJenaConnectionTests method connection_prepared_statement_select_01.
/**
* Tests use of prepared statements
*
* @throws SQLException
* @throws MalformedURLException
*/
@Test
public void connection_prepared_statement_select_01() throws SQLException, MalformedURLException {
// Prepare a dataset
Dataset ds = DatasetFactory.createTxnMem();
ds.asDatasetGraph().add(new Quad(NodeFactory.createURI("http://example/graph"), NodeFactory.createURI("http://example/subject"), NodeFactory.createURI("http://example/predicate"), NodeFactory.createURI("http://example/object")));
// Work with the connection
JenaConnection conn = this.getConnection(ds);
conn.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { GRAPH ? { ?s ?p ?o } }");
ParameterMetaData metadata = stmt.getParameterMetaData();
Assert.assertEquals(1, metadata.getParameterCount());
stmt.setURL(1, new URL("http://example/graph"));
ResultSet rset = stmt.executeQuery();
Assert.assertNotNull(rset);
Assert.assertFalse(rset.isClosed());
Assert.assertTrue(rset.isBeforeFirst());
// Check result set metadata
checkSelectMetadata(rset, 3);
// Should have a row
Assert.assertTrue(rset.next());
Assert.assertTrue(rset.isFirst());
Assert.assertEquals(1, rset.getRow());
// Should be no further rows
Assert.assertFalse(rset.next());
Assert.assertTrue(rset.isAfterLast());
Assert.assertFalse(rset.isClosed());
// Close things
rset.close();
Assert.assertTrue(rset.isClosed());
stmt.close();
Assert.assertTrue(stmt.isClosed());
conn.close();
Assert.assertTrue(conn.isClosed());
}
Aggregations