Search in sources :

Example 11 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class AbstractJenaConnectionTests method connection_statement_query_describe_02.

/**
     * Runs a CONSTRUCT query on a non-empty database and checks it returns
     * non-empty results
     * 
     * @throws SQLException
     */
@Test
public void connection_statement_query_describe_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.createURI("http://example/object")));
    // Work with the connection
    JenaConnection conn = this.getConnection(ds);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("DESCRIBE ?s WHERE { GRAPH ?g { ?s ?p ?o } }");
    Assert.assertNotNull(rset);
    Assert.assertFalse(rset.isClosed());
    Assert.assertTrue(rset.isBeforeFirst());
    // 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());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 12 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class AbstractJenaConnectionTests method connection_statement_query_select_03.

/**
     * Runs a SELECT query on a non-empty database and checks it returns
     * non-empty results
     * 
     * @throws SQLException
     */
@Test
public void connection_statement_query_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.createURI("http://example/object")));
    // Work with the connection
    JenaConnection conn = this.getConnection(ds);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } }");
    Assert.assertNotNull(rset);
    Assert.assertFalse(rset.isClosed());
    Assert.assertTrue(rset.isBeforeFirst());
    // Check result set metadata
    checkSelectMetadata(rset, 1);
    // 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());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 13 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class AbstractJenaConnectionTests method connection_statement_query_construct_02.

/**
     * Runs a CONSTRUCT query on a non-empty database and checks it returns
     * non-empty results
     * 
     * @throws SQLException
     */
@Test
public void connection_statement_query_construct_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.createURI("http://example/object")));
    // Work with the connection
    JenaConnection conn = this.getConnection(ds);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?g { ?s ?p ?o } }");
    Assert.assertNotNull(rset);
    Assert.assertFalse(rset.isClosed());
    Assert.assertTrue(rset.isBeforeFirst());
    // 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());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 14 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class SlotCompilerIndex method classify.

protected void classify(QuadBlock quadBlock, Collection<Node> constants, Collection<Var> vars) {
    for (Quad quad : quadBlock) {
        // Some constants are only markers and are not stored in the database.
        if (// quad.isDefaultGraph ARQ 2.8.4 and later
        !Quad.isDefaultGraph(quad.getGraph()) && !quad.isUnionGraph())
            acc(constants, vars, quad.getGraph());
        acc(constants, vars, quad.getSubject());
        acc(constants, vars, quad.getPredicate());
        acc(constants, vars, quad.getObject());
    }
}
Also used : Quad(org.apache.jena.sparql.core.Quad)

Example 15 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class T_QuadsObjectIsNull method one.

public static void one() {
    Quad q1 = SSE.parseQuad("(<g1> <s1> <p1> '1')");
    Quad q2 = SSE.parseQuad("(<g2> <s2> <p2> '2')");
    Quad q3 = SSE.parseQuad("(<g3> <s3> <p3> '3')");
    DatasetGraphTransaction dsg = (DatasetGraphTransaction) TDBFactory.createDatasetGraph(location);
    System.out.println("Start");
    dump(dsg);
    write(dsg, q1);
    write(dsg, q2);
    //write(dsg, q3) ;
    System.out.println("Finish");
    dump(dsg);
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraphTransaction(org.apache.jena.tdb.transaction.DatasetGraphTransaction)

Aggregations

Quad (org.apache.jena.sparql.core.Quad)161 Test (org.junit.Test)91 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)49 Node (org.apache.jena.graph.Node)36 BaseTest (org.apache.jena.atlas.junit.BaseTest)32 Triple (org.apache.jena.graph.Triple)25 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)14 Update (org.apache.jena.update.Update)14 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)12 ResultSet (java.sql.ResultSet)8 ArrayList (java.util.ArrayList)8 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)7 Var (org.apache.jena.sparql.core.Var)7 LongWritable (org.apache.hadoop.io.LongWritable)6 UpdateDataDelete (org.apache.jena.sparql.modify.request.UpdateDataDelete)6 UpdateDataInsert (org.apache.jena.sparql.modify.request.UpdateDataInsert)6 Element (org.apache.jena.sparql.syntax.Element)6 Graph (org.apache.jena.graph.Graph)5 BasicPattern (org.apache.jena.sparql.core.BasicPattern)4 IOException (java.io.IOException)3