1   package eu.fbk.knowledgestore.datastore;
2   
3   import java.io.IOException;
4   import java.util.Map;
5   import java.util.Set;
6   
7   import javax.annotation.Nullable;
8   
9   import com.google.common.collect.ForwardingObject;
10  
11  import org.openrdf.model.URI;
12  
13  import eu.fbk.knowledgestore.data.Record;
14  import eu.fbk.knowledgestore.data.Stream;
15  import eu.fbk.knowledgestore.data.XPath;
16  
17  /**
18   * A {@code DataTransaction} forwarding all its method calls to another {@code DataTransaction}.
19   * <p>
20   * This class provides a starting point for implementing the decorator pattern on top of the
21   * {@code DataTransaction} interface. Subclasses must implement method {@link #delegate()} and
22   * override the methods of {@code DataTransaction} they want to decorate.
23   * </p>
24   */
25  public abstract class ForwardingDataTransaction extends ForwardingObject implements
26          DataTransaction {
27  
28      @Override
29      protected abstract DataTransaction delegate();
30  
31      @Override
32      public Stream<Record> lookup(final URI type, final Set<? extends URI> ids,
33              @Nullable final Set<? extends URI> properties) throws IOException,
34              IllegalArgumentException, IllegalStateException {
35          return delegate().lookup(type, ids, properties);
36      }
37  
38      @Override
39      public Stream<Record> retrieve(final URI type, @Nullable final XPath condition,
40              @Nullable final Set<? extends URI> properties) throws IOException,
41              IllegalArgumentException, IllegalStateException {
42          return delegate().retrieve(type, condition, properties);
43      }
44  
45      @Override
46      public long count(final URI type, @Nullable final XPath condition) throws IOException,
47              IllegalArgumentException, IllegalStateException {
48          return delegate().count(type, condition);
49      }
50  
51      @Override
52      public Stream<Record> match(final Map<URI, XPath> conditions, final Map<URI, Set<URI>> ids,
53              final Map<URI, Set<URI>> properties) throws IOException, IllegalStateException {
54          return delegate().match(conditions, ids, properties);
55      }
56  
57      @Override
58      public void store(final URI type, final Record record) throws IOException,
59              IllegalStateException {
60          delegate().store(type, record);
61      }
62  
63      @Override
64      public void delete(final URI type, final URI id) throws IOException, IllegalStateException {
65          delegate().delete(type, id);
66      }
67  
68      @Override
69      public void end(final boolean commit) throws IOException, IllegalStateException {
70          delegate().end(commit);
71      }
72  
73  }