-
Notifications
You must be signed in to change notification settings - Fork 10
/
AGGraph.java
217 lines (185 loc) · 5.08 KB
/
AGGraph.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.franz.agraph.jena;
import org.openrdf.http.protocol.UnauthorizedException;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.query.Dataset;
import org.openrdf.query.impl.DatasetImpl;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.RepositoryResult;
import com.franz.agraph.repository.AGRepositoryConnection;
import com.franz.agraph.repository.AGValueFactory;
import com.hp.hpl.jena.graph.BulkUpdateHandler;
import com.hp.hpl.jena.graph.Capabilities;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphEventManager;
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Reifier;
import com.hp.hpl.jena.graph.TransactionHandler;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.TripleMatch;
import com.hp.hpl.jena.graph.query.QueryHandler;
import com.hp.hpl.jena.shared.AddDeniedException;
import com.hp.hpl.jena.shared.DeleteDeniedException;
import com.hp.hpl.jena.shared.PrefixMapping;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
public class AGGraph implements Graph {
private final AGGraphMaker maker;
private final Node graphNode;
private final AGRepositoryConnection conn;
private final AGValueFactory vf;
private final Resource context;
AGGraph(AGGraphMaker maker, Node graphNode) {
this.maker = maker;
this.graphNode = graphNode;
conn = maker.getRepositoryConnection();
vf = conn.getValueFactory();
context = vf.asResource(graphNode);
}
AGGraphMaker getGraphMaker() {
return maker;
}
Node getGraphNode() {
return graphNode;
}
Resource getGraphContext() {
return context;
}
AGRepositoryConnection getConnection() {
return conn;
}
@Override
public void close() {
}
@Override
public boolean contains(Triple t) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean contains(Node s, Node p, Node o) {
// TODO Auto-generated method stub
return false;
}
@Override
public void delete(Triple t) throws DeleteDeniedException {
try {
conn.remove(vf.asResource(t.getSubject()), vf.asURI(t.getPredicate()), vf.asValue(t.getObject()), context);
} catch (UnauthorizedException e) {
throw new DeleteDeniedException(e.getMessage());
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean dependsOn(Graph other) {
// TODO Auto-generated method stub
return false;
}
@Override
public ExtendedIterator<Triple> find(TripleMatch m) {
return find(m.getMatchSubject(),m.getMatchPredicate(),m.getMatchObject());
}
@Override
public ExtendedIterator<Triple> find(Node s, Node p, Node o) {
RepositoryResult<Statement> result;
try {
result = conn.getStatements(vf.asResource(s), vf.asURI(p), vf.asValue(o), false, context);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
return new AGTripleIterator(result);
}
@Override
public BulkUpdateHandler getBulkUpdateHandler() {
return new AGBulkUpdateHandler(this);
}
@Override
public Capabilities getCapabilities() {
// TODO Auto-generated method stub
return null;
}
@Override
public GraphEventManager getEventManager() {
// TODO Auto-generated method stub
return null;
}
@Override
public PrefixMapping getPrefixMapping() {
return new AGPrefixMapping(this);
}
@Override
public Reifier getReifier() {
// TODO Auto-generated method stub
return null;
}
@Override
public GraphStatisticsHandler getStatisticsHandler() {
// TODO Auto-generated method stub
return null;
}
@Override
public TransactionHandler getTransactionHandler() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isClosed() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isIsomorphicWith(Graph g) {
// TODO Auto-generated method stub
return false;
}
@Override
public QueryHandler queryHandler() {
// TODO Auto-generated method stub
return null;
}
@Override
public int size() {
// TODO deal with graphs bigger than int's.
int size;
try {
size = (int)conn.size(context);
} catch (RepositoryException e) {
// TODO: proper exception to throw?
throw new RuntimeException(e);
}
return size;
}
@Override
public void add(Triple t) throws AddDeniedException {
try {
conn.add(vf.asResource(t.getSubject()), vf.asURI(t.getPredicate()), vf.asValue(t.getObject()), context);
} catch (UnauthorizedException e) {
throw new AddDeniedException(e.getMessage());
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
@Override
public String toString() {
if (graphNode==null)
return "default-graph";
return graphNode.toString();
}
public Dataset getDataset() {
DatasetImpl dataset = new DatasetImpl();
if (context==null) {
dataset.addDefaultGraph(null);
} else if (context instanceof URI) {
dataset.addDefaultGraph((URI)context);
dataset.addNamedGraph((URI)context);
}
return dataset;
}
}