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:
parent
587887abd6
commit
ca4ad7ea3b
|
@ -8,6 +8,7 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
import eu.dnetlib.ariadneplus.elasticsearch.BulkUpload;
|
import eu.dnetlib.ariadneplus.elasticsearch.BulkUpload;
|
||||||
import eu.dnetlib.ariadneplus.reader.ResourceManager;
|
import eu.dnetlib.ariadneplus.reader.ResourceManager;
|
||||||
import eu.dnetlib.ariadneplus.reader.RunSPARQLQueryService;
|
import eu.dnetlib.ariadneplus.reader.RunSPARQLQueryService;
|
||||||
|
@ -263,24 +264,34 @@ public class GraphDBClient {
|
||||||
manager.init();
|
manager.init();
|
||||||
manager.setUsernameAndPassword(getWriterUser(), getWriterPwd());
|
manager.setUsernameAndPassword(getWriterUser(), getWriterPwd());
|
||||||
Repository repository = manager.getRepository(getRepository());
|
Repository repository = manager.getRepository(getRepository());
|
||||||
try (RepositoryConnection con = repository.getConnection()) {
|
//NOTE: One query with multiple updates separated by ; is ok with GraphDB EE.
|
||||||
con.begin();
|
// 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()) {
|
||||||
|
int countQueries = 0;
|
||||||
|
int countSuccess = 0;
|
||||||
|
for(String query : Splitter.on(";").split(queryValue)){
|
||||||
|
countQueries++;
|
||||||
|
con.begin();
|
||||||
Update updateResultQuery = con.prepareUpdate(queryValue);
|
Update updateResultQuery = con.prepareUpdate(queryValue);
|
||||||
if (updateResultQuery != null) {
|
if (updateResultQuery != null) {
|
||||||
updateResultQuery.execute();
|
updateResultQuery.execute();
|
||||||
result = "updated";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = "No result.";
|
throw new AriadnePlusPublisherException(String.format("Cannot generate Update statement from %s", query));
|
||||||
}
|
}
|
||||||
|
log.debug(String.format("Query %d executed: %s", countQueries, query));
|
||||||
log.debug("query result: "+result);
|
|
||||||
con.commit();
|
con.commit();
|
||||||
log.debug("query executed");
|
countSuccess++;
|
||||||
|
log.debug(String.format("Query %d committed", countQueries));
|
||||||
|
}
|
||||||
|
log.info(String.format("Queries committed with success %d/%d", countSuccess, countQueries));
|
||||||
}
|
}
|
||||||
catch (RDF4JException e) {
|
catch (RDF4JException e) {
|
||||||
log.error("error executing query ...", e);
|
log.error("error executing query ...", e);
|
||||||
|
throw new AriadnePlusPublisherException(e);
|
||||||
}
|
}
|
||||||
repository.shutDown();
|
repository.shutDown();
|
||||||
manager.shutDown();
|
manager.shutDown();
|
||||||
|
|
Loading…
Reference in New Issue