This example inserts two triples into the default graph using SPARQL update.
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.rdf.model.Model;
import oracle.rdf.kv.client.jena.*;
import com.hp.hpl.jena.update.*;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
public class Example14
{
public static void main(String[] args) throws Exception
{
String szStoreName = args[0];
String szHostName = args[1];
String szHostPort = args[2];
String szGraphName = args[3];
// Create Oracle NoSQL connection
OracleNoSqlConnection conn =
OracleNoSqlConnection.createInstance(szStoreName,
szHostName,
szHostPort);
// Create model for default graph
Model model =
OracleModelNoSql.createOracleModelNoSql(szGraphName, conn);
// Clear model
model.removeAll();
String insertString =
"PREFIX dc: <http://purl.org/dc/elements/1.1/> " +
"INSERT DATA " +
"{ <http://example/book3> dc:title \"A new book\" ; " +
" dc:creator \"A.N.Other\" . " +
" } ";
System.out.println("Execute insert action " + insertString);
UpdateAction.parseExecute(insertString, model);
OracleGraphNoSql graph = (OracleGraphNoSql) model.getGraph();
// Find all triples in the default graph
ExtendedIterator<Triple> ei = GraphUtil.findAll(graph);
while (ei.hasNext()) {
System.out.println("Triple " + ei.next().toString());
}
ei.close();
model.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 Example14.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 Example14 <store_name> \ <host_name> <host_port> <graph_name> Triple http://example/book3 @dc:creator "A.N.Other" Triple http://example/book3 @dc:title "A new book"