1
2
3
4
5
6 package org.openrdf.repository.delegate;
7
8 import java.io.File;
9 import java.io.IOException;
10 import java.io.InputStream;
11 import java.io.Reader;
12 import java.net.URL;
13
14 import org.openrdf.model.Resource;
15 import org.openrdf.model.Statement;
16 import org.openrdf.model.URI;
17 import org.openrdf.model.Value;
18 import org.openrdf.repository.Repository;
19 import org.openrdf.repository.RepositoryConnection;
20 import org.openrdf.repository.RepositoryException;
21 import org.openrdf.repository.base.RepositoryConnectionWrapper;
22 import org.openrdf.rio.RDFFormat;
23 import org.openrdf.rio.RDFParseException;
24
25
26
27
28
29
30
31
32 public class VersioningConnection extends RepositoryConnectionWrapper {
33
34 private int _version;
35
36 public VersioningConnection(Repository repository, RepositoryConnection delegate, int version) {
37 super(repository, delegate);
38 _version = version;
39 }
40
41 public int getVersion() {
42 return _version;
43 }
44
45 @Override
46 public void setAutoCommit(boolean autoCommit)
47 throws RepositoryException
48 {
49 super.setAutoCommit(autoCommit);
50 if (super.isAutoCommit()) {
51 _version++;
52 }
53 }
54
55 @Override
56 public void commit()
57 throws RepositoryException
58 {
59 super.commit();
60 _version++;
61 }
62
63 @Override
64 public void rollback()
65 throws RepositoryException
66 {
67 super.rollback();
68 _version++;
69 }
70
71 @Override
72 public void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts)
73 throws IOException, RDFParseException, RepositoryException
74 {
75 super.add(in, baseURI, dataFormat, contexts);
76 if (super.isAutoCommit()) {
77 _version++;
78 }
79 }
80
81 @Override
82 public void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts)
83 throws IOException, RDFParseException, RepositoryException
84 {
85 super.add(reader, baseURI, dataFormat, contexts);
86 if (super.isAutoCommit()) {
87 _version++;
88 }
89 }
90
91 @Override
92 public void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts)
93 throws IOException, RDFParseException, RepositoryException
94 {
95 super.add(url, baseURI, dataFormat, contexts);
96 if (super.isAutoCommit()) {
97 _version++;
98 }
99 }
100
101 @Override
102 public void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts)
103 throws IOException, RDFParseException, RepositoryException
104 {
105 super.add(file, baseURI, dataFormat, contexts);
106 if (super.isAutoCommit()) {
107 _version++;
108 }
109 }
110
111 @Override
112 public void add(Resource subject, URI predicate, Value object, Resource... contexts)
113 throws RepositoryException
114 {
115 super.add(subject, predicate, object, contexts);
116 if (super.isAutoCommit()) {
117 _version++;
118 }
119 }
120
121 @Override
122 public void add(Statement st, Resource... contexts)
123 throws RepositoryException
124 {
125 super.add(st, contexts);
126 if (super.isAutoCommit()) {
127 _version++;
128 }
129 }
130
131 @Override
132 public void add(Iterable<? extends Statement> statements, Resource... contexts)
133 throws RepositoryException
134 {
135 super.add(statements, contexts);
136 if (super.isAutoCommit()) {
137 _version++;
138 }
139 }
140
141 @Override
142 public void clear(Resource... contexts)
143 throws RepositoryException
144 {
145 super.clear(contexts);
146 if (super.isAutoCommit()) {
147 _version++;
148 }
149 }
150
151 @Override
152 public void remove(Resource subject, URI predicate, Value object, Resource... contexts)
153 throws RepositoryException
154 {
155 super.remove(subject, predicate, object, contexts);
156 if (super.isAutoCommit()) {
157 _version++;
158 }
159 }
160
161 @Override
162 public void remove(Statement st, Resource... contexts)
163 throws RepositoryException
164 {
165 super.remove(st, contexts);
166 if (super.isAutoCommit()) {
167 _version++;
168 }
169 }
170
171 @Override
172 public void remove(Iterable<? extends Statement> statements, Resource... contexts)
173 throws RepositoryException
174 {
175 super.remove(statements, contexts);
176 if (super.isAutoCommit()) {
177 _version++;
178 }
179 }
180 }