Skip to content

Commit

Permalink
add custom connection to SparqlRepository update
Browse files Browse the repository at this point in the history
(cherry picked from commit 41a94ad)
  • Loading branch information
ate47 committed Feb 22, 2024
1 parent dbfdffd commit 3546f28
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,34 @@ private ClosableResult<?> execute0(RepositoryConnection customConnection, String
* @param out the output stream, can be null
*/
public void executeUpdate(String sparqlQuery, int timeout, OutputStream out) {
executeUpdate(sparqlQuery, timeout, out, null);

}
/**
* execute a sparql update query
*
* @param sparqlQuery the query
* @param timeout query timeout
* @param out the output stream, can be null
* @param customConnection custom connection to use
*/
public void executeUpdate(String sparqlQuery, int timeout, OutputStream out, RepositoryConnection customConnection) {
// logger.info("Running update query:"+sparqlQuery);
sparqlQuery = applyPrefixes(sparqlQuery);
sparqlQuery = Pattern.compile("MINUS \\{(?s).*?}\\n {2}}").matcher(sparqlQuery).replaceAll("");
try (SailRepositoryConnection connection = repository.getConnection()) {

RepositoryConnection connectionCloseable;
RepositoryConnection connection;

if (customConnection == null) {
connection = repository.getConnection();
connectionCloseable = connection;
} else {
connectionCloseable = null;
connection = customConnection;
}

try (connectionCloseable) {
connection.setParserConfig(new ParserConfig().set(BasicParserSettings.VERIFY_URI_SYNTAX, false));

Update preparedUpdate = connection.prepareUpdate(QueryLanguage.SPARQL, sparqlQuery);
Expand Down

0 comments on commit 3546f28

Please sign in to comment.