/
SPARQLUpdateOperation.java
146 lines (120 loc) · 3.51 KB
/
SPARQLUpdateOperation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*******************************************************************************
* Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.http.protocol.transaction.operations;
import java.io.Serializable;
import org.eclipse.rdf4j.query.Binding;
import org.eclipse.rdf4j.query.Dataset;
import org.eclipse.rdf4j.query.MalformedQueryException;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.Update;
import org.eclipse.rdf4j.query.UpdateExecutionException;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
/**
* Encapsulation of a SPARQL 1.1 update operation executed as part of a transaction.
*
* @author Jeen Broekstra
*/
public class SPARQLUpdateOperation implements TransactionOperation, Serializable {
/**
*
*/
private static final long serialVersionUID = 4432275498318918582L;
private String updateString;
private String baseURI;
private boolean includeInferred;
private Dataset dataset;
private Binding[] bindings;
public SPARQLUpdateOperation() {
super();
}
public SPARQLUpdateOperation(String updateString, String baseURI, boolean includeInferred, Dataset dataset,
Binding... bindings) {
this.setUpdateString(updateString);
this.setBaseURI(baseURI);
this.setIncludeInferred(includeInferred);
this.setDataset(dataset);
this.setBindings(bindings);
}
@Override
public void execute(RepositoryConnection con) throws RepositoryException {
try {
Update preparedUpdate = con.prepareUpdate(QueryLanguage.SPARQL, getUpdateString(), getBaseURI());
preparedUpdate.setIncludeInferred(isIncludeInferred());
preparedUpdate.setDataset(getDataset());
if (getBindings() != null) {
for (Binding binding : getBindings()) {
preparedUpdate.setBinding(binding.getName(), binding.getValue());
}
}
preparedUpdate.execute();
} catch (MalformedQueryException | UpdateExecutionException e) {
throw new RepositoryException(e);
}
}
/**
* @return Returns the updateString.
*/
public String getUpdateString() {
return updateString;
}
/**
* @param updateString The updateString to set.
*/
public void setUpdateString(String updateString) {
this.updateString = updateString;
}
/**
* @return Returns the baseURI.
*/
public String getBaseURI() {
return baseURI;
}
/**
* @param baseURI The baseURI to set.
*/
public void setBaseURI(String baseURI) {
this.baseURI = baseURI;
}
/**
* @return Returns the includeInferred.
*/
public boolean isIncludeInferred() {
return includeInferred;
}
/**
* @param includeInferred The includeInferred to set.
*/
public void setIncludeInferred(boolean includeInferred) {
this.includeInferred = includeInferred;
}
/**
* @return Returns the dataset.
*/
public Dataset getDataset() {
return dataset;
}
/**
* @param dataset The dataset to set.
*/
public void setDataset(Dataset dataset) {
this.dataset = dataset;
}
/**
* @return Returns the bindings.
*/
public Binding[] getBindings() {
return bindings;
}
/**
* @param bindings The bindings to set.
*/
public void setBindings(Binding[] bindings) {
this.bindings = bindings;
}
}