1   package eu.fbk.knowledgestore.triplestore;
2   
3   import java.io.IOException;
4   
5   import javax.annotation.Nullable;
6   
7   import com.google.common.collect.ForwardingObject;
8   
9   import org.openrdf.model.Resource;
10  import org.openrdf.model.Statement;
11  import org.openrdf.model.URI;
12  import org.openrdf.model.Value;
13  import org.openrdf.query.BindingSet;
14  import org.openrdf.query.QueryEvaluationException;
15  
16  import info.aduna.iteration.CloseableIteration;
17  
18  import eu.fbk.knowledgestore.data.Handler;
19  
20  /**
21   * A <tt>TripleTransaction</tt> that forwards all its method calls to another
22   * <tt>TripleTransaction</tt>.
23   * <p>
24   * This class provides a starting point for implementing the decorator pattern on top of the
25   * <tt>TripleTransaction</tt> interface. Subclasses must implement method {@link #delegate()} and
26   * override the methods of <tt>TripleTransaction</tt> they want to decorate.
27   * </p>
28   */
29  public abstract class ForwardingTripleTransaction extends ForwardingObject implements
30          TripleTransaction {
31  
32      @Override
33      protected abstract TripleTransaction delegate();
34  
35      @Override
36      public CloseableIteration<? extends Statement, ? extends Exception> get(
37              @Nullable final Resource subject, @Nullable final URI predicate,
38              @Nullable final Value object, @Nullable final Resource context) throws IOException,
39              IllegalStateException {
40          return delegate().get(subject, predicate, object, context);
41      }
42  
43      @Override
44      public CloseableIteration<BindingSet, QueryEvaluationException> query(final SelectQuery query,
45              @Nullable final BindingSet bindings, @Nullable final Long timeout) throws IOException,
46              UnsupportedOperationException {
47          return delegate().query(query, bindings, timeout);
48      }
49  
50      @Override
51      public void infer(@Nullable final Handler<? super Statement> handler) throws IOException,
52              IllegalStateException {
53          delegate().infer(handler);
54      }
55  
56      @Override
57      public void add(final Iterable<? extends Statement> statements) throws IOException,
58              IllegalStateException {
59          delegate().add(statements);
60      }
61  
62      @Override
63      public void remove(final Iterable<? extends Statement> statements) throws IOException,
64              IllegalStateException {
65          delegate().remove(statements);
66      }
67  
68      @Override
69      public void end(final boolean commit) throws IOException {
70          delegate().end(commit);
71      }
72  
73  }