Skip to content

Commit ef106f9

Browse files
author
James Leigh
committed
Merge branch 'develop' of github.com:eclipse/rdf4j into issues/#870-repo-mgr-sail
2 parents 15a9a81 + fc5bdf7 commit ef106f9

44 files changed

Lines changed: 712 additions & 59 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SPARQLProtocolSession.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@
9494
import org.slf4j.Logger;
9595
import org.slf4j.LoggerFactory;
9696

97-
import com.google.common.base.Joiner;
98-
9997
/**
10098
* The SPARQLProtocolSession provides low level HTTP methods for communication with SPARQL endpoints. All
10199
* methods are compliant to the <a href="https://www.w3.org/TR/sparql11-protocol/">SPARQL 1.1 Protocol W3C
@@ -151,11 +149,6 @@ public class SPARQLProtocolSession implements HttpClientDependent {
151149

152150
final Logger logger = LoggerFactory.getLogger(this.getClass());
153151

154-
/**
155-
* shared instance of a {@link Joiner} for creating a comma-separated string.
156-
*/
157-
private static final Joiner commaJoiner = Joiner.on(", ");
158-
159152
/*-----------*
160153
* Variables *
161154
*-----------*/
@@ -828,7 +821,7 @@ private HttpResponse sendTupleQueryViaHttp(HttpUriRequest method, Set<QueryResul
828821
}
829822
}
830823

831-
method.addHeader(ACCEPT_PARAM_NAME, commaJoiner.join(acceptValues));
824+
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptValues));
832825

833826
try {
834827
return executeOK(method);
@@ -966,7 +959,7 @@ private HttpResponse sendGraphQueryViaHttp(HttpUriRequest method, boolean requir
966959
List<String> acceptParams = RDFFormat.getAcceptParams(rdfFormats, requireContext,
967960
getPreferredRDFFormat());
968961

969-
method.addHeader(ACCEPT_PARAM_NAME, commaJoiner.join(acceptParams));
962+
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptParams));
970963

971964
try {
972965
return executeOK(method);
@@ -1047,7 +1040,7 @@ private HttpResponse sendBooleanQueryViaHttp(HttpUriRequest method, Set<QueryRes
10471040
}
10481041
}
10491042

1050-
method.addHeader(ACCEPT_PARAM_NAME, commaJoiner.join(acceptValues));
1043+
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptValues));
10511044

10521045
return executeOK(method);
10531046
}

core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SharedHttpClientSessionManager.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@
1010
import java.util.Objects;
1111
import java.util.concurrent.ExecutorService;
1212
import java.util.concurrent.Executors;
13+
import java.util.concurrent.ThreadFactory;
1314
import java.util.concurrent.TimeUnit;
15+
import java.util.concurrent.atomic.AtomicLong;
1416

1517
import org.apache.http.client.HttpClient;
1618
import org.apache.http.client.utils.HttpClientUtils;
1719
import org.apache.http.impl.client.CloseableHttpClient;
1820
import org.apache.http.impl.client.HttpClientBuilder;
19-
import org.apache.http.impl.client.HttpClients;
2021
import org.eclipse.rdf4j.http.client.util.HttpClientBuilders;
2122

