Library Version 12.1.3.0

Concurrent RDF data loading
Prev | Chapter 8. Quick Start for the RDF Graph Feature | Next

## Concurrent RDF data loading

This example loads an RDF file into Oracle NoSQL Database using parallel loading (multiple threads). To use parallel loading, you can specify the degree of parallelism (number of threads used to load data as well as the batch size of the bucket of triples managed by each thread. The example also queries for all the quads stored in the Oracle NoSQL Database.

    import com.hp.hpl.jena.query.*;
    import com.hp.hpl.jena.sparql.core.DatasetImpl;
    import org.openjena.riot.Lang;
    import oracle.rdf.kv.client.jena.*;

    public class Example2b
    {

      public static void main(String[] args) throws Exception
      {

    String szStoreName  = args[0];
    String szHostName   = args[1];
    String szHostPort   = args[2];
    int iBatchSize      = Integer.parseInt(args[3]);
    int iDOP            = Integer.parseInt(args[4]);

    System.out.println("Create Oracle NoSQL connection");
    OracleNoSqlConnection conn
    = OracleNoSqlConnection.createInstance(szStoreName,
                                           szHostName,
                                           szHostPort);

    System.out.println("Create Oracle NoSQL datasetgraph");
    OracleGraphNoSql graph = new OracleGraphNoSql(conn);
    DatasetGraphNoSql datasetGraph = DatasetGraphNoSql.createFrom(graph);

    // Close graph, as it is no longer needed
    graph.close();

    // Clear datasetgraph
    datasetGraph.clearRepository();

    // Load data from file into the Oracle NoSQL Database
    DatasetGraphNoSql.load("example.nt", Lang.NQUADS, conn,
                            "http://example.org",
                            iBatchSize, // batch size
                            iDOP); // degree of parallelism

    // Create dataset from Oracle NoSQL datasetgraph to execute
    Dataset ds = DatasetImpl.wrap(datasetGraph);

    String szQuery = "select * where { graph ?g { ?s ?p ?o }  }";
    System.out.println("Execute query " + szQuery);

    Query query = QueryFactory.create(szQuery);
    QueryExecution qexec = QueryExecutionFactory.create(query, ds);

    try {
          ResultSet results = qexec.execSelect();
          ResultSetFormatter.out(System.out, results, query);
        }

    finally {
          qexec.close();
        }

    ds.close();
    conn.dispose();
     }
    }

The following are the commands to compile and run this example, as well as the expected output of the java command.

    javac -classpath ./:./jena-core-2.7.4.jar:./jena-arq-2.9.4.jar: \
    ./sdordfnosqlclient.jar:./kvclient.jar:./xercesImpl-2.10.0.jar: \
    ./slf4j-api-1.6.4.jar: ./slf4j-log4j12-1.6.4.jar:./log4j/1.2.16.jar: \
    ./jena-iri-0.9.4.jar:./xml-apis-1.4.01.jar Example2b.java

    javac -classpath ./:./jena-core-2.7.4.jar:./jena-arq-2.9.4.jar: \
    ./sdordfnosqlclient.jar:./kvclient.jar:./xercesImpl-2.10.0.jar: \
    ./slf4j-api-1.6.4.jar:./slf4j-log4j12-1.6.4.jar:./log4j/1.2.16.jar: \
    ./jena-iri-0.9.4.jar:./xml-apis-1.4.01.jar Example2b <store_name> \
    <host_name> <host_port> <batch_size> <dop>

    Execute query select * where { graph ?g { ?s ?p ?o } }

    ------------------------------------------
    | s                                      |
    ==========================================
    | _:b0                                   |
    | <http://example.org/alice/foaf.rdf#me> |
    | _:b0                                   |
    | <http://example.org/alice/foaf.rdf#me> |
    | _:b0                                   |
    | _:b0                                   |
    | <http://example.org/alice/foaf.rdf#me> |
    | <http://example.org/bob/foaf.rdf#me>   |
    | <http://example.org/bob/foaf.rdf#me>   |
    | <http://example.org/bob/foaf.rdf#me>   |
    ------------------------------------------
    -----------------------------------------------------
    | p                                                 |
    =====================================================
    | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> |
    | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> |
    | <http://xmlns.com/foaf/0.1/homepage>              |
    | <http://xmlns.com/foaf/0.1/knows>                 |
    | <http://www.w3.org/2000/01/rdf-schema#seeAlso>    |
    | <http://xmlns.com/foaf/0.1/name>                  |
    | <http://xmlns.com/foaf/0.1/name>                  |
    | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> |
    | <http://xmlns.com/foaf/0.1/homepage>              |
    | <http://xmlns.com/foaf/0.1/name>                  |
    -----------------------------------------------------
    ------------------------------------------
    | o                                      |
    ==========================================
    | <http://xmlns.com/foaf/0.1/Person>     |
    | <http://xmlns.com/foaf/0.1/Person>     |
    | <http://example.org/bob/>              |
    | _:b0                                   |
    | <http://example.org/bob/foaf.rdf>      |
    | "Bob"                                  |
    | "Alice"                                |
    | <http://xmlns.com/foaf/0.1/Person>     |
    | <http://example.org/bob/>              |
    | "Bob"                                  |
    ------------------------------------------
    ------------------------------------------
    | g                                      |
    ==========================================
    | <http://example.org/alice/foaf.rdf>    |
    | <http://example.org/alice/foaf.rdf>    |
    | <http://example.org/alice/foaf.rdf>    |
    | <http://example.org/alice/foaf.rdf>    |
    | <http://example.org/alice/foaf.rdf>    |
    | <http://example.org/alice/foaf.rdf>    |
    | <http://example.org/alice/foaf.rdf>    |
    | <http://example.org/bob/foaf.rdf>      |
    | <http://example.org/bob/foaf.rdf>      |
    | <http://example.org/bob/foaf.rdf>      |
    ------------------------------------------

Prev | Up | Next
Example2.java: Load an RDF file | Home | Example4.java: Query family relationships on a named graph