Skip to content

Commit 67f2b63

Browse files
committed
refactor a shared baseclass out of InsertRdfSourceTask
1 parent abf023a commit 67f2b63

File tree

2 files changed

+70
-21
lines changed

2 files changed

+70
-21
lines changed

cavendish-blazegraph/src/main/java/cavendish/blazegraph/task/InsertRdfSourceTask.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,21 @@
99
import org.openrdf.model.URI;
1010
import org.openrdf.model.Value;
1111
import org.openrdf.model.impl.ContextStatementImpl;
12-
import org.openrdf.model.impl.URIImpl;
1312
import org.openrdf.model.vocabulary.RDF;
1413
import org.openrdf.rio.RDFHandler;
15-
import org.openrdf.rio.RDFHandlerException;
1614

1715
import cavendish.blazegraph.ldp.Vocabulary;
1816
import cavendish.blazegraph.rdf.AddStatementHandler;
1917
import cavendish.blazegraph.rdf.ConstraintViolationException;
2018

2119
import com.bigdata.rdf.sail.BigdataSailRepositoryConnection;
22-
import com.bigdata.rdf.task.AbstractApiTask;
2320

2421
import org.openrdf.model.Resource;
2522
import org.slf4j.Logger;
2623
import org.slf4j.LoggerFactory;
2724

28-
public class InsertRdfSourceTask extends AbstractApiTask<Long> implements MutatingTask {
25+
public class InsertRdfSourceTask extends InsertResourceTask {
2926
private static final Logger LOG = LoggerFactory.getLogger(InsertRdfSourceTask.class);
30-
private final URI subject;
31-
private final Iterator<Statement> statementIterator;
3227
/**
3328
* @param namespace
3429
* The namespace of the target KB instance.
@@ -50,9 +45,7 @@ public InsertRdfSourceTask(final String namespace, final boolean isGRSRequired,
5045

5146
public InsertRdfSourceTask(final String namespace, final boolean isGRSRequired,
5247
final URI subject, Iterator<Statement> statements) {
53-
super(namespace, -1, isGRSRequired); // setting a > 0 time makes view read-only
54-
this.subject = subject;
55-
this.statementIterator = statements;
48+
super(namespace, isGRSRequired, subject, statements);
5649
}
5750

5851
public Long call() throws Exception {
@@ -153,18 +146,6 @@ public void validateContainerModel(URI subject, short ldpClassSwitches) throws C
153146
}
154147
}
155148

156-
public static void addTimeMap(URI subject, RDFHandler handler) throws RDFHandlerException {
157-
java.net.URI parsed = java.net.URI.create(subject.stringValue());
158-
parsed = parsed.resolve("/timemaps" + parsed.getPath());
159-
URIImpl timemap = new URIImpl(parsed.toString());
160-
handler.handleStatement(new ContextStatementImpl(subject, Vocabulary.IANA_TIMEMAP, timemap, Vocabulary.INTERNAL_CONTEXT));
161-
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_ORIGINAL, subject, Vocabulary.INTERNAL_CONTEXT));
162-
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_TYPE, Vocabulary.DIRECT_CONTAINER, Vocabulary.INTERNAL_CONTEXT));
163-
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_TYPE, Vocabulary.MEMENTO_TIMEMAP, Vocabulary.INTERNAL_CONTEXT));
164-
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.MEMBERSHIP_RESOURCE, subject, null));
165-
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.INSERTED_CONTENT_RELATION, timemap, null));
166-
}
167-
168149
@Override
169150
public boolean isReadOnly() {
170151
return false;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package cavendish.blazegraph.task;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.Iterator;
6+
7+
import org.openrdf.model.Statement;
8+
import org.openrdf.model.URI;
9+
import org.openrdf.model.impl.ContextStatementImpl;
10+
import org.openrdf.model.impl.URIImpl;
11+
import org.openrdf.rio.RDFHandler;
12+
import org.openrdf.rio.RDFHandlerException;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
16+
import com.bigdata.rdf.task.AbstractApiTask;
17+
18+
import cavendish.blazegraph.ldp.Vocabulary;
19+
20+
public abstract class InsertResourceTask extends AbstractApiTask<Long> implements MutatingTask {
21+
private static final Logger LOG = LoggerFactory.getLogger(InsertResourceTask.class);
22+
protected final URI subject;
23+
protected final Iterator<Statement> statementIterator;
24+
/**
25+
* @param namespace
26+
* The namespace of the target KB instance.
27+
* @param timestamp
28+
* The timestamp of the view of that KB instance.
29+
* @param isGRSRequired
30+
* <code>true</code> iff the task requires a lock on the GRS
31+
* index.
32+
*/
33+
public InsertResourceTask(final String namespace, final boolean isGRSRequired,
34+
final URI subject) {
35+
this(namespace, isGRSRequired, subject, Collections.<Statement> emptyList());
36+
}
37+
38+
public InsertResourceTask(final String namespace, final boolean isGRSRequired,
39+
final URI subject, Collection<Statement> statements) {
40+
this(namespace, isGRSRequired, subject, statements.iterator());
41+
}
42+
43+
public InsertResourceTask(final String namespace, final boolean isGRSRequired,
44+
final URI subject, Iterator<Statement> statements) {
45+
super(namespace, -1, isGRSRequired); // setting a > 0 time makes view read-only
46+
this.subject = subject;
47+
this.statementIterator = statements;
48+
}
49+
50+
public static void addTimeMap(URI subject, RDFHandler handler) throws RDFHandlerException {
51+
java.net.URI parsed = java.net.URI.create(subject.stringValue());
52+
parsed = parsed.resolve("/timemaps" + parsed.getPath());
53+
LOG.info("creating LDPCv/TimeMap at %s", parsed);
54+
URIImpl timemap = new URIImpl(parsed.toString());
55+
handler.handleStatement(new ContextStatementImpl(subject, Vocabulary.IANA_TIMEMAP, timemap, Vocabulary.INTERNAL_CONTEXT));
56+
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_ORIGINAL, subject, Vocabulary.INTERNAL_CONTEXT));
57+
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_TYPE, Vocabulary.DIRECT_CONTAINER, Vocabulary.INTERNAL_CONTEXT));
58+
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_TYPE, Vocabulary.MEMENTO_TIMEMAP, Vocabulary.INTERNAL_CONTEXT));
59+
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.MEMBERSHIP_RESOURCE, subject, null));
60+
handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.INSERTED_CONTENT_RELATION, timemap, null));
61+
}
62+
63+
@Override
64+
public boolean isReadOnly() {
65+
return false;
66+
}
67+
68+
}

0 commit comments

Comments
 (0)