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 2013/09/04 12:06:14 UTC
[1/2] git commit: towards better Sesame compliance (now most tests
are working)
Updated Branches:
refs/heads/develop 733020216 -> 8a2fe2bec
towards better Sesame compliance (now most tests are working)
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/117187d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/117187d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/117187d8
Branch: refs/heads/develop
Commit: 117187d80a673302ce8e3e7c38f5d06292c25ec3
Parents: dc2f18a
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Wed Sep 4 12:05:42 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Wed Sep 4 12:05:42 2013 +0200
----------------------------------------------------------------------
.../commons/collections/CollectionUtils.java | 2 +
.../commons/collections/EquivalenceHashSet.java | 448 +++++++++++++++++++
.../kiwi/persistence/KiWiConnection.java | 10 +-
.../kiwi/persistence/KiWiPersistence.java | 17 +-
.../marmotta/kiwi/sail/KiWiSailConnection.java | 2 +-
.../apache/marmotta/kiwi/sail/KiWiStore.java | 6 +-
.../marmotta/kiwi/sail/KiWiValueFactory.java | 167 ++++---
.../marmotta/kiwi/test/PersistenceTest.java | 1 +
libraries/kiwi/kiwi-tripletable/pom.xml | 4 +
.../kiwi/model/caching/TripleTable.java | 64 +--
10 files changed, 584 insertions(+), 137 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/CollectionUtils.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/CollectionUtils.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/CollectionUtils.java
index 7c4fd6f..0b9785f 100644
--- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/CollectionUtils.java
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/CollectionUtils.java
@@ -17,6 +17,8 @@
*/
package org.apache.marmotta.commons.collections;
+import com.google.common.base.Equivalence;
+
import java.text.Format;
import java.util.ArrayList;
import java.util.Collection;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java
new file mode 100644
index 0000000..09c8a15
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java
@@ -0,0 +1,448 @@
+/*
+ * 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.collections;
+
+import com.google.common.base.Equivalence;
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterators;
+
+import java.util.*;
+
+/**
+ * A hashset implementation accepting different notions of equvialence (based on the Guava Equivalence class).
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class EquivalenceHashSet<E> implements Set<E> {
+
+ private Equivalence equivalence;
+
+ private HashSet<ElementWrapper> delegate;
+
+
+ public EquivalenceHashSet() {
+ this.equivalence = Equivalence.equals();
+ this.delegate = new HashSet<>();
+ }
+
+ public EquivalenceHashSet(Equivalence equivalence) {
+ this.equivalence = equivalence;
+ this.delegate = new HashSet<>();
+ }
+
+
+ /**
+ * Adds the specified element to this set if it is not already present
+ * (optional operation). More formally, adds the specified element
+ * <tt>e</tt> to this set if the set contains no element <tt>e2</tt>
+ * such that
+ * <tt>(e==null ? e2==null : e.equals(e2))</tt>.
+ * If this set already contains the element, the call leaves the set
+ * unchanged and returns <tt>false</tt>. In combination with the
+ * restriction on constructors, this ensures that sets never contain
+ * duplicate elements.
+ * <p/>
+ * <p>The stipulation above does not imply that sets must accept all
+ * elements; sets may refuse to add any particular element, including
+ * <tt>null</tt>, and throw an exception, as described in the
+ * specification for {@link java.util.Collection#add Collection.add}.
+ * Individual set implementations should clearly document any
+ * restrictions on the elements that they may contain.
+ *
+ * @param e element to be added to this set
+ * @return <tt>true</tt> if this set did not already contain the specified
+ * element
+ * @throws UnsupportedOperationException if the <tt>add</tt> operation
+ * is not supported by this set
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this set
+ * @throws NullPointerException if the specified element is null and this
+ * set does not permit null elements
+ * @throws IllegalArgumentException if some property of the specified element
+ * prevents it from being added to this set
+ */
+ @Override
+ public boolean add(E e) {
+ return delegate.add(new ElementWrapper(e));
+ }
+
+ /**
+ * Returns the number of elements in this set (its cardinality). If this
+ * set contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
+ * <tt>Integer.MAX_VALUE</tt>.
+ *
+ * @return the number of elements in this set (its cardinality)
+ */
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ /**
+ * Returns <tt>true</tt> if this set contains no elements.
+ *
+ * @return <tt>true</tt> if this set contains no elements
+ */
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ /**
+ * Returns <tt>true</tt> if this set contains the specified element.
+ * More formally, returns <tt>true</tt> if and only if this set
+ * contains an element <tt>e</tt> such that
+ * <tt>(o==null ? e==null : o.equals(e))</tt>.
+ *
+ * @param o element whose presence in this set is to be tested
+ * @return <tt>true</tt> if this set contains the specified element
+ * @throws ClassCastException if the type of the specified element
+ * is incompatible with this set
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified element is null and this
+ * set does not permit null elements
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ */
+ @Override
+ public boolean contains(Object o) {
+ return delegate.contains(new ElementWrapper((E)o));
+ }
+
+ /**
+ * Returns an iterator over the elements in this set. The elements are
+ * returned in no particular order (unless this set is an instance of some
+ * class that provides a guarantee).
+ *
+ * @return an iterator over the elements in this set
+ */
+ @Override
+ public Iterator<E> iterator() {
+ return Iterators.transform(delegate.iterator(), new UnwrapFunction());
+ }
+
+ /**
+ * Returns an array containing all of the elements in this set.
+ * If this set makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the
+ * elements in the same order.
+ * <p/>
+ * <p>The returned array will be "safe" in that no references to it
+ * are maintained by this set. (In other words, this method must
+ * allocate a new array even if this set is backed by an array).
+ * The caller is thus free to modify the returned array.
+ * <p/>
+ * <p>This method acts as bridge between array-based and collection-based
+ * APIs.
+ *
+ * @return an array containing all the elements in this set
+ */
+ @Override
+ public Object[] toArray() {
+ return Iterators.toArray(this.iterator(), Object.class);
+ }
+
+ /**
+ * Returns an array containing all of the elements in this set; the
+ * runtime type of the returned array is that of the specified array.
+ * If the set fits in the specified array, it is returned therein.
+ * Otherwise, a new array is allocated with the runtime type of the
+ * specified array and the size of this set.
+ * <p/>
+ * <p>If this set fits in the specified array with room to spare
+ * (i.e., the array has more elements than this set), the element in
+ * the array immediately following the end of the set is set to
+ * <tt>null</tt>. (This is useful in determining the length of this
+ * set <i>only</i> if the caller knows that this set does not contain
+ * any null elements.)
+ * <p/>
+ * <p>If this set makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the elements
+ * in the same order.
+ * <p/>
+ * <p>Like the {@link #toArray()} method, this method acts as bridge between
+ * array-based and collection-based APIs. Further, this method allows
+ * precise control over the runtime type of the output array, and may,
+ * under certain circumstances, be used to save allocation costs.
+ * <p/>
+ * <p>Suppose <tt>x</tt> is a set known to contain only strings.
+ * The following code can be used to dump the set into a newly allocated
+ * array of <tt>String</tt>:
+ * <p/>
+ * <pre>
+ * String[] y = x.toArray(new String[0]);</pre>
+ *
+ * Note that <tt>toArray(new Object[0])</tt> is identical in function to
+ * <tt>toArray()</tt>.
+ *
+ * @param a the array into which the elements of this set are to be
+ * stored, if it is big enough; otherwise, a new array of the same
+ * runtime type is allocated for this purpose.
+ * @return an array containing all the elements in this set
+ * @throws ArrayStoreException if the runtime type of the specified array
+ * is not a supertype of the runtime type of every element in this
+ * set
+ * @throws NullPointerException if the specified array is null
+ */
+ @Override
+ public <T> T[] toArray(T[] a) {
+ // stolen from AbstractCollection
+
+ // Estimate size of array; be prepared to see more or fewer elements
+ int size = size();
+ T[] r = a.length >= size ? a :
+ (T[])java.lang.reflect.Array
+ .newInstance(a.getClass().getComponentType(), size);
+ Iterator<E> it = iterator();
+
+ for (int i = 0; i < r.length; i++) {
+ if (! it.hasNext()) { // fewer elements than expected
+ if (a != r)
+ return Arrays.copyOf(r, i);
+ r[i] = null; // null-terminate
+ return r;
+ }
+ r[i] = (T)it.next();
+ }
+ return it.hasNext() ? finishToArray(r, it) : r;
+ }
+
+
+ /**
+ * The maximum size of array to allocate.
+ * Some VMs reserve some header words in an array.
+ * Attempts to allocate larger arrays may result in
+ * OutOfMemoryError: Requested array size exceeds VM limit
+ */
+ private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
+
+ /**
+ * Reallocates the array being used within toArray when the iterator
+ * returned more elements than expected, and finishes filling it from
+ * the iterator.
+ *
+ * @param r the array, replete with previously stored elements
+ * @param it the in-progress iterator over this collection
+ * @return array containing the elements in the given array, plus any
+ * further elements returned by the iterator, trimmed to size
+ */
+ private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
+ int i = r.length;
+ while (it.hasNext()) {
+ int cap = r.length;
+ if (i == cap) {
+ int newCap = cap + (cap >> 1) + 1;
+ // overflow-conscious code
+ if (newCap - MAX_ARRAY_SIZE > 0)
+ newCap = hugeCapacity(cap + 1);
+ r = Arrays.copyOf(r, newCap);
+ }
+ r[i++] = (T)it.next();
+ }
+ // trim if overallocated
+ return (i == r.length) ? r : Arrays.copyOf(r, i);
+ }
+
+
+ private static int hugeCapacity(int minCapacity) {
+ if (minCapacity < 0) // overflow
+ throw new OutOfMemoryError
+ ("Required array size too large");
+ return (minCapacity > MAX_ARRAY_SIZE) ?
+ Integer.MAX_VALUE :
+ MAX_ARRAY_SIZE;
+ }
+
+
+ /**
+ * Removes the specified element from this set if it is present
+ * (optional operation). More formally, removes an element <tt>e</tt>
+ * such that
+ * <tt>(o==null ? e==null : o.equals(e))</tt>, if
+ * this set contains such an element. Returns <tt>true</tt> if this set
+ * contained the element (or equivalently, if this set changed as a
+ * result of the call). (This set will not contain the element once the
+ * call returns.)
+ *
+ * @param o object to be removed from this set, if present
+ * @return <tt>true</tt> if this set contained the specified element
+ * @throws ClassCastException if the type of the specified element
+ * is incompatible with this set
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified element is null and this
+ * set does not permit null elements
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws UnsupportedOperationException if the <tt>remove</tt> operation
+ * is not supported by this set
+ */
+ @Override
+ public boolean remove(Object o) {
+ return delegate.remove(new ElementWrapper((E)o));
+ }
+
+ /**
+ * Returns <tt>true</tt> if this set contains all of the elements of the
+ * specified collection. If the specified collection is also a set, this
+ * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
+ *
+ * @param c collection to be checked for containment in this set
+ * @return <tt>true</tt> if this set contains all of the elements of the
+ * specified collection
+ * @throws ClassCastException if the types of one or more elements
+ * in the specified collection are incompatible with this
+ * set
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified collection contains one
+ * or more null elements and this set does not permit null
+ * elements
+ * (<a href="Collection.html#optional-restrictions">optional</a>),
+ * or if the specified collection is null
+ * @see #contains(Object)
+ */
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return delegate.containsAll(Collections2.transform(c,new WrapFunction()));
+ }
+
+ /**
+ * Adds all of the elements in the specified collection to this set if
+ * they're not already present (optional operation). If the specified
+ * collection is also a set, the <tt>addAll</tt> operation effectively
+ * modifies this set so that its value is the <i>union</i> of the two
+ * sets. The behavior of this operation is undefined if the specified
+ * collection is modified while the operation is in progress.
+ *
+ * @param c collection containing elements to be added to this set
+ * @return <tt>true</tt> if this set changed as a result of the call
+ * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
+ * is not supported by this set
+ * @throws ClassCastException if the class of an element of the
+ * specified collection prevents it from being added to this set
+ * @throws NullPointerException if the specified collection contains one
+ * or more null elements and this set does not permit null
+ * elements, or if the specified collection is null
+ * @throws IllegalArgumentException if some property of an element of the
+ * specified collection prevents it from being added to this set
+ * @see #add(Object)
+ */
+ @Override
+ public boolean addAll(Collection<? extends E> c) {
+ return delegate.addAll(Collections2.transform(c, new WrapFunction()));
+ }
+
+ /**
+ * Retains only the elements in this set that are contained in the
+ * specified collection (optional operation). In other words, removes
+ * from this set all of its elements that are not contained in the
+ * specified collection. If the specified collection is also a set, this
+ * operation effectively modifies this set so that its value is the
+ * <i>intersection</i> of the two sets.
+ *
+ * @param c collection containing elements to be retained in this set
+ * @return <tt>true</tt> if this set changed as a result of the call
+ * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
+ * is not supported by this set
+ * @throws ClassCastException if the class of an element of this set
+ * is incompatible with the specified collection
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if this set contains a null element and the
+ * specified collection does not permit null elements
+ * (<a href="Collection.html#optional-restrictions">optional</a>),
+ * or if the specified collection is null
+ * @see #remove(Object)
+ */
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ return delegate.retainAll(Collections2.transform(c, new WrapFunction()));
+ }
+
+ /**
+ * Removes from this set all of its elements that are contained in the
+ * specified collection (optional operation). If the specified
+ * collection is also a set, this operation effectively modifies this
+ * set so that its value is the <i>asymmetric set difference</i> of
+ * the two sets.
+ *
+ * @param c collection containing elements to be removed from this set
+ * @return <tt>true</tt> if this set changed as a result of the call
+ * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
+ * is not supported by this set
+ * @throws ClassCastException if the class of an element of this set
+ * is incompatible with the specified collection
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if this set contains a null element and the
+ * specified collection does not permit null elements
+ * (<a href="Collection.html#optional-restrictions">optional</a>),
+ * or if the specified collection is null
+ * @see #remove(Object)
+ * @see #contains(Object)
+ */
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ return delegate.removeAll(Collections2.transform(c, new WrapFunction()));
+ }
+
+ /**
+ * Removes all of the elements from this set (optional operation).
+ * The set will be empty after this call returns.
+ *
+ * @throws UnsupportedOperationException if the <tt>clear</tt> method
+ * is not supported by this set
+ */
+ @Override
+ public void clear() {
+ delegate.clear();
+ }
+
+ private class ElementWrapper {
+
+ private E delegate;
+
+ private ElementWrapper(E delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if(o instanceof EquivalenceHashSet<?>.ElementWrapper) {
+ return equivalence.equivalent(ElementWrapper.this.delegate, ((ElementWrapper)o).delegate);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return equivalence.hash(delegate);
+ }
+ }
+
+ private class UnwrapFunction implements Function<ElementWrapper, E> {
+ @Override
+ public E apply(ElementWrapper input) {
+ return input.delegate;
+ }
+ }
+
+ private class WrapFunction implements Function<Object,ElementWrapper> {
+ @Override
+ public ElementWrapper apply(Object input) {
+ return new ElementWrapper((E)input);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
index 48b3c5f..5325ea3 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
@@ -1959,8 +1959,9 @@ public class KiWiConnection {
connection.commit();
}
} catch(SQLException ex) {
- if(retry < 10) {
- log.warn("COMMIT: temporary concurrency conflict, retrying in 1000 ms ... (thread={}, retry={})", Thread.currentThread().getName(), retry);
+ // MySQL deadlock, wait and retry
+ if(retry < 10 && ("40001".equals(ex.getSQLState()) || "40P01".equals(ex.getSQLState()))) {
+ log.warn("COMMIT: temporary concurrency conflict (deadlock), retrying in 1000 ms ... (thread={}, retry={})", Thread.currentThread().getName(), retry);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
@@ -1999,7 +2000,10 @@ public class KiWiConnection {
}
}
} catch(SQLException ex) {
- log.error("SQL exception:",ex);
+ // MySQL deadlock state, in this case we retry anyways
+ if(!"40001".equals(ex.getSQLState())) {
+ log.error("SQL exception:",ex);
+ }
throw ex;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
index 29e354a..f9a6fad 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
@@ -98,6 +98,8 @@ public class KiWiPersistence {
private boolean droppedDatabase = false;
+ private boolean initialized = false;
+
// keep track which memory sequences have been updated and need to be written back
private Set<String> sequencesUpdated;
@@ -111,7 +113,9 @@ public class KiWiPersistence {
this.maintenance = false;
this.sequencesLock = new ReentrantLock();
this.sequencesUpdated = new HashSet<>();
+ }
+ public void initialise() {
// init JDBC connection pool
initConnectionPool();
@@ -127,8 +131,12 @@ public class KiWiPersistence {
}
+ //garbageCollector.start();
+
+ initialized = true;
}
+
public KiWiDialect getDialect() {
return configuration.getDialect();
}
@@ -394,6 +402,10 @@ public class KiWiPersistence {
* @throws SQLException in case a new connection could not be established
*/
public KiWiConnection getConnection() throws SQLException {
+ if(!initialized) {
+ throw new SQLException("persistence backend not initialized; call initialise before acquiring a connection");
+ }
+
if(connectionPool != null) {
KiWiConnection con = new KiWiConnection(this,configuration.getDialect(),cacheManager);
if(getDialect().isBatchSupported()) {
@@ -543,9 +555,6 @@ public class KiWiPersistence {
}
- public void initialise() {
- //garbageCollector.start();
- }
public void shutdown() {
if(!droppedDatabase && !configuration.isCommitSequencesOnCommit()) {
@@ -570,6 +579,8 @@ public class KiWiPersistence {
connectionPool = null;
memorySequences = null;
+
+ initialized = false;
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java
index bbb1bfd..1d0c1a0 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java
@@ -596,7 +596,7 @@ public class KiWiSailConnection extends NotifyingSailConnectionBase implements I
throw new IllegalArgumentException("e must not be null");
}
else {
- throw new IllegalArgumentException("Unexpected exception type: " + e.getClass());
+ throw new IllegalArgumentException("Unexpected exception type: " + e.getClass(),e);
}
}
};
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
index d8e3349..4119023 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
@@ -98,7 +98,6 @@ public class KiWiStore extends NotifyingSailBase {
this.tripleLock = new ReentrantLock();
this.inferredContext = inferredContext;
- tripleRegistry = new MapMaker().weakValues().makeMap();
}
@@ -117,9 +116,11 @@ public class KiWiStore extends NotifyingSailBase {
*/
@Override
protected void initializeInternal() throws SailException {
+ tripleRegistry = new MapMaker().weakValues().makeMap();
+
try {
- persistence.initDatabase();
persistence.initialise();
+ persistence.initDatabase();
initialized = true;
} catch (SQLException e) {
@@ -173,6 +174,7 @@ public class KiWiStore extends NotifyingSailBase {
protected void shutDownInternal() throws SailException {
closeValueFactory();
persistence.shutdown();
+ tripleRegistry = null;
initialized = false;
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
index a1ff121..17015c4 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
@@ -390,9 +390,15 @@ public class KiWiValueFactory implements ValueFactory {
*/
private <T> KiWiLiteral createLiteral(T value, String lang, String type) {
commitLock.readLock().lock();
- final Locale locale;
+ Locale locale;
if(lang != null) {
- locale = LocaleUtils.toLocale(lang.replace("-","_"));
+ try {
+ locale = LocaleUtils.toLocale(lang.replace("-","_"));
+ } catch (IllegalArgumentException ex) {
+ log.warn("malformed language literal (language: {})", lang);
+ locale = null;
+ lang = null;
+ }
} else
locale = null;
@@ -420,86 +426,98 @@ public class KiWiValueFactory implements ValueFactory {
final KiWiConnection connection = aqcuireConnection();
try {
-
- // differentiate between the different types of the value
- if (type == null) {
- // FIXME: MARMOTTA-39 (this is to avoid a NullPointerException in the following if-clauses)
- result = connection.loadLiteral(value.toString(), lang, rtype);
-
- if(result == null) {
- result = new KiWiStringLiteral(value.toString(), locale, rtype);
- }
- } else if(value instanceof Date || type.equals(Namespaces.NS_XSD+"dateTime")) {
- // parse if necessary
- final Date dvalue;
- if(value instanceof Date) {
- dvalue = (Date)value;
+ try {
+ // differentiate between the different types of the value
+ if (type == null) {
+ // FIXME: MARMOTTA-39 (this is to avoid a NullPointerException in the following if-clauses)
+ result = connection.loadLiteral(value.toString(), lang, rtype);
+
+ if(result == null) {
+ result = new KiWiStringLiteral(value.toString(), locale, rtype);
+ }
+ } else if(value instanceof Date || type.equals(Namespaces.NS_XSD+"dateTime")) {
+ // parse if necessary
+ final Date dvalue;
+ if(value instanceof Date) {
+ dvalue = (Date)value;
+ } else {
+ dvalue = DateUtils.parseDate(value.toString());
+ }
+
+ result = connection.loadLiteral(dvalue);
+
+ if(result == null) {
+ result= new KiWiDateLiteral(dvalue, rtype);
+ }
+ } else if(Integer.class.equals(value.getClass()) || int.class.equals(value.getClass()) ||
+ Long.class.equals(value.getClass()) || long.class.equals(value.getClass()) ||
+ type.equals(Namespaces.NS_XSD+"integer") || type.equals(Namespaces.NS_XSD+"long")) {
+ long ivalue = 0;
+ if(Integer.class.equals(value.getClass()) || int.class.equals(value.getClass())) {
+ ivalue = (Integer)value;
+ } else if(Long.class.equals(value.getClass()) || long.class.equals(value.getClass())) {
+ ivalue = (Long)value;
+ } else {
+ ivalue = Long.parseLong(value.toString());
+ }
+
+
+ result = connection.loadLiteral(ivalue);
+
+ if(result == null) {
+ result= new KiWiIntLiteral(ivalue, rtype);
+ }
+ } else if(Double.class.equals(value.getClass()) || double.class.equals(value.getClass()) ||
+ Float.class.equals(value.getClass()) || float.class.equals(value.getClass()) ||
+ type.equals(Namespaces.NS_XSD+"double") || type.equals(Namespaces.NS_XSD+"float")) {
+ double dvalue = 0.0;
+ if(Float.class.equals(value.getClass()) || float.class.equals(value.getClass())) {
+ dvalue = (Float)value;
+ } else if(Double.class.equals(value.getClass()) || double.class.equals(value.getClass())) {
+ dvalue = (Double)value;
+ } else {
+ dvalue = Double.parseDouble(value.toString());
+ }
+
+
+ result = connection.loadLiteral(dvalue);
+
+ if(result == null) {
+ result= new KiWiDoubleLiteral(dvalue, rtype);
+ }
+ } else if(Boolean.class.equals(value.getClass()) || boolean.class.equals(value.getClass()) ||
+ type.equals(Namespaces.NS_XSD+"boolean")) {
+ boolean bvalue = false;
+ if(Boolean.class.equals(value.getClass()) || boolean.class.equals(value.getClass())) {
+ bvalue = (Boolean)value;
+ } else {
+ bvalue = Boolean.parseBoolean(value.toString());
+ }
+
+
+ result = connection.loadLiteral(bvalue);
+
+ if(result == null) {
+ result= new KiWiBooleanLiteral(bvalue, rtype);
+ }
} else {
- dvalue = DateUtils.parseDate(value.toString());
- }
-
- result = connection.loadLiteral(dvalue);
+ result = connection.loadLiteral(value.toString(), lang, rtype);
- if(result == null) {
- result= new KiWiDateLiteral(dvalue, rtype);
- }
- } else if(Integer.class.equals(value.getClass()) || int.class.equals(value.getClass()) ||
- Long.class.equals(value.getClass()) || long.class.equals(value.getClass()) ||
- type.equals(Namespaces.NS_XSD+"integer") || type.equals(Namespaces.NS_XSD+"long")) {
- long ivalue = 0;
- if(Integer.class.equals(value.getClass()) || int.class.equals(value.getClass())) {
- ivalue = (Integer)value;
- } else if(Long.class.equals(value.getClass()) || long.class.equals(value.getClass())) {
- ivalue = (Long)value;
- } else {
- ivalue = Long.parseLong(value.toString());
+ if(result == null) {
+ result = new KiWiStringLiteral(value.toString(), locale, rtype);
+ }
}
+ } catch(IllegalArgumentException ex) {
+ // malformed number or date
+ log.warn("malformed argument for typed literal of type {}: {}", rtype.stringValue(), value);
+ KiWiUriResource mytype = (KiWiUriResource)createURI(Namespaces.NS_XSD+"string");
-
- result = connection.loadLiteral(ivalue);
+ result = connection.loadLiteral(value.toString(), lang, mytype);
if(result == null) {
- result= new KiWiIntLiteral(ivalue, rtype);
+ result = new KiWiStringLiteral(value.toString(), locale, mytype);
}
- } else if(Double.class.equals(value.getClass()) || double.class.equals(value.getClass()) ||
- Float.class.equals(value.getClass()) || float.class.equals(value.getClass()) ||
- type.equals(Namespaces.NS_XSD+"double") || type.equals(Namespaces.NS_XSD+"float")) {
- double dvalue = 0.0;
- if(Float.class.equals(value.getClass()) || float.class.equals(value.getClass())) {
- dvalue = (Float)value;
- } else if(Double.class.equals(value.getClass()) || double.class.equals(value.getClass())) {
- dvalue = (Double)value;
- } else {
- dvalue = Double.parseDouble(value.toString());
- }
-
- result = connection.loadLiteral(dvalue);
-
- if(result == null) {
- result= new KiWiDoubleLiteral(dvalue, rtype);
- }
- } else if(Boolean.class.equals(value.getClass()) || boolean.class.equals(value.getClass()) ||
- type.equals(Namespaces.NS_XSD+"boolean")) {
- boolean bvalue = false;
- if(Boolean.class.equals(value.getClass()) || boolean.class.equals(value.getClass())) {
- bvalue = (Boolean)value;
- } else {
- bvalue = Boolean.parseBoolean(value.toString());
- }
-
-
- result = connection.loadLiteral(bvalue);
-
- if(result == null) {
- result= new KiWiBooleanLiteral(bvalue, rtype);
- }
- } else {
- result = connection.loadLiteral(value.toString(), lang, rtype);
-
- if(result == null) {
- result = new KiWiStringLiteral(value.toString(), locale, rtype);
- }
}
if(result.getId() == null) {
@@ -515,6 +533,7 @@ public class KiWiValueFactory implements ValueFactory {
return result;
+
} catch (SQLException e) {
log.error("database error, could not load literal",e);
throw new IllegalStateException("database error, could not load literal",e);
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
index e390feb..566b470 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
@@ -79,6 +79,7 @@ public class PersistenceTest {
@Before
public void initDatabase() throws SQLException {
persistence = new KiWiPersistence(kiwiConfig);
+ persistence.initialise();
persistence.initDatabase();
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/libraries/kiwi/kiwi-tripletable/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-tripletable/pom.xml b/libraries/kiwi/kiwi-tripletable/pom.xml
index 845c4c2..9f98878 100644
--- a/libraries/kiwi/kiwi-tripletable/pom.xml
+++ b/libraries/kiwi/kiwi-tripletable/pom.xml
@@ -46,6 +46,10 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>marmotta-commons</artifactId>
+ </dependency>
<dependency>
<artifactId>junit</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/117187d8/libraries/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/TripleTable.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/TripleTable.java b/libraries/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/TripleTable.java
index 0d9736b..93b2f03 100644
--- a/libraries/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/TripleTable.java
+++ b/libraries/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/TripleTable.java
@@ -17,11 +17,10 @@
*/
package org.apache.marmotta.kiwi.model.caching;
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
-import com.google.common.collect.Iterators;
+import org.apache.marmotta.commons.collections.EquivalenceHashSet;
+import org.apache.marmotta.commons.sesame.model.StatementCommons;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
@@ -40,7 +39,7 @@ public class TripleTable<Triple extends Statement> implements Set<Triple>, Seria
private static final long serialVersionUID = 1L;
- private Set<StatementWrapper> data;
+ private Set<Triple> data;
/**
* A set that orders triples orderd in a way that the subject is the most significant, while the context is the
@@ -57,14 +56,14 @@ public class TripleTable<Triple extends Statement> implements Set<Triple>, Seria
private NavigableMap<IntArray,Triple> indexCSPO;
public TripleTable() {
- data = new HashSet<StatementWrapper>();
+ data = new EquivalenceHashSet<Triple>(StatementCommons.quadrupleEquivalence());
indexSPOC = new TreeMap<IntArray, Triple>();
indexCSPO = new TreeMap<IntArray, Triple>();
}
public TripleTable(Collection<Triple> triples) {
- data = new HashSet<StatementWrapper>(triples.size());
+ data = new EquivalenceHashSet<Triple>(StatementCommons.quadrupleEquivalence());
indexSPOC = new TreeMap<IntArray, Triple>();
indexCSPO = new TreeMap<IntArray, Triple>();
addAll(triples);
@@ -120,7 +119,7 @@ public class TripleTable<Triple extends Statement> implements Set<Triple>, Seria
*/
@Override
public Iterator<Triple> iterator() {
- return Iterators.transform(data.iterator(), new UnwrapperFunction());
+ return data.iterator();
}
/**
@@ -225,7 +224,7 @@ public class TripleTable<Triple extends Statement> implements Set<Triple>, Seria
public synchronized boolean add(Triple triple) {
indexSPOC.put(IntArray.createSPOCKey(triple.getSubject(), triple.getPredicate(), triple.getObject(), triple.getContext()),triple);
indexCSPO.put(IntArray.createCSPOKey(triple.getSubject(), triple.getPredicate(), triple.getObject(), triple.getContext()),triple);
- return data.add(new StatementWrapper(triple));
+ return data.add(triple);
}
/**
@@ -442,14 +441,14 @@ public class TripleTable<Triple extends Statement> implements Set<Triple>, Seria
}
};
- return Collections2.filter(Collections2.transform(data, new UnwrapperFunction()), p);
+ return Collections2.filter(data, p);
}
}
public synchronized Collection<Resource> listContextIDs() {
Set<Resource> result = new HashSet<>();
- for(StatementWrapper stmt : data) {
- result.add(stmt.delegate.getContext());
+ for(Triple t : data) {
+ result.add(t.getContext());
}
return result;
}
@@ -473,47 +472,4 @@ public class TripleTable<Triple extends Statement> implements Set<Triple>, Seria
}
- private class StatementWrapper {
- Triple delegate;
-
- private StatementWrapper(Triple delegate) {
- this.delegate = delegate;
- }
-
- private Triple getDelegate() {
- return delegate;
- }
-
-
- @Override
- public int hashCode() {
- return Objects.hashCode(delegate,delegate.getContext());
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
-
- Statement triple = ((StatementWrapper)o).delegate;
- if (!Objects.equal(delegate.getContext(), triple.getContext())) return false;
- if (!Objects.equal(delegate.getObject(),triple.getObject())) return false;
- if (!Objects.equal(delegate.getPredicate(),triple.getPredicate())) return false;
- return Objects.equal(delegate.getSubject(),triple.getSubject());
- }
- }
-
-
- private class WrapperFunction implements Function<Triple, StatementWrapper> {
- @Override
- public StatementWrapper apply(Triple input) {
- return new StatementWrapper(input);
- }
- }
-
- private class UnwrapperFunction implements Function<StatementWrapper, Triple> {
- @Override
- public Triple apply(StatementWrapper input) {
- return input.delegate;
- }
- }
}
[2/2] git commit: Merge branch 'develop' of
https://git-wip-us.apache.org/repos/asf/incubator-marmotta into develop
Posted by ss...@apache.org.
Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/incubator-marmotta into develop
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/8a2fe2be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/8a2fe2be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/8a2fe2be
Branch: refs/heads/develop
Commit: 8a2fe2bec9c4ef63fb582110e2c36800412802b0
Parents: 117187d 7330202
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Wed Sep 4 12:06:06 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Wed Sep 4 12:06:06 2013 +0200
----------------------------------------------------------------------
.../marmotta/commons/http/ETagGenerator.java | 24 +++++--
.../platform/core/rio/RDFHtmlWriterImpl.java | 67 ++++++++++++--------
.../webservices/resource/MetaWebService.java | 59 ++++++++++-------
.../resource/ResourceWebService.java | 55 ++++++++++------
.../resource/ResourceWebServiceHelper.java | 34 +++++-----
.../src/main/resources/templates/rdfhtml.ftl | 51 +++++++++++----
.../sparqlhtml/SPARQLResultsHTMLWriter.java | 4 +-
7 files changed, 188 insertions(+), 106 deletions(-)
----------------------------------------------------------------------