Need to split the multiple inserts and perform separate transactions in GraphDB Free edition. See https://stackoverflow.com/questions/54428161/graphdb-read-check-and-update-in-a-transaction

This commit is contained in:
Alessia Bardi 2020-08-07 14:54:15 +02:00
parent 587887abd6
commit ca4ad7ea3b
1 changed files with 24 additions and 13 deletions

View File

@ -8,6 +8,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import com.google.common.base.Splitter;
import eu.dnetlib.ariadneplus.elasticsearch.BulkUpload;
import eu.dnetlib.ariadneplus.reader.ResourceManager;
import eu.dnetlib.ariadneplus.reader.RunSPARQLQueryService;
@ -263,24 +264,34 @@ public class GraphDBClient {
manager.init();
manager.setUsernameAndPassword(getWriterUser(), getWriterPwd());
Repository repository = manager.getRepository(getRepository());
//NOTE: One query with multiple updates separated by ; is ok with GraphDB EE.
// Using the free edition, we have to divide them in separate INSERT,
// otherwise we cannot see the triples inserted by the previous updates.
//see https://stackoverflow.com/questions/54428161/graphdb-read-check-and-update-in-a-transaction
try (RepositoryConnection con = repository.getConnection()) {
con.begin();
Update updateResultQuery = con.prepareUpdate(queryValue);
if (updateResultQuery!=null) {
updateResultQuery.execute();
result = "updated";
int countQueries = 0;
int countSuccess = 0;
for(String query : Splitter.on(";").split(queryValue)){
countQueries++;
con.begin();
Update updateResultQuery = con.prepareUpdate(queryValue);
if (updateResultQuery != null) {
updateResultQuery.execute();
}
else {
throw new AriadnePlusPublisherException(String.format("Cannot generate Update statement from %s", query));
}
log.debug(String.format("Query %d executed: %s", countQueries, query));
con.commit();
countSuccess++;
log.debug(String.format("Query %d committed", countQueries));
}
else {
result = "No result.";
}
log.debug("query result: "+result);
con.commit();
log.debug("query executed");
log.info(String.format("Queries committed with success %d/%d", countSuccess, countQueries));
}
catch (RDF4JException e) {
log.error("error executing query ...", e);
throw new AriadnePlusPublisherException(e);
}
repository.shutDown();
manager.shutDown();