22-
import com.google.common.util.concurrent.ThreadFactoryBuilder;
23-
2423
/**
2524
* A Manager for HTTP sessions that uses a shared {@link HttpClient} to manage HTTP connections.
2625
*
2726
* @author James Leigh
2827
*/
2928
public class SharedHttpClientSessionManager implements HttpClientSessionManager, HttpClientDependent {
3029

30+
private static final AtomicLong threadCount = new AtomicLong();
31+
3132
/** independent life cycle */
3233
private volatile HttpClient httpClient;
3334

@@ -46,8 +47,16 @@ public class SharedHttpClientSessionManager implements HttpClientSessionManager,
4647
*--------------*/
4748

4849
public SharedHttpClientSessionManager() {
49-
this.executor = Executors.newCachedThreadPool(
50-
new ThreadFactoryBuilder().setNameFormat("rdf4j-sesameclientimpl-%d").build());
50+
final ThreadFactory backingThreadFactory = Executors.defaultThreadFactory();
51+
this.executor = Executors.newCachedThreadPool(new ThreadFactory() {
52+
53+
public Thread newThread(Runnable runnable) {
54+
Thread thread = backingThreadFactory.newThread(runnable);
55+
thread.setName(String.format("rdf4j-sesameclientimpl-%d", threadCount.getAndIncrement()));
56+
thread.setDaemon(true);
57+
return thread;
58+
}
59+
});
5160
}
5261

5362
public SharedHttpClientSessionManager(CloseableHttpClient dependentClient,

core/model/src/main/java/org/eclipse/rdf4j/model/Model.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @see org.eclipse.rdf4j.model.util.Models the Models utility class
2929
*/
3030
@SuppressWarnings("deprecation")
31-
public interface Model extends Graph, Set<Statement>, Serializable {
31+
public interface Model extends Graph, Set<Statement>, Serializable, NamespaceAware {
3232

3333
/**
3434
* Returns an unmodifiable view of this model. This method provides "read-only" access to this model.
@@ -40,25 +40,6 @@ public interface Model extends Graph, Set<Statement>, Serializable {
4040
*/
4141
public Model unmodifiable();
4242

43-
/**
44-
* Gets the map that contains the assigned namespaces.
45-
*
46-
* @return Map of prefix to namespace
47-
*/
48-
public Set<Namespace> getNamespaces();
49-
50-
/**
51-
* Gets the namespace that is associated with the specified prefix, if any.
52-
*
53-
* @param prefix
54-
* A namespace prefix.
55-
* @return The namespace name that is associated with the specified prefix, or {@link Optional#empty()} if
56-
* there is no such namespace.
57-
*/
58-
public default Optional<Namespace> getNamespace(String prefix) {
59-
return getNamespaces().stream().filter(t -> t.getPrefix().equals(prefix)).findAny();
60-
}
61-
6243
/**
6344
* Sets the prefix for a namespace. This will replace any existing namespace associated to the prefix.
6445
*
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Eclipse RDF4J contributors and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Distribution License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/org/documents/edl-v10.php.
7+
*******************************************************************************/
8+
package org.eclipse.rdf4j.model;
9+
10+
import java.util.Optional;
11+
import java.util.Set;
12+
13+
/**
14+
* An interface that is used to signify that something is able to provide {@link Namespace} information, in
15+
* addition to {@link Statement}s.
16+
*
17+
* @author Peter Ansell
18+
*/
19+
@FunctionalInterface
20+
public interface NamespaceAware {
21+
22+
/**
23+
* Gets the set that contains the assigned namespaces.
24+
*
25+
* @return A {@link Set} containing the {@link Namespace} objects that are available.
26+
*/
27+
public Set<Namespace> getNamespaces();
28+
29+
/**
30+
* Gets the namespace that is associated with the specified prefix, if any. If multiple namespaces match
31+
* the given prefix, the result may not be consistent over successive calls to this method.
32+
*
33+
* @param prefix
34+
* A namespace prefix.
35+
* @return The namespace name that is associated with the specified prefix, or {@link Optional#empty()} if
36+
* there is no such namespace.
37+
*/
38+
public default Optional<Namespace> getNamespace(String prefix) {
39+
return getNamespaces().stream().filter(t -> t.getPrefix().equals(prefix)).findAny();
40+
}
41+
42+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) 2017 Eclipse RDF4J contributors, and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Distribution License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/org/documents/edl-v10.php.
7+
*/
8+
package org.eclipse.rdf4j.model.util;
9+
10+
import java.lang.reflect.Field;
11+
import java.util.LinkedHashSet;
12+
import java.util.Set;
13+
14+
import org.eclipse.rdf4j.model.IRI;
15+
16+
/**
17+
* Utility functions for working with vocabularies.
18+
*
19+
* @author Bart Hanssens
20+
*/
21+
public class Vocabularies {
22+
/**
23+
* Get all the {@link IRI IRIs} of the classes and properties of a vocabulary.
24+
*
25+
* @param vocabulary RDF vocabulary
26+
* @return set of IRIs
27+
*/
28+
public static Set<IRI> getIRIs(Class vocabulary) {
29+
Set<IRI> iris = new LinkedHashSet<>();
30+
31+
for (Field f : vocabulary.getFields()) {
32+
if (f.getType().equals(IRI.class)) {
33+
try {
34+
iris.add((IRI) f.get(vocabulary));
35+
} catch (IllegalAccessException ex) {
36+
// should not happen
37+
throw new RuntimeException("Cannot access vocabulary field", ex);
38+
}
39+
}
40+
}
41+
return iris;
42+
}
43+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2017 Eclipse RDF4J contributors, and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Distribution License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/org/documents/edl-v10.php.
7+
*/
8+
package org.eclipse.rdf4j.model.util;
9+
10+
import java.util.Arrays;
11+
import java.util.HashSet;
12+
import java.util.Set;
13+
14+
import org.eclipse.rdf4j.model.IRI;
15+
import org.eclipse.rdf4j.model.vocabulary.DC;
16+
17+
import org.junit.Test;
18+
import static org.junit.Assert.assertEquals;
19+
20+
/**
21+
* @author Bart Hanssens
22+
*/
23+
public class VocabulariesTest {
24+
25+
@Test
26+
public void testVocabAllIRI() throws Exception {
27+
Set<IRI> dcIRIs = new HashSet<>(Arrays.asList(
28+
DC.CONTRIBUTOR, DC.COVERAGE, DC.CREATOR, DC.DATE, DC.DESCRIPTION,
29+
DC.FORMAT, DC.IDENTIFIER, DC.LANGUAGE, DC.PUBLISHER, DC.RELATION,
30+
DC.RIGHTS, DC.SOURCE, DC.SUBJECT, DC.TITLE, DC.TYPE));
31+
32+
Set<IRI> allIRIs = Vocabularies.getIRIs(DC.class);
33+
34+
assertEquals(dcIRIs, allIRIs);
35+
}
36+
}

core/repository/api/src/main/java/org/eclipse/rdf4j/repository/config/RepositoryConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*******************************************************************************/
88
package org.eclipse.rdf4j.repository.config;
99

10+
import static org.eclipse.rdf4j.repository.config.RepositoryConfigSchema.NAMESPACE;
1011
import static org.eclipse.rdf4j.repository.config.RepositoryConfigSchema.REPOSITORY;
1112
import static org.eclipse.rdf4j.repository.config.RepositoryConfigSchema.REPOSITORYID;
1213
import static org.eclipse.rdf4j.repository.config.RepositoryConfigSchema.REPOSITORYIMPL;
@@ -19,6 +20,7 @@
1920
import org.eclipse.rdf4j.model.util.Models;
2021
import org.eclipse.rdf4j.model.vocabulary.RDF;
2122
import org.eclipse.rdf4j.model.vocabulary.RDFS;
23+
import org.eclipse.rdf4j.model.vocabulary.XMLSchema;
2224

2325
/**
2426
* @author Arjohn Kampman
@@ -131,6 +133,9 @@ public void export(Model model) {
131133
*/
132134
public void export(Model model, Resource repositoryNode) {
133135
ValueFactory vf = SimpleValueFactory.getInstance();
136+
model.setNamespace(RDFS.NS);
137+
model.setNamespace(XMLSchema.NS);
138+
model.setNamespace("rep", NAMESPACE);
134139
model.add(repositoryNode, RDF.TYPE, REPOSITORY);
135140

136141
if (id != null) {

core/repository/http/src/main/java/org/eclipse/rdf4j/repository/http/config/HTTPRepositoryConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*******************************************************************************/
88
package org.eclipse.rdf4j.repository.http.config;
99

10+
import static org.eclipse.rdf4j.repository.http.config.HTTPRepositorySchema.NAMESPACE;
1011
import static org.eclipse.rdf4j.repository.http.config.HTTPRepositorySchema.PASSWORD;
1112
import static org.eclipse.rdf4j.repository.http.config.HTTPRepositorySchema.REPOSITORYURL;
1213
import static org.eclipse.rdf4j.repository.http.config.HTTPRepositorySchema.USERNAME;
@@ -78,6 +79,7 @@ public Resource export(Model graph) {
7879
Resource implNode = super.export(graph);
7980

8081
if (url != null) {
82+
graph.setNamespace("http", NAMESPACE);
8183
graph.add(implNode, REPOSITORYURL, SimpleValueFactory.getInstance().createIRI(url));
8284
}
8385
// if (username != null) {

core/repository/sail/src/main/java/org/eclipse/rdf4j/repository/sail/config/ProxyRepositoryConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void validate()
5050
public Resource export(Model model) {
5151
Resource implNode = super.export(model);
5252
if (null != this.proxiedID) {
53+
model.setNamespace("proxy", ProxyRepositorySchema.NAMESPACE);
5354
model.add(implNode, ProxyRepositorySchema.PROXIED_ID,
5455
SimpleValueFactory.getInstance().createLiteral(this.proxiedID));
5556
}

core/repository/sail/src/main/java/org/eclipse/rdf4j/repository/sail/config/SailRepositoryConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*******************************************************************************/
88
package org.eclipse.rdf4j.repository.sail.config;
99

10+
import static org.eclipse.rdf4j.repository.sail.config.SailRepositorySchema.NAMESPACE;
1011
import static org.eclipse.rdf4j.repository.sail.config.SailRepositorySchema.SAILIMPL;
1112
import static org.eclipse.rdf4j.sail.config.SailConfigSchema.SAILTYPE;
1213

@@ -69,6 +70,7 @@ public Resource export(Model model) {
6970
Resource repImplNode = super.export(model);
7071

7172
if (sailImplConfig != null) {
73+
model.setNamespace("sr", NAMESPACE);
7274
Resource sailImplNode = sailImplConfig.export(model);
7375
model.add(repImplNode, SAILIMPL, sailImplNode);
7476
}

0 commit comments

Comments
 (0)