Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Add Store Update #14

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions LICENSE.EDL
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Eclipse Distribution License - v 1.0

Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the Eclipse Foundation, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 3 additions & 1 deletion src/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target/
/.settings/
/.project
/.classpath
34 changes: 21 additions & 13 deletions src/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>store-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Lyo Store Parent</name>
<name>Lyo Store :: Parent</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -19,25 +19,18 @@

<modules>
<module>store-core</module>
<module>store-sync</module>
</modules>

<dependencyManagement>
<dependencies>
<!-- Jena -->

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId>
<version>3.0.1</version>
<artifactId>apache-jena-libs</artifactId>
<version>3.6.0</version>
<type>pom</type>
</dependency>

<!-- Generic -->
Expand All @@ -51,12 +44,23 @@
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<dependency>
<!--TODO why is it here?-->
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.04</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

<!-- Test -->
<dependency>
Expand Down Expand Up @@ -105,5 +109,9 @@
<name>Eclipse Public License 1.0</name>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
<license>
<name>Eclipse Distribution License 1.0</name>
<url>https://www.eclipse.org/org/documents/edl-v10.html</url>
</license>
</licenses>
</project>
10 changes: 5 additions & 5 deletions src/store-core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
hs_err_pid*

# Eclipse
.metadata
**/bin/
**/tmp/
/.project
/.classpath
/.metadata
*.tmp
*.bak
*.swp
Expand Down Expand Up @@ -63,8 +63,8 @@ local.properties
# MAVEN
#########################

**/overlays/
**/target/
/overlays/
/target/
pom.xml.tag
pom.xml.next
release.properties
Expand Down
39 changes: 7 additions & 32 deletions src/store-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>

<artifactId>store-core</artifactId>
<version>2.4.0-SNAPSHOT</version>
<name>Lyo Store :: Core</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -48,37 +48,8 @@
<!-- Jena -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
</dependency>

<!-- Generic -->
Expand Down Expand Up @@ -272,5 +243,9 @@
<name>Eclipse Public License 1.0</name>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
<license>
<name>Eclipse Distribution License 1.0</name>
<url>https://www.eclipse.org/org/documents/edl-v10.html</url>
</license>
</licenses>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
* @since 0.14.0
*/
public class ModelUnmarshallingException extends Exception {
/**
*
*/
private static final long serialVersionUID = 7760792549346636219L;

public ModelUnmarshallingException() {
super();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
* @since 0.13
*/
public class StoreAccessException extends Exception {
/**
*
*/
private static final long serialVersionUID = -7535919324037847033L;

public StoreAccessException() {
super();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Contributors:
* Andrew Berezovskyi - initial implementation
* %%
* Copyright (C) 2016 KTH Royal Institute of Technology
* Copyright (C) 2016 - 2018 KTH Royal Institute of Technology
* %%
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -15,6 +15,7 @@
*/

import com.google.common.collect.Sets;
import java.util.HashSet;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.rdf.model.Model;
Expand Down Expand Up @@ -74,6 +75,7 @@ public boolean namedGraphExists(final URI namedGraph) {
dataset.begin(ReadWrite.READ);
try {
contains = dataset.containsNamedModel(namedGraph.toString());
dataset.commit();
} finally {
dataset.end();
}
Expand All @@ -86,9 +88,9 @@ public <T extends IResource> List<T> getResources(final URI namedGraph,
if (namedGraphExists(namedGraph)) {
dataset.begin(ReadWrite.READ);
final Model model = dataset.getNamedModel(namedGraph.toString());
dataset.end();
try {
final Object[] obj = JenaModelHelper.fromJenaModel(model, clazz);
dataset.commit();
@SuppressWarnings("unchecked") final T[] castObjects = (T[]) Array.newInstance(
clazz, obj.length);
for (int i = 0; i < obj.length; i++) {
Expand All @@ -100,6 +102,8 @@ public <T extends IResource> List<T> getResources(final URI namedGraph,
InvocationTargetException | NoSuchMethodException | URISyntaxException e) {
throw new ModelUnmarshallingException(
"Failed to buildPersistent an " + "object from Jena model", e);
} finally {
dataset.end();
}
} else {
throw new StoreAccessException(
Expand Down Expand Up @@ -163,7 +167,9 @@ public Set<String> keySet() {
dataset.begin(ReadWrite.READ);
try {
final Iterator<String> namedGraphNames = dataset.listNames();
return Sets.newHashSet(namedGraphNames);
final HashSet<String> strings = Sets.newHashSet(namedGraphNames);
dataset.commit();
return strings;
} finally {
dataset.end();
}
Expand All @@ -172,7 +178,14 @@ public Set<String> keySet() {
@Override
public void removeAll() {
// TODO Andrew@2017-04-04: do we need a transaction here?
dataset.asDatasetGraph().clear();
dataset.begin(ReadWrite.WRITE);
try {
dataset.asDatasetGraph().clear();
dataset.commit();
}
finally {
dataset.end();
}
}

@Override
Expand All @@ -198,7 +211,7 @@ public void insertJenaModel(final URI name, final Model model) {
} finally {
dataset.end();
}
TDB.sync(dataset);
// TDB.sync(dataset);
}

public void putJenaModel(final URI name, final Model model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Contributors:
* Andrew Berezovskyi - initial implementation
* %%
* Copyright (C) 2016 KTH Royal Institute of Technology
* Copyright (C) 2016 - 2018 KTH Royal Institute of Technology
* %%
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -14,12 +14,17 @@
* #L%
*/

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.update.UpdateExecutionFactory;
import org.apache.jena.update.UpdateFactory;
import org.apache.jena.update.UpdateProcessor;
import org.apache.jena.atlas.web.auth.SimpleAuthenticator;

/**
* SparqlQueryExecutorImpl is a SPARQL endpoint-based implementation of {@link JenaQueryExecutor}.
Expand All @@ -32,23 +37,30 @@ public class SparqlQueryExecutorBasicAuthImpl implements JenaQueryExecutor {

private final String queryEndpoint;
private final String updateEndpoint;
private final SimpleAuthenticator authenticator;
private final CloseableHttpClient client;

public SparqlQueryExecutorBasicAuthImpl(final String sparqlEndpoint,
final String updateEndpoint, final String login, final String password) {
this.queryEndpoint = sparqlEndpoint;
this.updateEndpoint = updateEndpoint;
authenticator = new SimpleAuthenticator(login, password.toCharArray());
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(login, password);
provider.setCredentials(AuthScope.ANY, credentials);

client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
}

@Override
public QueryExecution prepareSparqlQuery(final String query) {
return QueryExecutionFactory.sparqlService(queryEndpoint, query, authenticator);
return QueryExecutionFactory.sparqlService(queryEndpoint, query, client);
}

@Override
public UpdateProcessor prepareSparqlUpdate(final String query) {
return UpdateExecutionFactory.createRemote(UpdateFactory.create(query), updateEndpoint,
authenticator);
return UpdateExecutionFactory.createRemote(
UpdateFactory.create(query),
updateEndpoint,
client
);
}
}
Loading