I read different tutorials explaining how to load a Model to a Virtuoso SPARQL endpoint using Java Apache Jena (eg https://jena.apache.org/documentation/rdfconnection/ ), but I am not able to make it.
I tried this function:
public void uploader(){
String myVirtuosoEndpoint = "http://10.1.22.17:8890/"; //my Virtuoso endpoint IP
Model model = ModelFactory.createDefaultModel() ; //the Model I want to upload
model.createResource("https://example.org").addProperty(RDF.type, "http://myType");
try (RDFConnection conn = RDFConnectionFactory.connect(myVirtuosoEndpoint)) {
conn.begin(ReadWrite.WRITE);
conn.load("http://myGraph", model);
conn.commit();
conn.end();
}
}
I also tried this other function, leveraging Jena's Txn library ( https://jena.apache.org/documentation/txn/txn.html ).
try (RDFConnection conn = RDFConnectionFactory.connect(myVirtuosoEndpoint)) {
Txn.executeWrite(conn, ()-> {
conn.load(targetGraph, model);
}) ;
}
I am using a OpenLink Virtuoso Server version 07.20.3217. As for the Jena dependencies I am using the following:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jena/jena-rdfconnection -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-rdfconnection</artifactId>
<version>3.10.0</version>
</dependency>
It seems that code works as I don't get any error, but the graph where I want to upload the model does not change. I am verifying it by simply executing a SPARQL query against the Graph after executing the code.
Anyone with the same problem?
Thanks
I am trying another new approach to update the content of an RDF graph in Virtuoso.
Code:
//Connect to Virtuoso
VirtModel virtualModel = VirtModel.openDatabaseModel(GRAPH_NAME, endpoint, USERNAME, PASSWORD);
long modelInitialSize = virtualModel.size();
//Add model
virtualModel.add(model);
long modelNewSize = virtualModel.size();
virtualModel.close();
Where the endpoint is similar to jdbc:virtuoso://10.1.22.xxx:1111
I am using these dependencies in the pom.xml
:
<!-- https://mvnrepository.com/artifact/org.apache.jena/jena-tdb -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId>
<version>3.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jena/apache-jena-libs -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<version>3.9.0</version>
<type>pom</type>
</dependency>
Furthermore, I am using the virt_jena3.jar and virtjdbc4.jar dependencies from Virtuoso webapge
Now I am getting the following error when trying to get the VirtModel's size with the command long modelNewSize = virtualModel.size();
:
org.apache.jena.shared.JenaException: virtuoso.jdbc4.VirtuosoException: Problem during serialization : Software caused connection abort: socket write error
.
Besides, once this error appears, it seems like the Virtuoso server goes down, and I need to restart the Virtual Machine to fix it.
The tricky part is is that with dependencies available here , the same code works perfectly...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.