You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2014/01/21 15:41:36 UTC
[1/2] git commit: switched LDPath Linked Data backend to use LDCache
directly
Updated Branches:
refs/heads/develop f3f6356f5 -> d1403dbd7
switched LDPath Linked Data backend to use LDCache directly
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1414cafe
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1414cafe
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1414cafe
Branch: refs/heads/develop
Commit: 1414cafe125d6cd111ea7d60829f98d720a56122
Parents: 21e0e9d
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Jan 21 15:41:16 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Jan 21 15:41:16 2014 +0100
----------------------------------------------------------------------
.../commons/sesame/model/ValueCommons.java | 43 +++
.../services/test/ng/BaseLDCacheTest.java | 8 +-
.../ldpath/ldpath-backend-linkeddata/pom.xml | 42 ++-
.../backend/linkeddata/LDCacheBackend.java | 342 +++++++++++++++++++
.../backend/linkeddata/LDPersistentBackend.java | 97 ------
.../ldpath/backend/linkeddata/LDQuery.java | 26 +-
.../linkeddata/test/LDCacheBackendTest.java | 93 +++++
.../marmotta/ldpath/template/LDTemplate.java | 39 +--
8 files changed, 515 insertions(+), 175 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1414cafe/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/ValueCommons.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/ValueCommons.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/ValueCommons.java
new file mode 100644
index 0000000..5b4493f
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/ValueCommons.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.commons.sesame.model;
+
+import com.google.common.base.Function;
+import org.openrdf.model.Value;
+
+/**
+ * Utility functions for working with values.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ValueCommons {
+
+ public static Function<Value,String> stringValue() {
+ return STRING_VALUE;
+ }
+
+
+
+ private static Function<Value, String> STRING_VALUE = new Function<Value, String>() {
+ @Override
+ public String apply(Value input) {
+ return input.stringValue();
+ }
+ };
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1414cafe/libraries/ldcache/ldcache-core/src/test/java/org/apache/marmotta/ldcache/services/test/ng/BaseLDCacheTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-core/src/test/java/org/apache/marmotta/ldcache/services/test/ng/BaseLDCacheTest.java b/libraries/ldcache/ldcache-core/src/test/java/org/apache/marmotta/ldcache/services/test/ng/BaseLDCacheTest.java
index f2d243d..8f42b22 100644
--- a/libraries/ldcache/ldcache-core/src/test/java/org/apache/marmotta/ldcache/services/test/ng/BaseLDCacheTest.java
+++ b/libraries/ldcache/ldcache-core/src/test/java/org/apache/marmotta/ldcache/services/test/ng/BaseLDCacheTest.java
@@ -44,10 +44,10 @@ import java.io.StringWriter;
*/
public abstract class BaseLDCacheTest {
- private static final String DBPEDIA = "http://dbpedia.org/resource/Berlin";
- private static final String GEONAMES = "http://sws.geonames.org/3020251/";
- private static final String MARMOTTA = "http://rdfohloh.wikier.org/project/marmotta";
- private static final String WIKIER = "http://www.wikier.org/foaf#wikier";
+ public static final String DBPEDIA = "http://dbpedia.org/resource/Berlin";
+ public static final String GEONAMES = "http://sws.geonames.org/3020251/";
+ public static final String MARMOTTA = "http://rdfohloh.wikier.org/project/marmotta";
+ public static final String WIKIER = "http://www.wikier.org/foaf#wikier";
private static Logger log = LoggerFactory.getLogger(BaseLDCacheTest.class);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1414cafe/libraries/ldpath/ldpath-backend-linkeddata/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/pom.xml b/libraries/ldpath/ldpath-backend-linkeddata/pom.xml
index 0299f77..89f317a 100644
--- a/libraries/ldpath/ldpath-backend-linkeddata/pom.xml
+++ b/libraries/ldpath/ldpath-backend-linkeddata/pom.xml
@@ -232,11 +232,7 @@
</dependency>
<dependency>
<groupId>org.apache.marmotta</groupId>
- <artifactId>ldcache-sail-generic</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>ldcache-backend-file</artifactId>
+ <artifactId>ldcache-backend-infinispan</artifactId>
</dependency>
<!-- Sesame Model and Parsers -->
@@ -280,18 +276,6 @@
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-trig</artifactId>
</dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-sail-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-sail-memory</artifactId>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-sail-nativerdf</artifactId>
- </dependency>
<dependency>
<groupId>commons-cli</groupId>
@@ -316,6 +300,30 @@
<artifactId>guava</artifactId>
</dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>hamcrest-core</artifactId>
+ <groupId>org.hamcrest</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>hamcrest-library</artifactId>
+ <groupId>org.hamcrest</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>ldcache-core</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1414cafe/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDCacheBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDCacheBackend.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDCacheBackend.java
new file mode 100644
index 0000000..05097eb
--- /dev/null
+++ b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDCacheBackend.java
@@ -0,0 +1,342 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.backend.linkeddata;
+
+import org.apache.marmotta.ldcache.api.LDCachingBackend;
+import org.apache.marmotta.ldcache.backend.infinispan.LDCachingInfinispanBackend;
+import org.apache.marmotta.ldcache.model.CacheConfiguration;
+import org.apache.marmotta.ldcache.services.LDCache;
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.openrdf.model.BNode;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Value;
+import org.openrdf.model.impl.LiteralImpl;
+import org.openrdf.model.impl.URIImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.*;
+import java.util.concurrent.ThreadPoolExecutor;
+
+/**
+ * A Linked Data backend with persistent caching of the retrieved data. All data is read and stored in the directory
+ * passed as constructor argument.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LDCacheBackend implements RDFBackend<Value> {
+ private static final Logger log = LoggerFactory.getLogger(LDCacheBackend.class);
+
+
+ private LDCache ldcache;
+
+
+ public LDCacheBackend() {
+ LDCachingBackend backend = new LDCachingInfinispanBackend();
+ backend.initialize();
+
+ this.ldcache = new LDCache(new CacheConfiguration(), backend);
+ }
+
+ public LDCacheBackend(LDCache ldcache) {
+ this.ldcache = ldcache;
+ }
+
+ /**
+ * Test whether the node passed as argument is a literal
+ *
+ * @param n the node to check
+ * @return true if the node is a literal
+ */
+ @Override
+ public boolean isLiteral(Value n) {
+ return n instanceof Literal;
+ }
+
+ /**
+ * Test whether the node passed as argument is a URI
+ *
+ * @param n the node to check
+ * @return true if the node is a URI
+ */
+ @Override
+ public boolean isURI(Value n) {
+ return n instanceof org.openrdf.model.URI;
+ }
+
+ /**
+ * Test whether the node passed as argument is a blank node
+ *
+ * @param n the node to check
+ * @return true if the node is a blank node
+ */
+ @Override
+ public boolean isBlank(Value n) {
+ return n instanceof BNode;
+ }
+
+ /**
+ * Return the language of the literal node passed as argument.
+ *
+ * @param n the literal node for which to return the language
+ * @return a Locale representing the language of the literal, or null if the literal node has no language
+ * @throws IllegalArgumentException in case the node is no literal
+ */
+ @Override
+ public Locale getLiteralLanguage(Value n) {
+ try {
+ if(((Literal)n).getLanguage() != null) {
+ return new Locale( ((Literal)n).getLanguage() );
+ } else {
+ return null;
+ }
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+n.stringValue()+" is not a literal" +
+ "but of type "+debugType(n));
+ }
+ }
+
+ /**
+ * Return the URI of the type of the literal node passed as argument.
+ *
+ * @param n the literal node for which to return the typer
+ * @return a URI representing the type of the literal content, or null if the literal is untyped
+ * @throws IllegalArgumentException in case the node is no literal
+ */
+ @Override
+ public URI getLiteralType(Value n) {
+ try {
+ if(((Literal)n).getDatatype() != null) {
+ try {
+ return new URI(((Literal)n).getDatatype().stringValue());
+ } catch (URISyntaxException e) {
+ log.error("literal datatype was not a valid URI: {}",((Literal) n).getDatatype());
+ return null;
+ }
+ } else {
+ return null;
+ }
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+n.stringValue()+" is not a literal" +
+ "but of type "+debugType(n));
+ }
+ }
+
+ /**
+ * Return the string value of a node. For a literal, this will be the content, for a URI node it will be the
+ * URI itself, and for a blank node it will be the identifier of the node.
+ *
+ * @param value
+ * @return
+ */
+ @Override
+ public String stringValue(Value value) {
+ return value.stringValue();
+ }
+
+ @Override
+ public BigDecimal decimalValue(Value node) {
+ try {
+ return ((Literal)node).decimalValue();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+ @Override
+ public BigInteger integerValue(Value node) {
+ try {
+ return ((Literal)node).integerValue();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+ @Override
+ public Boolean booleanValue(Value node) {
+ try {
+ return ((Literal)node).booleanValue();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+ @Override
+ public Date dateTimeValue(Value node) {
+ try {
+ XMLGregorianCalendar cal = ((Literal)node).calendarValue();
+ //TODO: check if we need to deal with timezone and Local here
+ return cal.toGregorianCalendar().getTime();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+ @Override
+ public Date dateValue(Value node) {
+ try {
+ XMLGregorianCalendar cal = ((Literal)node).calendarValue();
+ return new GregorianCalendar(cal.getYear(), cal.getMonth(), cal.getDay()).getTime();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+ @Override
+ public Date timeValue(Value node) {
+ //TODO: Unless someone knows how to create a Date that only has the time
+ // from a XMLGregorianCalendar
+ return dateTimeValue(node);
+ }
+
+ @Override
+ public Long longValue(Value node) {
+ try {
+ return ((Literal)node).longValue();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+ @Override
+ public Double doubleValue(Value node) {
+ try {
+ return ((Literal)node).doubleValue();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+ @Override
+ public Float floatValue(Value node) {
+ try {
+ return ((Literal)node).floatValue();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+ @Override
+ public Integer intValue(Value node) {
+ try {
+ return ((Literal)node).intValue();
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
+ "but of type "+debugType(node));
+ }
+ }
+
+
+ /**
+ * Prints the type (URI,bNode,literal) by inspecting the parsed {@link Value}
+ * to improve error messages and other loggings. In case of literals
+ * also the {@link #getLiteralType(Value) literal type} is printed
+ * @param value the value or <code>null</code>
+ * @return the type as string.
+ */
+ protected String debugType(Value value) {
+ return value == null ? "null":isURI(value)?"URI":isBlank(value)?"bNode":
+ "literal ("+getLiteralType(value)+")";
+ }
+
+ @Override
+ public Literal createLiteral(String content) {
+ return new LiteralImpl(content);
+ }
+
+ @Override
+ public Literal createLiteral(String content, Locale language, URI type) {
+ log.debug("creating literal with content \"{}\", language {}, datatype {}",new Object[]{content,language,type});
+ if(language == null && type == null) {
+ return createLiteral(content);
+ } else if(type == null) {
+ return new LiteralImpl(content,language.getLanguage());
+ } else {
+ return new LiteralImpl(content, createURI(type.toString()));
+ }
+ }
+
+ @Override
+ public org.openrdf.model.URI createURI(String uri) {
+ return new URIImpl(uri);
+ }
+
+
+ /**
+ * @deprecated subject to be removed in the next release
+ */
+ @Override
+ public boolean supportsThreading() {
+ return false;
+ }
+
+ /**
+ * @deprecated subject to be removed in the next release
+ */
+ @Override
+ public ThreadPoolExecutor getThreadPool() {
+ return null;
+ }
+
+ /**
+ * List the objects of triples in the triple store underlying this backend that have the subject and
+ * property given as argument.
+ *
+ * @param subject the subject of the triples to look for
+ * @param property the property of the triples to look for, <code>null</code> is interpreted as wildcard
+ * @return all objects of triples with matching subject and property
+ */
+ @Override
+ public Collection<Value> listObjects(Value subject, Value property) {
+ log.info("retrieving resource {}", subject);
+ if(subject instanceof org.openrdf.model.URI && subject instanceof org.openrdf.model.URI) {
+ org.openrdf.model.URI s = (org.openrdf.model.URI) subject;
+ org.openrdf.model.URI p = (org.openrdf.model.URI) property;
+ return ldcache.get(s).filter(s, p, null).objects();
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ /**
+ * List the subjects of triples in the triple store underlying this backend that have the object and
+ * property given as argument.
+ *
+ * @param property the property of the triples to look for, <code>null</code> is interpreted as wildcard
+ * @param object the object of the triples to look for
+ * @return all subjects of triples with matching object and property
+ * @throws UnsupportedOperationException in case reverse selection is not supported (e.g. when querying Linked Data)
+ */
+ @Override
+ public Collection<Value> listSubjects(Value property, Value object) {
+ throw new UnsupportedOperationException("reverse traversal not supported for Linked Data backend");
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1414cafe/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDPersistentBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDPersistentBackend.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDPersistentBackend.java
deleted file mode 100644
index 1e56703..0000000
--- a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDPersistentBackend.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.marmotta.ldpath.backend.linkeddata;
-
-import org.apache.marmotta.commons.sesame.filter.AlwaysTrueFilter;
-import org.apache.marmotta.commons.sesame.filter.SesameFilter;
-import org.apache.marmotta.ldcache.backend.file.LDCachingFileBackend;
-import org.apache.marmotta.ldcache.sail.GenericLinkedDataSail;
-import org.apache.marmotta.ldclient.model.ClientConfiguration;
-import org.apache.marmotta.ldpath.backend.sesame.SesameRepositoryBackend;
-import org.openrdf.model.Resource;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sail.SailRepository;
-import org.openrdf.sail.memory.MemoryStore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * A Linked Data backend with persistent caching of the retrieved data. All data is read and stored in the directory
- * passed as constructor argument.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class LDPersistentBackend extends SesameRepositoryBackend {
- private static final Logger log = LoggerFactory.getLogger(LDPersistentBackend.class);
-
- private LDCachingFileBackend backend;
-
- private GenericLinkedDataSail sail;
-
- private SesameFilter<Resource> cacheFilter;
-
-
- /**
- * Create a persistent linked data backend storing the cache data in the directory passed as argument.
- * The directory will be created if it does not exist.
- * @param dataDirectory
- */
- public LDPersistentBackend(File dataDirectory) throws IOException {
- super();
-
- if(!dataDirectory.exists()) {
- dataDirectory.mkdirs();
- }
-
- File tripleStore = new File(dataDirectory.getAbsolutePath()+File.separator+"triples");
- if(!tripleStore.exists()) {
- tripleStore.mkdirs();
- }
-
- cacheFilter = new AlwaysTrueFilter<Resource>();
-
- try {
- ClientConfiguration config = new ClientConfiguration();
-
- backend = new LDCachingFileBackend(dataDirectory);
- sail = new GenericLinkedDataSail(new MemoryStore(),backend, cacheFilter, config);
- Repository repository = new SailRepository(sail);
- repository.initialize();
- setRepository(repository);
-
- } catch (RepositoryException e) {
- log.error("error initialising connection to Sesame in-memory repository",e);
- }
- }
-
-
- public void shutdown() {
- try {
- getRepository().shutDown();
- } catch (RepositoryException e) {
- log.error("error shutting down repository for resource cache");
- }
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1414cafe/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java
index 5a7ee3e..b5383c0 100644
--- a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java
+++ b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java
@@ -18,19 +18,9 @@
package org.apache.marmotta.ldpath.backend.linkeddata;
import ch.qos.logback.classic.Level;
-import com.google.common.io.Files;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.OptionGroup;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.*;
import org.apache.commons.io.FileUtils;
import org.apache.marmotta.ldpath.LDPath;
-import org.apache.marmotta.ldpath.backend.sesame.SesameRepositoryBackend;
import org.apache.marmotta.ldpath.exception.LDPathParseException;
import org.openrdf.model.Resource;
import org.openrdf.model.Value;
@@ -89,18 +79,11 @@ public class LDQuery {
File tmpDir = null;
- SesameRepositoryBackend backend;
- if(cmd.hasOption("store")) {
- backend = new LDPersistentBackend(new File(cmd.getOptionValue("store")));
- } else {
- tmpDir = Files.createTempDir();
-
- backend = new LDPersistentBackend(tmpDir);
- }
+ LDCacheBackend backend = new LDCacheBackend();
Resource context = null;
if(cmd.hasOption("context")) {
- context = backend.getRepository().getValueFactory().createURI(cmd.getOptionValue("context"));
+ context = backend.createURI(cmd.getOptionValue("context"));
}
if(backend != null && context != null) {
@@ -135,9 +118,6 @@ public class LDQuery {
}
}
- if(backend instanceof LDPersistentBackend) {
- ((LDPersistentBackend) backend).shutdown();
- }
if(tmpDir != null) {
FileUtils.deleteDirectory(tmpDir);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1414cafe/libraries/ldpath/ldpath-backend-linkeddata/src/test/java/org/apache/marmotta/ldpath/backend/linkeddata/test/LDCacheBackendTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/test/java/org/apache/marmotta/ldpath/backend/linkeddata/test/LDCacheBackendTest.java b/libraries/ldpath/ldpath-backend-linkeddata/src/test/java/org/apache/marmotta/ldpath/backend/linkeddata/test/LDCacheBackendTest.java
new file mode 100644
index 0000000..690dd49
--- /dev/null
+++ b/libraries/ldpath/ldpath-backend-linkeddata/src/test/java/org/apache/marmotta/ldpath/backend/linkeddata/test/LDCacheBackendTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.ldpath.backend.linkeddata.test;
+
+import com.google.common.collect.Collections2;
+import org.apache.marmotta.commons.sesame.model.ValueCommons;
+import org.apache.marmotta.ldcache.api.LDCachingBackend;
+import org.apache.marmotta.ldcache.backend.infinispan.LDCachingInfinispanBackend;
+import org.apache.marmotta.ldcache.services.test.ng.BaseLDCacheTest;
+import org.apache.marmotta.ldpath.LDPath;
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.apache.marmotta.ldpath.backend.linkeddata.LDCacheBackend;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.openrdf.model.Value;
+import org.openrdf.model.impl.URIImpl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class LDCacheBackendTest extends BaseLDCacheTest {
+
+ protected static Map<String,String> pathExpressions = new HashMap<>();
+ protected static Map<String,String> pathResults = new HashMap<>();
+ static {
+ pathExpressions.put(DBPEDIA, "rdfs:label[@en]");
+ pathResults.put(DBPEDIA, "Berlin");
+
+ pathExpressions.put(GEONAMES, "<http://www.geonames.org/ontology#name>");
+ pathResults.put(GEONAMES, "Embrun");
+
+ pathExpressions.put(MARMOTTA, "<http://usefulinc.com/ns/doap#name>");
+ pathResults.put(MARMOTTA, "Apache Marmotta");
+
+ pathExpressions.put(WIKIER, "<http://xmlns.com/foaf/0.1/name>[@es]");
+ pathResults.put(WIKIER, "Sergio Fernández");
+ }
+
+ /**
+ * Needs to be implemented by tests to provide the correct backend. Backend needs to be properly initialised.
+ *
+ * @return
+ */
+ @Override
+ protected LDCachingBackend createBackend() {
+ LDCachingBackend backend = new LDCachingInfinispanBackend();
+ backend.initialize();
+
+ return backend;
+ }
+
+ protected RDFBackend<Value> createLDPathBackend() {
+ LDCacheBackend backend = new LDCacheBackend(ldcache);
+ return backend;
+ }
+
+
+ @Override
+ protected void testResource(String uri, String sparqlFile) throws Exception {
+ super.testResource(uri, sparqlFile);
+
+ if(pathExpressions.containsKey(uri)) {
+ LDPath<Value> ldpath = new LDPath<Value>(createLDPathBackend());
+
+ Collection<String> results = Collections2.transform(ldpath.pathQuery(new URIImpl(uri), pathExpressions.get(uri), Collections.EMPTY_MAP), ValueCommons.stringValue());
+
+ Assert.assertThat(results, Matchers.hasItem(pathResults.get(uri)));
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1414cafe/libraries/ldpath/ldpath-template-linkeddata/src/main/java/org/apache/marmotta/ldpath/template/LDTemplate.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-template-linkeddata/src/main/java/org/apache/marmotta/ldpath/template/LDTemplate.java b/libraries/ldpath/ldpath-template-linkeddata/src/main/java/org/apache/marmotta/ldpath/template/LDTemplate.java
index 320d38a..0d684c2 100644
--- a/libraries/ldpath/ldpath-template-linkeddata/src/main/java/org/apache/marmotta/ldpath/template/LDTemplate.java
+++ b/libraries/ldpath/ldpath-template-linkeddata/src/main/java/org/apache/marmotta/ldpath/template/LDTemplate.java
@@ -18,31 +18,17 @@
package org.apache.marmotta.ldpath.template;
import ch.qos.logback.classic.Level;
-import com.google.common.io.Files;
import freemarker.template.TemplateException;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.*;
import org.apache.commons.io.FileUtils;
-import org.apache.marmotta.ldpath.backend.linkeddata.LDPersistentBackend;
-import org.apache.marmotta.ldpath.backend.sesame.SesameRepositoryBackend;
+import org.apache.marmotta.ldpath.backend.linkeddata.LDCacheBackend;
import org.apache.marmotta.ldpath.template.engine.TemplateEngine;
import org.openrdf.model.Resource;
import org.openrdf.model.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.io.*;
/**
* Add file description here!
@@ -94,18 +80,11 @@ public class LDTemplate {
File tmpDir = null;
- SesameRepositoryBackend backend;
- if(cmd.hasOption("store")) {
- backend = new LDPersistentBackend(new File(cmd.getOptionValue("store")));
- } else {
- tmpDir = Files.createTempDir();
-
- backend = new LDPersistentBackend(tmpDir);
- }
+ LDCacheBackend backend = new LDCacheBackend();
Resource context = null;
if(cmd.hasOption("context")) {
- context = backend.getRepository().getValueFactory().createURI(cmd.getOptionValue("context"));
+ context = backend.createURI(cmd.getOptionValue("context"));
}
BufferedWriter out = null;
@@ -130,10 +109,6 @@ public class LDTemplate {
}
out.close();
- if(backend instanceof LDPersistentBackend) {
- ((LDPersistentBackend) backend).shutdown();
- }
-
if(tmpDir != null) {
FileUtils.deleteDirectory(tmpDir);
}
@@ -178,10 +153,6 @@ public class LDTemplate {
Option loglevel = OptionBuilder.withArgName("level").hasArg().withDescription("set the log level; default is 'warn'").create("loglevel");
result.addOption(loglevel);
- Option store = OptionBuilder.withArgName("dir").hasArg().withDescription("cache the retrieved data in this directory").create("store");
- result.addOption(store);
-
-
return result;
}
[2/2] git commit: Merge remote-tracking branch 'origin/develop' into
develop
Posted by ss...@apache.org.
Merge remote-tracking branch 'origin/develop' into develop
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d1403dbd
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d1403dbd
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d1403dbd
Branch: refs/heads/develop
Commit: d1403dbd7116afaed6c42b744571881a8a477ef9
Parents: 1414caf f3f6356
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Jan 21 15:41:29 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Jan 21 15:41:29 2014 +0100
----------------------------------------------------------------------
launchers/marmotta-installer/pom.xml | 24 +++-----------------
.../src/main/resources/installer/standalone.xml | 3 +--
launchers/marmotta-splash/pom.xml | 1 +
.../splash/common/ui/SelectionDialog.java | 5 +---
.../splash/startup/StartupListener.java | 16 ++++++++-----
.../splash/systray/SystrayListener.java | 2 --
6 files changed, 16 insertions(+), 35 deletions(-)
----------------------------------------------------------------------