View Javadoc

1   /*
2    * Copyright James Leigh (c) 2007.
3    *
4    * Licensed under the Aduna BSD-style license.
5    */
6   package org.openrdf.repository.contextaware;
7   
8   import info.aduna.iteration.CloseableIteration;
9   import info.aduna.iteration.Iteration;
10  
11  import java.io.File;
12  import java.io.IOException;
13  import java.io.InputStream;
14  import java.io.Reader;
15  import java.net.URL;
16  
17  import org.openrdf.model.Resource;
18  import org.openrdf.model.Statement;
19  import org.openrdf.model.URI;
20  import org.openrdf.model.Value;
21  import org.openrdf.query.BooleanQuery;
22  import org.openrdf.query.GraphQuery;
23  import org.openrdf.query.MalformedQueryException;
24  import org.openrdf.query.Query;
25  import org.openrdf.query.QueryLanguage;
26  import org.openrdf.query.TupleQuery;
27  import org.openrdf.repository.Repository;
28  import org.openrdf.repository.RepositoryConnection;
29  import org.openrdf.repository.RepositoryException;
30  import org.openrdf.repository.RepositoryResult;
31  import org.openrdf.repository.base.RepositoryConnectionWrapper;
32  import org.openrdf.repository.util.RDFInserter;
33  import org.openrdf.rio.RDFFormat;
34  import org.openrdf.rio.RDFHandler;
35  import org.openrdf.rio.RDFHandlerException;
36  import org.openrdf.rio.RDFParseException;
37  import org.openrdf.rio.UnsupportedRDFormatException;
38  
39  /**
40   * Allows contexts to be specified at the connection level or the method level.
41   * 
42   * @author James Leigh
43   */
44  public class ContextAwareConnection extends RepositoryConnectionWrapper {
45  
46  	private static final Resource[] ALL_CONTEXTS = new Resource[0];
47  
48  	private boolean _includeInferred = true;
49  
50  	private QueryLanguage _ql = QueryLanguage.SPARQL;
51  
52  	private Resource[] _readContexts = ALL_CONTEXTS;
53  
54  	private Resource[] _addContexts = ALL_CONTEXTS;
55  
56  	private Resource[] _removeContexts = ALL_CONTEXTS;
57  
58  	private Resource[] _archiveContexts = ALL_CONTEXTS;
59  
60  	private ContextQueryRewriter _rewriter = new ContextQueryRewriter();
61  
62  	public ContextAwareConnection(Repository repository)
63  		throws RepositoryException
64  	{
65  		this(repository, repository.getConnection());
66  	}
67  
68  	public ContextAwareConnection(Repository repository, RepositoryConnection connection) {
69  		super(repository, connection);
70  	}
71  
72  	@Override
73  	protected boolean isDelegatingRemove() {
74  		return _archiveContexts.length == 0;
75  	}
76  
77  	/**
78  	 * if false, no inferred statements are considered; if true, inferred
79  	 * statements are considered if available
80  	 */
81  	public boolean isIncludeInferred() {
82  		return _includeInferred;
83  	}
84  
85  
86  	/**
87  	 * if false, no inferred statements are considered; if true, inferred
88  	 * statements are considered if available
89  	 */
90  	public void setIncludeInferred(boolean includeInferred) {
91  		this._includeInferred = includeInferred;
92  	}
93  
94  	public QueryLanguage getQueryLanguage() {
95  		return _ql;
96  	}
97  
98  	public void setQueryLanguage(QueryLanguage ql) {
99  		this._ql = ql;
100 	}
101 
102 	/**
103 	 * The context(s) to get the data from. Note that this parameter is a vararg
104 	 * and as such is optional. If no contexts are supplied the method operates
105 	 * on the entire repository.
106 	 */
107 	public Resource[] getReadContexts() {
108 		return _readContexts;
109 	}
110 
111 	/**
112 	 * The context(s) to get the data from. Note that this parameter is a vararg
113 	 * and as such is optional. If no contexts are supplied the method operates
114 	 * on the entire repository.
115 	 */
116 	public void setReadContexts(Resource... readContexts) {
117 		this._readContexts = readContexts;
118 		_rewriter.setContexts(readContexts);
119 	}
120 
121 	/**
122 	 * The contexts to add the statements to. Note that this parameter is a
123 	 * vararg and as such is optional. If no contexts are specified, each
124 	 * statement is added to any context specified in the statement, or if the
125 	 * statement contains no context, it is added without context. If one or
126 	 * more contexts are specified each statement is added to these contexts,
127 	 * ignoring any context information in the statement itself. ignored.
128 	 */
129 	public Resource[] getAddContexts() {
130 		return _addContexts;
131 	}
132 
133 	/**
134 	 * The contexts to add the statements to. Note that this parameter is a
135 	 * vararg and as such is optional. If no contexts are specified, each
136 	 * statement is added to any context specified in the statement, or if the
137 	 * statement contains no context, it is added without context. If one or
138 	 * more contexts are specified each statement is added to these contexts,
139 	 * ignoring any context information in the statement itself. ignored.
140 	 */
141 	public void setAddContexts(Resource... addContexts) {
142 		this._addContexts = addContexts;
143 	}
144 
145 	/**
146 	 * The context(s) to remove the data from. Note that this parameter is a
147 	 * vararg and as such is optional. If no contexts are supplied the method
148 	 * operates on the contexts associated with the statement itself, and if no
149 	 * context is associated with the statement, on the entire repository.
150 	 */
151 	public Resource[] getRemoveContexts() {
152 		return _removeContexts;
153 	}
154 
155 	/**
156 	 * The context(s) to remove the data from. Note that this parameter is a
157 	 * vararg and as such is optional. If no contexts are supplied the method
158 	 * operates on the contexts associated with the statement itself, and if no
159 	 * context is associated with the statement, on the entire repository.
160 	 */
161 	public void setRemoveContexts(Resource... removeContexts) {
162 		this._removeContexts = removeContexts;
163 	}
164 
165 	/**
166 	 * Before Statements are removed, they are first copied to these contexts.
167 	 */
168 	public Resource[] getArchiveContexts() {
169 		return _archiveContexts;
170 	}
171 
172 	/**
173 	 * Before Statements are removed, they are first copied to these contexts.
174 	 */
175 
176 	public void setArchiveContexts(Resource... archiveContexts) {
177 		_archiveContexts = archiveContexts;
178 	}
179 
180 
181 	/**
182 	 * Adds RDF data from the specified file to a specific contexts in the
183 	 * repository.
184 	 * 
185 	 * @param file
186 	 *        A file containing RDF data.
187 	 * @param baseURI
188 	 *        The base URI to resolve any relative URIs that are in the data
189 	 *        against. This defaults to the value of
190 	 *        {@link java.io.File#toURI() file.toURI()} if the value is set to
191 	 *        <tt>null</tt>.
192 	 * @param dataFormat
193 	 *        The serialization format of the data.
194 	 * @throws IOException
195 	 *         If an I/O error occurred while reading from the file.
196 	 * @throws UnsupportedRDFormatException
197 	 *         If no parser is available for the specified RDF format.
198 	 * @throws RDFParseException
199 	 *         If an error was found while parsing the RDF data.
200 	 * @throws RepositoryException
201 	 *         If the data could not be added to the repository, for example
202 	 *         because the repository is not writable.
203 	 * @see #getAddContexts()
204 	 */
205 	public void add(File file, String baseURI, RDFFormat dataFormat)
206 		throws IOException, RDFParseException, RepositoryException
207 	{
208 		super.add(file, baseURI, dataFormat, _addContexts);
209 	}
210 
211 	/**
212 	 * Adds RDF data from an InputStream to the repository, optionally to one or
213 	 * more named contexts.
214 	 * 
215 	 * @param in
216 	 *        An InputStream from which RDF data can be read.
217 	 * @param baseURI
218 	 *        The base URI to resolve any relative URIs that are in the data
219 	 *        against.
220 	 * @param dataFormat
221 	 *        The serialization format of the data.
222 	 * @throws IOException
223 	 *         If an I/O error occurred while reading from the input stream.
224 	 * @throws UnsupportedRDFormatException
225 	 *         If no parser is available for the specified RDF format.
226 	 * @throws RDFParseException
227 	 *         If an error was found while parsing the RDF data.
228 	 * @throws RepositoryException
229 	 *         If the data could not be added to the repository, for example
230 	 *         because the repository is not writable.
231 	 * @see #getAddContexts()
232 	 */
233 	public void add(InputStream in, String baseURI, RDFFormat dataFormat)
234 		throws IOException, RDFParseException, RepositoryException
235 	{
236 		super.add(in, baseURI, dataFormat, _addContexts);
237 	}
238 
239 	/**
240 	 * Adds the supplied statements to this repository, optionally to one or more
241 	 * named contexts.
242 	 * 
243 	 * @param statements
244 	 *        The statements that should be added.
245 	 * @throws RepositoryException
246 	 *         If the statements could not be added to the repository, for
247 	 *         example because the repository is not writable.
248 	 * @see #getAddContexts()
249 	 */
250 	public void add(Iterable<? extends Statement> statements)
251 		throws RepositoryException
252 	{
253 		super.add(statements, _addContexts);
254 	}
255 
256 	/**
257 	 * Adds the supplied statements to this repository, optionally to one or more
258 	 * named contexts.
259 	 * 
260 	 * @param statementIter
261 	 *        The statements to add. In case the iterator is a
262 	 *        {@link CloseableIteration}, it will be closed before this method
263 	 *        returns.
264 	 * @throws RepositoryException
265 	 *         If the statements could not be added to the repository, for
266 	 *         example because the repository is not writable.
267 	 * @see #getAddContexts()
268 	 */
269 	public void add(Iteration<? extends Statement, RepositoryException> statementIter)
270 		throws RepositoryException
271 	{
272 		super.add(statementIter, _addContexts);
273 	}
274 
275 	/**
276 	 * Adds RDF data from a Reader to the repository, optionally to one or more
277 	 * named contexts. <b>Note: using a Reader to upload byte-based data means
278 	 * that you have to be careful not to destroy the data's character encoding
279 	 * by enforcing a default character encoding upon the bytes. If possible,
280 	 * adding such data using an InputStream is to be preferred.</b>
281 	 * 
282 	 * @param reader
283 	 *        A Reader from which RDF data can be read.
284 	 * @param baseURI
285 	 *        The base URI to resolve any relative URIs that are in the data
286 	 *        against.
287 	 * @param dataFormat
288 	 *        The serialization format of the data.
289 	 * @throws IOException
290 	 *         If an I/O error occurred while reading from the reader.
291 	 * @throws UnsupportedRDFormatException
292 	 *         If no parser is available for the specified RDF format.
293 	 * @throws RDFParseException
294 	 *         If an error was found while parsing the RDF data.
295 	 * @throws RepositoryException
296 	 *         If the data could not be added to the repository, for example
297 	 *         because the repository is not writable.
298 	 * @see #getAddContexts()
299 	 */
300 	public void add(Reader reader, String baseURI, RDFFormat dataFormat)
301 		throws IOException, RDFParseException, RepositoryException
302 	{
303 		super.add(reader, baseURI, dataFormat, _addContexts);
304 	}
305 
306 	/**
307 	 * Adds a statement with the specified subject, predicate and object to this
308 	 * repository, optionally to one or more named contexts.
309 	 * 
310 	 * @param subject
311 	 *        The statement's subject.
312 	 * @param predicate
313 	 *        The statement's predicate.
314 	 * @param object
315 	 *        The statement's object.
316 	 * @throws RepositoryException
317 	 *         If the data could not be added to the repository, for example
318 	 *         because the repository is not writable.
319 	 * @see #getAddContexts()
320 	 */
321 	public void add(Resource subject, URI predicate, Value object)
322 		throws RepositoryException
323 	{
324 		super.add(subject, predicate, object, _addContexts);
325 	}
326 
327 	/**
328 	 * Adds the supplied statement to this repository, optionally to one or more
329 	 * named contexts.
330 	 * 
331 	 * @param st
332 	 *        The statement to add.
333 	 * @throws RepositoryException
334 	 *         If the statement could not be added to the repository, for example
335 	 *         because the repository is not writable.
336 	 * @see #getAddContexts()
337 	 */
338 	public void add(Statement st)
339 		throws RepositoryException
340 	{
341 		super.add(st, _addContexts);
342 	}
343 
344 	/**
345 	 * Adds the RDF data that can be found at the specified URL to the
346 	 * repository, optionally to one or more named contexts.
347 	 * 
348 	 * @param url
349 	 *        The URL of the RDF data.
350 	 * @param baseURI
351 	 *        The base URI to resolve any relative URIs that are in the data
352 	 *        against. This defaults to the value of {@link
353 	 *        java.net.URL#toExternalForm() url.toExternalForm()} if the value is
354 	 *        set to <tt>null</tt>.
355 	 * @param dataFormat
356 	 *        The serialization format of the data.
357 	 * @throws IOException
358 	 *         If an I/O error occurred while reading from the URL.
359 	 * @throws UnsupportedRDFormatException
360 	 *         If no parser is available for the specified RDF format.
361 	 * @throws RDFParseException
362 	 *         If an error was found while parsing the RDF data.
363 	 * @throws RepositoryException
364 	 *         If the data could not be added to the repository, for example
365 	 *         because the repository is not writable.
366 	 * @see #getAddContexts()
367 	 */
368 	public void add(URL url, String baseURI, RDFFormat dataFormat)
369 		throws IOException, RDFParseException, RepositoryException
370 	{
371 		super.add(url, baseURI, dataFormat, _addContexts);
372 	}
373 
374 	/**
375 	 * Removes all statements from a specific contexts in the repository.
376 	 * 
377 	 * @throws RepositoryException
378 	 *         If the statements could not be removed from the repository, for
379 	 *         example because the repository is not writable.
380 	 * @see #getRemoveContexts()
381 	 */
382 	public void clear()
383 		throws RepositoryException
384 	{
385 		super.clear(_removeContexts);
386 	}
387 
388 	/**
389 	 * Exports all explicit statements in the specified contexts to the supplied
390 	 * RDFHandler.
391 	 * 
392 	 * @param handler
393 	 *        The handler that will handle the RDF data.
394 	 * @throws RDFHandlerException
395 	 *         If the handler encounters an unrecoverable error.
396 	 * @see #getReadContexts()
397 	 */
398 	public void export(RDFHandler handler)
399 		throws RepositoryException, RDFHandlerException
400 	{
401 		super.export(handler, _readContexts);
402 	}
403 
404 	/**
405 	 * Exports all statements with a specific subject, predicate and/or object
406 	 * from the repository, optionally from the specified contexts.
407 	 * 
408 	 * @param subj
409 	 *        The subject, or null if the subject doesn't matter.
410 	 * @param pred
411 	 *        The predicate, or null if the predicate doesn't matter.
412 	 * @param obj
413 	 *        The object, or null if the object doesn't matter.
414 	 * @param handler
415 	 *        The handler that will handle the RDF data.
416 	 * @throws RDFHandlerException
417 	 *         If the handler encounters an unrecoverable error.
418 	 * @see #getReadContexts()
419 	 * @see #isIncludeInferred()
420 	 */
421 	public void exportStatements(Resource subj, URI pred, Value obj, RDFHandler hander)
422 		throws RepositoryException, RDFHandlerException
423 	{
424 		super.exportStatements(subj, pred, obj, _includeInferred, hander, _readContexts);
425 	}
426 
427 	/**
428 	 * Gets all statements with a specific subject, predicate and/or object from
429 	 * the repository. The result is optionally restricted to the specified set
430 	 * of named contexts.
431 	 * 
432 	 * @param subj
433 	 *        A Resource specifying the subject, or <tt>null</tt> for a
434 	 *        wildcard.
435 	 * @param pred
436 	 *        A URI specifying the predicate, or <tt>null</tt> for a wildcard.
437 	 * @param obj
438 	 *        A Value specifying the object, or <tt>null</tt> for a wildcard.
439 	 * @return The statements matching the specified pattern. The result object
440 	 *         is a {@link RepositoryResult} object, a lazy Iterator-like object
441 	 *         containing {@link Statement}s and optionally throwing a
442 	 *         {@link RepositoryException} when an error when a problem occurs
443 	 *         during retrieval.
444 	 * @see #getReadContexts()
445 	 * @see #isIncludeInferred()
446 	 */
447 	public RepositoryResult<Statement> getStatements(Resource subj, URI pred, Value obj)
448 		throws RepositoryException
449 	{
450 		RepositoryResult<Statement> stmts;
451 		stmts = super.getStatements(subj, pred, obj, _includeInferred, _readContexts);
452 		stmts.enableDuplicateFilter();
453 		return stmts;
454 	}
455 
456 	/**
457 	 * Checks whether the repository contains statements with a specific subject,
458 	 * predicate and/or object, optionally in the specified contexts.
459 	 * 
460 	 * @param subj
461 	 *        A Resource specifying the subject, or <tt>null</tt> for a
462 	 *        wildcard.
463 	 * @param pred
464 	 *        A URI specifying the predicate, or <tt>null</tt> for a wildcard.
465 	 * @param obj
466 	 *        A Value specifying the object, or <tt>null</tt> for a wildcard.
467 	 * @return true If a matching statement is in the repository in the specified
468 	 *         context, false otherwise.
469 	 * @see #getReadContexts()
470 	 * @see #isIncludeInferred()
471 	 */
472 	public boolean hasStatement(Resource subj, URI pred, Value obj)
473 		throws RepositoryException
474 	{
475 		return super.hasStatement(subj, pred, obj, _includeInferred, _readContexts);
476 	}
477 
478 	/**
479 	 * Checks whether the repository contains the specified statement, optionally
480 	 * in the specified contexts.
481 	 * 
482 	 * @param st
483 	 *        The statement to look for. Context information in the statement is
484 	 *        ignored.
485 	 * @return true If the repository contains the specified statement, false
486 	 *         otherwise.
487 	 * @see #getReadContexts()
488 	 * @see #isIncludeInferred()
489 	 */
490 	public boolean hasStatement(Statement st)
491 		throws RepositoryException
492 	{
493 		return super.hasStatement(st, _includeInferred, _readContexts);
494 	}
495 
496 	public GraphQuery prepareGraphQueryWithinContext(String query)
497 		throws MalformedQueryException, RepositoryException
498 	{
499 		GraphQuery preparedQuery;
500 		if (_readContexts.length == 0) {
501 			preparedQuery = super.prepareGraphQuery(_ql, query);
502 		} else {
503 			QueryLanguage ql = _rewriter.getQueryLanguage();
504 			String queryString = _rewriter.rewriteQuery(_ql, query, null);
505 			preparedQuery = super.prepareGraphQuery(ql, queryString);
506 		}
507 		preparedQuery.setIncludeInferred(_includeInferred);
508 		return preparedQuery;
509 	}
510 
511 	public Query prepareQueryWithinContext(String query)
512 		throws MalformedQueryException, RepositoryException
513 	{
514 		Query preparedQuery;
515 		if (_readContexts.length == 0) {
516 			preparedQuery = super.prepareQuery(_ql, query);
517 		} else {
518 			QueryLanguage ql = _rewriter.getQueryLanguage();
519 			String queryString = _rewriter.rewriteQuery(_ql, query, null);
520 			preparedQuery = super.prepareQuery(ql, queryString);
521 		}
522 		preparedQuery.setIncludeInferred(_includeInferred);
523 		return preparedQuery;
524 	}
525 
526 	public TupleQuery prepareTupleQueryWithinContext(String query)
527 		throws MalformedQueryException, RepositoryException
528 	{
529 		TupleQuery preparedQuery;
530 		if (_readContexts.length == 0) {
531 			preparedQuery = super.prepareTupleQuery(_ql, query);
532 		} else {
533 			QueryLanguage ql = _rewriter.getQueryLanguage();
534 			String queryString = _rewriter.rewriteQuery(_ql, query, null);
535 			preparedQuery = super.prepareTupleQuery(ql, queryString);
536 		}
537 		preparedQuery.setIncludeInferred(_includeInferred);
538 		return preparedQuery;
539 	}
540 
541 	public GraphQuery prepareGraphQueryWithinContext(QueryLanguage qlang, String query, String baseURI)
542 		throws MalformedQueryException, RepositoryException
543 	{
544 		GraphQuery preparedQuery;
545 		if (_readContexts.length == 0) {
546 			preparedQuery = super.prepareGraphQuery(qlang, query, baseURI);
547 		} else {
548 			QueryLanguage ql = _rewriter.getQueryLanguage();
549 			String queryString = _rewriter.rewriteQuery(qlang, query, baseURI);
550 			preparedQuery = super.prepareGraphQuery(ql, queryString, baseURI);
551 		}
552 		preparedQuery.setIncludeInferred(_includeInferred);
553 		return preparedQuery;
554 	}
555 
556 	public Query prepareQueryWithinContext(QueryLanguage qlang, String query, String baseURI)
557 		throws MalformedQueryException, RepositoryException
558 	{
559 		Query preparedQuery;
560 		if (_readContexts.length == 0) {
561 			preparedQuery = super.prepareQuery(qlang, query, baseURI);
562 		} else {
563 			QueryLanguage ql = _rewriter.getQueryLanguage();
564 			String queryString = _rewriter.rewriteQuery(qlang, query, baseURI);
565 			preparedQuery = super.prepareQuery(ql, queryString, baseURI);
566 		}
567 		preparedQuery.setIncludeInferred(_includeInferred);
568 		return preparedQuery;
569 	}
570 
571 	public TupleQuery prepareTupleQueryWithinContext(QueryLanguage qlang, String query, String baseURI)
572 		throws MalformedQueryException, RepositoryException
573 	{
574 		TupleQuery preparedQuery;
575 		if (_readContexts.length == 0) {
576 			preparedQuery = super.prepareTupleQuery(qlang, query, baseURI);
577 		} else {
578 			QueryLanguage ql = _rewriter.getQueryLanguage();
579 			String queryString = _rewriter.rewriteQuery(qlang, query, baseURI);
580 			preparedQuery = super.prepareTupleQuery(ql, queryString, baseURI);
581 		}
582 		preparedQuery.setIncludeInferred(_includeInferred);
583 		return preparedQuery;
584 	}
585 
586 	public GraphQuery prepareGraphQuery(String query)
587 		throws MalformedQueryException, RepositoryException
588 	{
589 		GraphQuery preparedQuery = super.prepareGraphQuery(_ql, query);
590 		preparedQuery.setIncludeInferred(_includeInferred);
591 		return preparedQuery;
592 	}
593 
594 	public Query prepareQuery(String query)
595 		throws MalformedQueryException, RepositoryException
596 	{
597 		Query preparedQuery = super.prepareQuery(_ql, query);
598 		preparedQuery.setIncludeInferred(_includeInferred);
599 		return preparedQuery;
600 	}
601 
602 	public TupleQuery prepareTupleQuery(String query)
603 		throws MalformedQueryException, RepositoryException
604 	{
605 		TupleQuery preparedQuery = super.prepareTupleQuery(_ql, query);
606 		preparedQuery.setIncludeInferred(_includeInferred);
607 		return preparedQuery;
608 	}
609 
610 	@Override
611 	public GraphQuery prepareGraphQuery(QueryLanguage ql, String query)
612 		throws MalformedQueryException, RepositoryException
613 	{
614 		GraphQuery preparedQuery = super.prepareGraphQuery(ql, query);
615 		preparedQuery.setIncludeInferred(_includeInferred);
616 		return preparedQuery;
617 	}
618 
619 	@Override
620 	public Query prepareQuery(QueryLanguage ql, String query)
621 		throws MalformedQueryException, RepositoryException
622 	{
623 		Query preparedQuery = super.prepareQuery(ql, query);
624 		preparedQuery.setIncludeInferred(_includeInferred);
625 		return preparedQuery;
626 	}
627 
628 	@Override
629 	public TupleQuery prepareTupleQuery(QueryLanguage ql, String query)
630 		throws MalformedQueryException, RepositoryException
631 	{
632 		TupleQuery preparedQuery = super.prepareTupleQuery(ql, query);
633 		preparedQuery.setIncludeInferred(_includeInferred);
634 		return preparedQuery;
635 	}
636 
637 	@Override
638 	public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String query)
639 		throws MalformedQueryException, RepositoryException
640 	{
641 		BooleanQuery preparedQuery = super.prepareBooleanQuery(ql, query);
642 		preparedQuery.setIncludeInferred(_includeInferred);
643 		return preparedQuery;
644 	}
645 
646 	@Override
647 	public GraphQuery prepareGraphQuery(QueryLanguage ql, String query, String baseURI)
648 		throws MalformedQueryException, RepositoryException
649 	{
650 		GraphQuery preparedQuery = super.prepareGraphQuery(ql, query, baseURI);
651 		preparedQuery.setIncludeInferred(_includeInferred);
652 		return preparedQuery;
653 	}
654 
655 	@Override
656 	public Query prepareQuery(QueryLanguage ql, String query, String baseURI)
657 		throws MalformedQueryException, RepositoryException
658 	{
659 		Query preparedQuery = super.prepareQuery(ql, query, baseURI);
660 		preparedQuery.setIncludeInferred(_includeInferred);
661 		return preparedQuery;
662 	}
663 
664 	@Override
665 	public TupleQuery prepareTupleQuery(QueryLanguage ql, String query, String baseURI)
666 		throws MalformedQueryException, RepositoryException
667 	{
668 		TupleQuery preparedQuery = super.prepareTupleQuery(ql, query, baseURI);
669 		preparedQuery.setIncludeInferred(_includeInferred);
670 		return preparedQuery;
671 	}
672 
673 	@Override
674 	public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String query, String baseURI)
675 		throws MalformedQueryException, RepositoryException
676 	{
677 		BooleanQuery preparedQuery = super.prepareBooleanQuery(ql, query, baseURI);
678 		preparedQuery.setIncludeInferred(_includeInferred);
679 		return preparedQuery;
680 	}
681 	
682 	/**
683 	 * Removes the supplied statements from the specified contexts in this
684 	 * repository.
685 	 * 
686 	 * @param statements
687 	 *        The statements that should be added.
688 	 * @throws RepositoryException
689 	 *         If the statements could not be added to the repository, for
690 	 *         example because the repository is not writable.
691 	 * @see #getRemoveContexts()
692 	 */
693 	public void remove(Iterable<? extends Statement> statements)
694 		throws RepositoryException
695 	{
696 		super.remove(statements, _removeContexts);
697 	}
698 
699 	/**
700 	 * Removes the supplied statements from a specific context in this
701 	 * repository, ignoring any context information carried by the statements
702 	 * themselves.
703 	 * 
704 	 * @param statementIter
705 	 *        The statements to remove. In case the iterator is a
706 	 *        {@link CloseableIteration}, it will be closed before this method
707 	 *        returns.
708 	 * @throws RepositoryException
709 	 *         If the statements could not be removed from the repository, for
710 	 *         example because the repository is not writable.
711 	 * @see #getRemoveContexts()
712 	 */
713 	public void remove(Iteration<? extends Statement, RepositoryException> statementIter)
714 		throws RepositoryException
715 	{
716 		super.remove(statementIter, _removeContexts);
717 	}
718 
719 	/**
720 	 * Removes the statement with the specified subject, predicate and object
721 	 * from the repository, optionally restricted to the specified contexts.
722 	 * 
723 	 * @param subject
724 	 *        The statement's subject.
725 	 * @param predicate
726 	 *        The statement's predicate.
727 	 * @param object
728 	 *        The statement's object.
729 	 * @throws RepositoryException
730 	 *         If the statement could not be removed from the repository, for
731 	 *         example because the repository is not writable.
732 	 * @see #getRemoveContexts()
733 	 */
734 	public void remove(Resource subject, URI predicate, Value object)
735 		throws RepositoryException
736 	{
737 		super.remove(subject, predicate, object, _removeContexts);
738 	}
739 
740 	/**
741 	 * Removes the supplied statement from the specified contexts in the
742 	 * repository.
743 	 * 
744 	 * @param st
745 	 *        The statement to remove.
746 	 * @throws RepositoryException
747 	 *         If the statement could not be removed from the repository, for
748 	 *         example because the repository is not writable.
749 	 * @see #getRemoveContexts()
750 	 */
751 	public void remove(Statement st)
752 		throws RepositoryException
753 	{
754 		super.remove(st, _removeContexts);
755 	}
756 
757 	/**
758 	 * Returns the number of (explicit) statements that are in the specified
759 	 * contexts in this repository.
760 	 * 
761 	 * @return The number of explicit statements from the specified contexts in
762 	 *         this repository.
763 	 * @see #getReadContexts()
764 	 */
765 	public long size()
766 		throws RepositoryException
767 	{
768 		return super.size(_readContexts);
769 	}
770 
771 	@Override
772 	protected void removeWithoutCommit(Resource subject, URI predicate, Value object, Resource... contexts) throws RepositoryException {
773 		RDFHandler handler = new RDFInserter(getDelegate());
774 		try {
775 			getDelegate().exportStatements(subject, predicate, object, true,
776 					handler, _archiveContexts);
777 		} catch (RDFHandlerException e) {
778 			if (e.getCause() instanceof RepositoryException)
779 				throw (RepositoryException) e.getCause();
780 			throw new AssertionError(e);
781 		}
782 		getDelegate().remove(subject, predicate, object, contexts);
783 	}
784 
785 }