Updated Branches: refs/heads/develop 1c4b4a5c8 -> e43574efa
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamWriter.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamWriter.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamWriter.java new file mode 100644 index 0000000..4c0770d --- /dev/null +++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamWriter.java @@ -0,0 +1,365 @@ +/* + * Javolution - Java(TM) Solution for Real-Time and Embedded Systems + * Copyright (C) 2012 - Javolution (http://javolution.org/) + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software is + * freely granted, provided that this notice is preserved. + */ +package javolution.xml.stream; + +import java.lang.CharSequence; + +/** + * <p> This interface is similar to + * <code>javax.xml.stream.XMLStreamWriter</code>; but it does not forces + * dynamic allocation when formatting (any {@link CharSequence CharSequence} + * can be used instead of {@link String}).</p> + * + * <p> Except for the speed (faster) and the added flexibility, the + * usage/behavior is about the same as its StAX counterpart.</p> + * + * <p> This writer does not require creating new <code>String</code> objects + * during XML formatting. Attributes values can be held by a single/reusable + * {@link javolution.text.TextBuilder TextBuilder} + * (or <code>StringBuilder</code>) instance to avoid adverse effects + * on memory footprint (heap), garbage collection and performance. + * [code] + * // Creates a new writer (potentially recycled). + * XMLOutputFactory factory = OSGiServices.getXMLOutputFactory(); + * XMLStreamWriter writer = factory.createXMLStreamWriter(outputStream); + * + * TextBuilder tmp = new TextBuilder(); // To avoid creating new String instances. + * writer.writeStartDocument(); + * writer.writeStartElement("Time"); + * writer.writeAttribute("hour", tmp.clear().append(time.hour); + * writer.writeAttribute("minute", tmp.clear().append(time.minute); + * writer.writeAttribute("second", tmp.clear().append(time.second); + * writer.writeEndElement(); + * writer.writeStartDocument(); + * + * writer.close(); // Closes the writer (does not close underlying output stream). + * [/code]</p> + * + * @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a> + * @version 6.0 December 12, 2012 + */ +public interface XMLStreamWriter { + + /** + * Writes a start tag to the output. All writeStartElement methods open a + * new scope in the internal namespace context. Writing the corresponding + * EndElement causes the scope to be closed. + * + * @param localName local name of the tag. + * @throws XMLStreamException + */ + void writeStartElement(CharSequence localName) + throws XMLStreamException; + + /** + * Writes a start tag to the output. + * + * @param namespaceURI the namespaceURI of the prefix to use. + * @param localName local name of the tag. + * @throws XMLStreamException if the namespace URI has not been bound + * to a prefix and this writer does not {@link + * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}. + */ + void writeStartElement(CharSequence namespaceURI, + CharSequence localName) throws XMLStreamException; + + /** + * Writes a start tag to the output. + * + * @param localName local name of the tag. + * @param prefix the prefix of the tag. + * @param namespaceURI the uri to bind the prefix to. + * @throws XMLStreamException if the namespace URI has not been bound + * to a prefix and this writer does not {@link + * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}. + */ + void writeStartElement(CharSequence prefix, CharSequence localName, + CharSequence namespaceURI) throws XMLStreamException; + + /** + * Writes an empty element tag to the output. + * + * @param namespaceURI the uri to bind the tag to. + * @param localName local name of the tag. + * @throws XMLStreamException if the namespace URI has not been bound + * to a prefix and this writer does not {@link + * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}. + */ + void writeEmptyElement(CharSequence namespaceURI, + CharSequence localName) throws XMLStreamException; + + /** + * Writes an empty element tag to the output. + * + * @param prefix the prefix of the tag. + * @param localName local name of the tag. + * @param namespaceURI the uri to bind the tag to. + * @throws XMLStreamException if the namespace URI has not been bound + * to a prefix and this writer does not {@link + * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}. + */ + void writeEmptyElement(CharSequence prefix, CharSequence localName, + CharSequence namespaceURI) throws XMLStreamException; + + /** + * Writes an empty element tag to the output. + * + * @param localName local name of the tag. + * @throws XMLStreamException + */ + void writeEmptyElement(CharSequence localName) + throws XMLStreamException; + + /** + * Writes an end tag to the output relying on the internal state of the + * writer to determine the prefix and local name of the event. + * + * @throws XMLStreamException + */ + void writeEndElement() throws XMLStreamException; + + /** + * Closes any start tags and writes corresponding end tags. + * + * @throws XMLStreamException + */ + void writeEndDocument() throws XMLStreamException; + + /** + * Close this writer and free any resources associated with the writer. This + * must not close the underlying output stream. + * + * @throws XMLStreamException + */ + void close() throws XMLStreamException; + + /** + * Write any cached data to the underlying output mechanism. + * + * @throws XMLStreamException + */ + void flush() throws XMLStreamException; + + /** + * Writes an attribute to the output stream without a prefix. + * + * @param localName the local name of the attribute. + * @param value the value of the attribute. + * @throws IllegalStateException if the current state does not allow + * attribute writing. + * @throws XMLStreamException + */ + void writeAttribute(CharSequence localName, CharSequence value) + throws XMLStreamException; + + /** + * Writes an attribute to the output stream. + * + * @param prefix the prefix for this attribute. + * @param namespaceURI the uri of the prefix for this attribute + * @param localName the local name of the attribute. + * @param value the value of the attribute. + * @throws IllegalStateException if the current state does not allow + * attribute writing. + * @throws XMLStreamException if the namespace URI has not been bound + * to a prefix and this writer does not {@link + * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}. + */ + + void writeAttribute(CharSequence prefix, CharSequence namespaceURI, + CharSequence localName, CharSequence value) + throws XMLStreamException; + + /** + * Writes an attribute to the output stream. + * + * @param namespaceURI the uri of the prefix for this attribute. + * @param localName the local name of the attribute. + * @param value the value of the attribute. + * @throws IllegalStateException if the current state does not allow + * attribute writing. + * @throws XMLStreamException if the namespace URI has not been bound + * to a prefix and this writer does not {@link + * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}. + */ + void writeAttribute(CharSequence namespaceURI, + CharSequence localName, CharSequence value) + throws XMLStreamException; + + /** + * Writes a namespace to the output stream. If the prefix argument to this + * method is the empty string, "xmlns", or <code>null</code> this method + * will delegate to writeDefaultNamespace. + * + * @param prefix the prefix to bind this namespace to or <code>null</code> + * @param namespaceURI the uri to bind the prefix. + * @throws IllegalStateException if the current state does not allow + * namespace writing. + * @throws XMLStreamException + */ + void writeNamespace(CharSequence prefix, CharSequence namespaceURI) + throws XMLStreamException; + + /** + * Writes the default namespace to the stream. + * + * @param namespaceURI the uri to bind the default namespace to or + * <code>null</code> (to map the prefix to <code>""</code> URI) + * @throws IllegalStateException if the current state does not allow + * namespace writing. + * @throws XMLStreamException + */ + void writeDefaultNamespace(CharSequence namespaceURI) + throws XMLStreamException; + + /** + * Writes an xml comment with the data enclosed. + * + * @param data the data contained in the comment or <code>null</code> + * @throws XMLStreamException + */ + void writeComment(CharSequence data) throws XMLStreamException; + + /** + * Writes a processing instruction. + * + * @param target the target of the processing instruction. + * @throws XMLStreamException + */ + void writeProcessingInstruction(CharSequence target) + throws XMLStreamException; + + /** + * Writes a processing instruction + * + * @param target the target of the processing instruction. + * @param data the data contained in the processing instruction. + * @throws XMLStreamException + */ + void writeProcessingInstruction(CharSequence target, + CharSequence data) throws XMLStreamException; + + /** + * Writes a CData section. + * + * @param data the data contained in the CData Section. + * @throws XMLStreamException + */ + void writeCData(CharSequence data) throws XMLStreamException; + + /** + * Writes a DTD section (representing the entire doctypedecl + * production from the XML 1.0 specification). + * + * @param dtd the DTD to be written. + * @throws XMLStreamException + */ + void writeDTD(CharSequence dtd) throws XMLStreamException; + + /** + * Writes an entity reference + * + * @param name the name of the entity. + * @throws XMLStreamException + */ + void writeEntityRef(CharSequence name) throws XMLStreamException; + + /** + * Writes the XML Declaration. Defaults the XML version to 1.0 and the + * encoding (if any) to the one specified when the instance is created + * using {@link XMLOutputFactory}. + * + * @throws XMLStreamException + */ + void writeStartDocument() throws XMLStreamException; + + /** + * Writes the XML Declaration. Default the encoding (if any) to the one + * specified when the instance is created using {@link XMLOutputFactory}. + * + * @param version the version of the xml document or <code>null</code>. + * @throws XMLStreamException + */ + void writeStartDocument(CharSequence version) + throws XMLStreamException; + + /** + * Writes the XML Declaration. Note that the encoding parameter does not set + * the actual encoding of the underlying output. That must be set when the + * instance when the instance is created using {@link XMLOutputFactory}. + * + * @param encoding the encoding of the xml declaration or <code>null</code>. + * @param version the version of the xml document or <code>null</code>. + * @throws XMLStreamException + */ + void writeStartDocument(CharSequence encoding, CharSequence version) + throws XMLStreamException; + + /** + * Writes text to the output. + * + * @param text the value to write or <code>null</code>. + * @throws XMLStreamException + */ + void writeCharacters(CharSequence text) throws XMLStreamException; + + /** + * Writes text to the output. + * + * @param text the value to write + * @param start the starting position in the array. + * @param length the number of characters to write. + * @throws XMLStreamException + */ + void writeCharacters(char[] text, int start, int length) + throws XMLStreamException; + + /** + * Gets the prefix the specified uri is bound to. + * + * @param uri namespace URI + * @return the prefix for the URI or <code>null</code> + * @throws XMLStreamException + */ + CharSequence getPrefix(CharSequence uri) throws XMLStreamException; + + /** + * Sets the prefix the uri is bound to. This prefix is bound in the scope of + * the current START_ELEMENT / END_ELEMENT pair. If this method is called + * before a START_ELEMENT has been written the prefix is bound in the root + * scope. + * + * @param prefix the prefix to bind to the uri. + * @param uri the uri to bind to the prefix or <code>null</code> + * @throws XMLStreamException + */ + void setPrefix(CharSequence prefix, CharSequence uri) + throws XMLStreamException; + + /** + * Binds a URI to the default namespace. This URI is bound in the scope of + * the current START_ELEMENT / END_ELEMENT pair. If this method is called + * before a START_ELEMENT has been written the uri is bound in the root + * scope. + * + * @param uri the uri to bind to the default namespace or <code>null</code>. + * @throws XMLStreamException + */ + void setDefaultNamespace(CharSequence uri) throws XMLStreamException; + + /** + * Gets the value of a feature/property from the underlying implementation. + * + * @param name the name of the property. + * @return the value of the property. + * @throws IllegalArgumentException if the property is not supported. + */ + Object getProperty(String name) throws IllegalArgumentException; + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/package-info.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/package-info.java new file mode 100644 index 0000000..7e0d279 --- /dev/null +++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/package-info.java @@ -0,0 +1,17 @@ +/** +<p> StAX-like XML readers/writers which do not require object + creation (such as String) and are consequently faster than standard StAX.</p> +<p> The main difference with "javax.xml.stream.*" classes is the integration with + OSGi to retrieve {@code XMLInputFactory/XMLOutputFactory} instances and the use + of <code>CharSequence</code> instead of <code>String</code>. Since + <code>String</code> is a <code>CharSequence</code> (JDK 1.4+), most + existing StAX code requires very little modification to be used with these + new classes.</p> +<p> For more information about the usage of this package please read the + documentation for the {@link javolution.xml.stream.XMLStreamReader} and + {@link javolution.xml.stream.XMLStreamWriter} interfaces.</p> +<p> For more information about StAX (Streaming API for XML) in general see + <a href="http://en.wikipedia.org/wiki/StAX">Wikipedia: StAX</a></p> + */ +package javolution.xml.stream; + http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/ws/WebServiceClient.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/ws/WebServiceClient.java b/commons/marmotta-commons/src/ext/java/javolution/xml/ws/WebServiceClient.java new file mode 100644 index 0000000..d960cdf --- /dev/null +++ b/commons/marmotta-commons/src/ext/java/javolution/xml/ws/WebServiceClient.java @@ -0,0 +1,223 @@ +/* + * Javolution - Java(TM) Solution for Real-Time and Embedded Systems + * Copyright (C) 2012 - Javolution (http://javolution.org/) + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software is + * freely granted, provided that this notice is preserved. + */ +package javolution.xml.ws; + +import java.io.IOException; +import javolution.io.AppendableWriter; +import javolution.io.UTF8StreamWriter; +import javolution.text.Text; +import javolution.text.TextBuilder; +import javolution.xml.XMLObjectReader; +import javolution.xml.XMLObjectWriter; +import javolution.xml.stream.XMLStreamException; +import javolution.xml.stream.XMLStreamReader; +import javolution.xml.stream.XMLStreamWriter; + +/** + * <p> This class provides a simple web service client capable of leveraging + * Javolution XML marshalling/unmarshalling.</p> + * + * <p> Sub-classes may work from WSDL files, {@link javolution.xml.XMLFormat + * XMLFormat} or directly with the XML streams (StAX). For example:[code] + * private static class HelloWorld extends WebServiceClient { + * protected void writeRequest(XMLObjectWriter out) throws XMLStreamException { + * XMLStreamWriter xml = out.getStreamWriter(); + * xml.writeDefaultNamespace("http://www.openuri.org/"); + * xml.writeEmptyElement("helloWorld"); // Operation name. + * } + * protected void readResponse(XMLObjectReader in) throws XMLStreamException { + * XMLStreamReader xml = in.getStreamReader(); + * xml.require(START_ELEMENT, "http://www.openuri.org/", "string"); + * xml.next(); // Move to character content. + * System.out.println(xml.getText()); + * } + * } + * WebServiceClient ws = new HelloWorld().setAddress("http://acme.com:80/HelloWorld.jws"); + * ws.invoke(); + * + * > Hello World! + * [/code]</p> + * + * @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a> + * @version 5.2, September 16, 2007 + */ +public abstract class WebServiceClient { + + /** + * Holds standard SOAP envelope prefix. + */ + public static final String ENVELOPE_PREFIX = "env"; + + /** + * Holds standard SOAP envelope namespace. + */ + public static final String ENVELOPE_URI = "http://schemas.xmlsoap.org/soap/envelope/"; + + /** + * Holds the URL (J2SE). + */ + Object _url; + + /** + * Default constructor (address not set). + */ + public WebServiceClient() {} + + /** + * Sets the address of this web service. + * + * @param address the service full address. + */ + public WebServiceClient setAddress(String address) { + try { + _url = new java.net.URL(address); + } catch (java.net.MalformedURLException e) { + throw new IllegalArgumentException("Malformed URL: " + address); + } + return this; + } + + /** + * Invokes the web service. + */ + public void invoke() throws IOException, XMLStreamException { + try { + // Formats the request message (we cannot write directly to + // the output stream because the http request requires the length. + _out.setOutput(_buffer); + _writer.setOutput(_out); + final XMLStreamWriter xmlOut = _writer.getStreamWriter(); + xmlOut.setPrefix(csq(ENVELOPE_PREFIX), csq(ENVELOPE_URI)); + xmlOut.writeStartElement(csq(ENVELOPE_URI), csq("Envelope")); + xmlOut.writeNamespace(csq(ENVELOPE_PREFIX), csq(ENVELOPE_URI)); + xmlOut.writeStartElement(csq(ENVELOPE_URI), csq("Header")); + xmlOut.writeEndElement(); + xmlOut.writeStartElement(csq(ENVELOPE_URI), csq("Body")); + writeRequest(_writer); + _writer.close(); + + // Sends the request. + if (_url == null) + throw new IOException("URL not set"); + /**/ + java.net.HttpURLConnection http = (java.net.HttpURLConnection) ((java.net.URL) _url) + .openConnection(); + http.setRequestProperty("Content-Length", + String.valueOf(_buffer.length())); + http.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); + // httpConn.setRequestProperty("SOAPAction", ""); + http.setRequestMethod("POST"); + http.setDoOutput(true); + http.setDoInput(true); + _utf8Writer.setOutput(http.getOutputStream()); + /**/ + _utf8Writer.append(_buffer); + _utf8Writer.close(); + + // Reads the response. + /**/ + _reader.setInput(http.getInputStream()); + /**/ + final XMLStreamReader xmlIn = _reader.getStreamReader(); + while (xmlIn.hasNext()) { + if ((xmlIn.next() == XMLStreamReader.START_ELEMENT) + && xmlIn.getLocalName().equals("Body") + && xmlIn.getNamespaceURI().equals(ENVELOPE_URI)) { + // Found body, position reader to next element. + xmlIn.next(); + readResponse(_reader); + break; + } + } + + } finally { + _reader.close(); + _writer.reset(); + _out.reset(); + _buffer.clear(); + _utf8Writer.reset(); + _reader.reset(); + } + } + + private final TextBuilder _buffer = new TextBuilder(); + private final AppendableWriter _out = new AppendableWriter(); + private final XMLObjectWriter _writer = new XMLObjectWriter(); + private final UTF8StreamWriter _utf8Writer = new UTF8StreamWriter(); + private final XMLObjectReader _reader = new XMLObjectReader(); + + /**/ + + /** + * Writes the web service request (SOAP body). + * + * @param out the XML object writer. + */ + protected abstract void writeRequest(XMLObjectWriter out) + throws XMLStreamException; + + /** + * Reads the web service response (SOAP body). The default implementation + * writes the body XML events to <code>System.out</code>. + * + * @param in the XML object reader. + */ + protected void readResponse(XMLObjectReader in) throws XMLStreamException { + final XMLStreamReader xml = in.getStreamReader(); + while (xml.hasNext()) { + switch (xml.next()) { + case XMLStreamReader.START_DOCUMENT: + System.out.println("Start Document"); + break; + case XMLStreamReader.END_DOCUMENT: + System.out.println("End Document."); + break; + case XMLStreamReader.START_ELEMENT: + System.out.println("Start Element: " + xml.getLocalName() + + "(" + xml.getNamespaceURI() + ")"); + for (int i = 0, n = xml.getAttributeCount(); i < n; i++) { + System.out.println(" Attribute: " + + xml.getAttributeLocalName(i) + "(" + + xml.getAttributeNamespace(i) + "), Value: " + + xml.getAttributeValue(i)); + } + break; + case XMLStreamReader.END_ELEMENT: + if (xml.getLocalName().equals("Body") + && xml.getNamespaceURI().equals(ENVELOPE_URI)) + return; // End body. + System.out.println("End Element: " + xml.getLocalName() + + "(" + xml.getNamespaceURI() + ")"); + break; + case XMLStreamReader.CHARACTERS: + System.out.println("Characters: " + xml.getText()); + break; + case XMLStreamReader.CDATA: + System.out.println("CDATA: " + xml.getText()); + break; + case XMLStreamReader.COMMENT: + System.out.println("Comment: " + xml.getText()); + break; + case XMLStreamReader.SPACE: + System.out.println("Space"); + break; + default: + System.out.println(xml); + } + } + + } + + // For J2ME compatiblity. + private static final CharSequence csq(Object string) { + return (string instanceof CharSequence) ? (CharSequence) string : Text + .valueOf(string); + + } +} http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/ws/package-info.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/ws/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/xml/ws/package-info.java new file mode 100644 index 0000000..0eef27c --- /dev/null +++ b/commons/marmotta-commons/src/ext/java/javolution/xml/ws/package-info.java @@ -0,0 +1,5 @@ +/** +<p> Classes and interfaces to create and handle web services.</p> + */ +package javolution.xml.ws; + http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java index 41e68e4..c04e7be 100644 --- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java +++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java @@ -19,8 +19,16 @@ package org.apache.marmotta.commons.sesame.model; import com.google.common.base.Equivalence; import com.google.common.base.Objects; +import javolution.util.FastMap; +import javolution.util.FastSet; +import javolution.util.function.Equality; +import org.apache.marmotta.commons.collections.EquivalenceHashMap; +import org.apache.marmotta.commons.collections.EquivalenceHashSet; import org.openrdf.model.Statement; +import java.util.Map; +import java.util.Set; + /** * Provide some utility functions for managing statements (e.g. different forms of equivalence) * @@ -28,74 +36,155 @@ import org.openrdf.model.Statement; */ public class StatementCommons { + private final static Equivalence<Statement> TRIPLE_EQUIVALENCE = new Equivalence<Statement>() { + @Override + protected boolean doEquivalent(Statement a, Statement b) { + if(a == b) return true; + + if(!Objects.equal(a.getSubject(), b.getSubject())) return false; + if(!Objects.equal(a.getPredicate(), b.getPredicate())) return false; + if(!Objects.equal(a.getObject(), b.getObject())) return false; + return true; + } + + @Override + protected int doHash(Statement statement) { + return Objects.hashCode(statement.getSubject(), statement.getPredicate(), statement.getObject()); + } + + @Override + public boolean equals(Object obj) { + return this.getClass().equals(obj.getClass()); + } + + @Override + public int hashCode() { + return this.getClass().hashCode(); + } + }; + + + private final static Equivalence<Statement> QUADRUPLE_EQUIVALENCE = new Equivalence<Statement>() { + @Override + protected boolean doEquivalent(Statement a, Statement b) { + if(a == b) return true; + + if(!Objects.equal(a.getSubject(), b.getSubject())) return false; + if(!Objects.equal(a.getPredicate(), b.getPredicate())) return false; + if(!Objects.equal(a.getObject(), b.getObject())) return false; + if(!Objects.equal(a.getContext(), b.getContext())) return false; + return true; + } + + @Override + protected int doHash(Statement statement) { + return Objects.hashCode(statement.getSubject(), statement.getPredicate(), statement.getObject(), statement.getContext()); + } + + @Override + public boolean equals(Object obj) { + return this.getClass().equals(obj.getClass()); + } + + @Override + public int hashCode() { + return this.getClass().hashCode(); + } + }; + /** * Return triple equivalence, taking only into account subject, predicate and object * * @return */ public static Equivalence<Statement> tripleEquivalence() { - return new Equivalence<Statement>() { - @Override - protected boolean doEquivalent(Statement a, Statement b) { - if(a == b) return true; + return TRIPLE_EQUIVALENCE; + } - if(!Objects.equal(a.getSubject(), b.getSubject())) return false; - if(!Objects.equal(a.getPredicate(), b.getPredicate())) return false; - if(!Objects.equal(a.getObject(), b.getObject())) return false; - return true; - } + /** + * Return quadruple equivalence, taking into account subject, predicate, object, and context. + * + * @return + */ + public static Equivalence<Statement> quadrupleEquivalence() { + return QUADRUPLE_EQUIVALENCE; - @Override - protected int doHash(Statement statement) { - return Objects.hashCode(statement.getSubject(), statement.getPredicate(), statement.getObject()); - } + } - @Override - public boolean equals(Object obj) { - return this.getClass().equals(obj.getClass()); - } + /** + * Create a new set for statements using the triple equivalence (based on subject, predicate, object only) + * @param <T> + * @return + */ + public static <T extends Statement> Set<T> newTripleSet() { + //return new EquivalenceHashSet<>(tripleEquivalence()); + return new FastSet<>(equivalenceEquality(tripleEquivalence())); + } - @Override - public int hashCode() { - return this.getClass().hashCode(); - } - }; + /** + * Create a new set for statements using the triple equivalence (based on subject, predicate, object and context) + * @param <T> + * @return + */ + public static <T extends Statement> Set<T> newQuadrupleSet() { + //return new EquivalenceHashSet<>(quadrupleEquivalence()); + return new FastSet<>(equivalenceEquality(quadrupleEquivalence())); } /** - * Return quadruple equivalence, taking into account subject, predicate, object, and context. + * Create a new map where the keys are statements and the equivalence relation used for keys is triple + * equivalence (based on subject, predicate, object only) * + * @param <K> + * @param <V> * @return */ - public static Equivalence<Statement> quadrupleEquivalence() { - return new Equivalence<Statement>() { + public static <K extends Statement, V> Map<K,V> newTripleMap() { + //return new EquivalenceHashMap<>(tripleEquivalence()); + return new FastMap<>(equivalenceEquality(tripleEquivalence())); + } + + /** + * Create a new map where the keys are statements and the equivalence relation used for keys is triple + * equivalence (based on subject, predicate, object only) + * + * @param <K> + * @param <V> + * @return + */ + public static <K extends Statement, V> Map<K,V> newQuadrupleMap() { + //return new EquivalenceHashMap<>(quadrupleEquivalence()); + return new FastMap<>(equivalenceEquality(quadrupleEquivalence())); + } + + + + private static <E> Equality<E> equivalenceEquality(final Equivalence<E> equivalence) { + return new Equality<E>() { @Override - protected boolean doEquivalent(Statement a, Statement b) { - if(a == b) return true; - - if(!Objects.equal(a.getSubject(), b.getSubject())) return false; - if(!Objects.equal(a.getPredicate(), b.getPredicate())) return false; - if(!Objects.equal(a.getObject(), b.getObject())) return false; - if(!Objects.equal(a.getContext(), b.getContext())) return false; - return true; + public int hashCodeOf(E object) { + return equivalence.hash(object); } @Override - protected int doHash(Statement statement) { - return Objects.hashCode(statement.getSubject(), statement.getPredicate(), statement.getObject(), statement.getContext()); + public boolean areEqual(E left, E right) { + return equivalence.equivalent(left, right); } @Override - public boolean equals(Object obj) { - return this.getClass().equals(obj.getClass()); + public int compare(E left, E right) { + return equivalence.hash(left) - equivalence.hash(right); } @Override public int hashCode() { - return this.getClass().hashCode(); + return equivalence.hashCode(); } - }; + @Override + public boolean equals(Object obj) { + return obj.hashCode() == hashCode(); + } + }; } - } http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/collections/EquivalenceHashSet2Test.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/collections/EquivalenceHashSet2Test.java b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/collections/EquivalenceHashSet2Test.java new file mode 100644 index 0000000..185b0be --- /dev/null +++ b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/collections/EquivalenceHashSet2Test.java @@ -0,0 +1,62 @@ +/* + * 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 javolution.util.FastSet; +import javolution.util.function.Equality; + +import java.util.Set; + +/** + * Add file description here! + * + * @author Sebastian Schaffert ([email protected]) + */ +public class EquivalenceHashSet2Test extends EquivalenceHashSetTest { + + @Override + public Set<String> createHashSet(final Equivalence<String> equivalence) { + return new FastSet<>(new Equality<String>() { + @Override + public int hashCodeOf(String object) { + return equivalence.hash(object); + } + + @Override + public boolean areEqual(String left, String right) { + return equivalence.equivalent(left, right); + } + + @Override + public int compare(String left, String right) { + return equivalence.hash(left) - equivalence.hash(right); + } + + @Override + public int hashCode() { + return equivalence.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj.hashCode() == hashCode(); + } + }); + } +} http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/collections/EquivalenceHashSetTest.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/collections/EquivalenceHashSetTest.java b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/collections/EquivalenceHashSetTest.java new file mode 100644 index 0000000..4aa3e9c --- /dev/null +++ b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/collections/EquivalenceHashSetTest.java @@ -0,0 +1,136 @@ +/* + * 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 org.junit.Assert; +import org.junit.Test; + +import java.util.Set; + +/** + * Add file description here! + * + * @author Sebastian Schaffert ([email protected]) + */ +public class EquivalenceHashSetTest { + + // a simple equivalence function on strings, saying they are equal if their first character is the same + Equivalence<String> equivalence = new Equivalence<String>() { + @Override + protected boolean doEquivalent(String a, String b) { + return a.charAt(0) == b.charAt(0); + } + + @Override + protected int doHash(String s) { + return s.charAt(0) * 31; + } + }; + + public Set<String> createHashSet(Equivalence<String> equivalence) { + return new EquivalenceHashSet<>(equivalence); + } + + @Test + public void testEquivalence() { + Assert.assertTrue(equivalence.equivalent("abc","axy")); + Assert.assertFalse(equivalence.equivalent("abc", "xyz")); + + Assert.assertTrue(equivalence.hash("abc") == equivalence.hash("axy")); + Assert.assertFalse(equivalence.hash("abc") == equivalence.hash("xyz")); + } + + @Test + public void testSetContains() { + String a = "abc"; + String b = "axy"; + String c = "xyz"; + + Set<String> set = createHashSet(equivalence); + set.add(a); + + // set should now also contain b (because first character the same) + Assert.assertTrue(set.contains(b)); + + set.add(b); + + // adding b should not change the set + Assert.assertEquals(1, set.size()); + + set.add(c); + + Assert.assertEquals(2, set.size()); + + } + + + @Test + public void testSetEquals() { + String a1 = "abc"; + String a2 = "axy"; + String b1 = "bcd"; + String b2 = "bxy"; + String c1 = "cde"; + + Set<String> set1 = createHashSet(equivalence); + Set<String> set2 = createHashSet(equivalence); + + // test empty sets + Assert.assertEquals(set1,set2); + + set1.add(a1); + set1.add(b1); + + set2.add(b2); + set2.add(a2); + + + Assert.assertEquals(2, set1.size()); + Assert.assertEquals(2, set2.size()); + + + // test sets with elements, insertion order different + Assert.assertEquals(set1,set2); + + set1.add(c1); + + Assert.assertNotEquals(set1,set2); + + + } + + @Test + public void testIteration() { + String a = "abc"; + String b = "axy"; + String c = "xyz"; + + Set<String> set = createHashSet(equivalence); + set.add(a); + set.add(b); + set.add(c); + + int count = 0; + for(String x : set) { + count++; + } + Assert.assertEquals(2,count); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java index c7eb138..415fa3c 100644 --- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java +++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java @@ -17,27 +17,20 @@ */ package org.apache.marmotta.kiwi.reasoner.engine; +import com.google.common.base.Equivalence; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import info.aduna.iteration.CloseableIteration; import info.aduna.iteration.EmptyIteration; import info.aduna.iteration.Iterations; import info.aduna.iteration.SingletonIteration; -import org.apache.marmotta.commons.collections.EquivalenceHashMap; -import org.apache.marmotta.commons.collections.EquivalenceHashSet; import org.apache.marmotta.commons.sesame.model.StatementCommons; import org.apache.marmotta.kiwi.model.caching.TripleTable; import org.apache.marmotta.kiwi.model.rdf.KiWiNode; import org.apache.marmotta.kiwi.model.rdf.KiWiResource; import org.apache.marmotta.kiwi.model.rdf.KiWiTriple; import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource; -import org.apache.marmotta.kiwi.reasoner.model.program.Justification; -import org.apache.marmotta.kiwi.reasoner.model.program.LiteralField; -import org.apache.marmotta.kiwi.reasoner.model.program.Pattern; -import org.apache.marmotta.kiwi.reasoner.model.program.Program; -import org.apache.marmotta.kiwi.reasoner.model.program.ResourceField; -import org.apache.marmotta.kiwi.reasoner.model.program.Rule; -import org.apache.marmotta.kiwi.reasoner.model.program.VariableField; +import org.apache.marmotta.kiwi.reasoner.model.program.*; import org.apache.marmotta.kiwi.reasoner.model.query.QueryResult; import org.apache.marmotta.kiwi.reasoner.persistence.KiWiReasoningConnection; import org.apache.marmotta.kiwi.reasoner.persistence.KiWiReasoningPersistence; @@ -56,14 +49,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.SQLException; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -139,6 +125,8 @@ public class ReasoningEngine implements TransactionListener { */ private SKWRLReasoner reasonerThread; + private static Equivalence<Statement> equivalence = StatementCommons.quadrupleEquivalence(); + /** * A lock to ensure that only once thread at a time is carrying out persistence */ @@ -349,7 +337,7 @@ public class ReasoningEngine implements TransactionListener { private void executeReasoner(TransactionData data) { updateTaskStatus("fetching worklist"); - Set<KiWiTriple> newTriples = new EquivalenceHashSet<>(StatementCommons.quadrupleEquivalence()); + Set<KiWiTriple> newTriples = StatementCommons.newQuadrupleSet(); for(Statement stmt : data.getAddedTriples()) { KiWiTriple t = (KiWiTriple)stmt; if(t.isMarkedForReasoning()) { @@ -517,24 +505,30 @@ public class ReasoningEngine implements TransactionListener { updateTaskStatus("loading unsupported triples"); CloseableIteration<KiWiTriple,SQLException> tripleIterator = connection.listUnsupportedTriples(); - - updateTaskStatus("deleting unsupported triples"); - SailConnection tc = store.getConnection(); - KiWiSailConnection ic = getWrappedConnection(tc); try { - tc.begin(); - while(tripleIterator.hasNext()) { - ic.removeInferredStatement(tripleIterator.next()); - count++; + if(tripleIterator.hasNext()) { + + updateTaskStatus("deleting unsupported triples"); + SailConnection tc = store.getConnection(); + KiWiSailConnection ic = getWrappedConnection(tc); + try { + tc.begin(); + while(tripleIterator.hasNext()) { + ic.removeInferredStatement(tripleIterator.next()); + count++; + } + log.debug("removed {} unsupported triples",count); + tc.commit(); + } catch(SailException ex) { + ic.rollback(); + throw ex; + } finally { + ic.close(); + } } - log.debug("removed {} unsupported triples",count); - tc.commit(); - } catch(SailException ex) { - ic.rollback(); - throw ex; } finally { Iterations.closeCloseable(tripleIterator); - ic.close(); + } } @@ -768,7 +762,7 @@ public class ReasoningEngine implements TransactionListener { HashSet<Justification> justifications = new HashSet<Justification>(); Iterations.addAll(connection.listJustificationsForTriple(t), justifications); for(Justification j : transactionJustifications) { - if(j.getTriple().equals(t)) { + if(equivalence.equivalent(j.getTriple(), t)) { justifications.add(j); } } @@ -784,7 +778,7 @@ public class ReasoningEngine implements TransactionListener { */ private Set<Justification> getBaseJustifications(KiWiReasoningConnection connection, Set<Justification> justifications) throws SQLException { Set<Justification> baseJustifications = new HashSet<Justification>(); - Map<KiWiTriple,Collection<Justification>> justificationCache = new HashMap<KiWiTriple, Collection<Justification>>(); + Map<KiWiTriple,Collection<Justification>> justificationCache = StatementCommons.newQuadrupleMap(); for(Justification justification : justifications) { KiWiTriple triple = justification.getTriple(); @@ -842,7 +836,7 @@ public class ReasoningEngine implements TransactionListener { */ private void removeDuplicateJustifications(KiWiReasoningConnection connection, Set<Justification> justifications) throws SQLException { // remove duplicate justifications - Map<KiWiTriple,Collection<Justification>> justificationCache = new EquivalenceHashMap<KiWiTriple, Collection<Justification>>(StatementCommons.quadrupleEquivalence()); + Map<KiWiTriple,Collection<Justification>> justificationCache = StatementCommons.newQuadrupleMap(); for(Iterator<Justification> it = justifications.iterator(); it.hasNext(); ) { Justification j = it.next(); @@ -928,6 +922,8 @@ public class ReasoningEngine implements TransactionListener { } public void shutdown() { + log.info("shutting down reasoning service ..."); + for(int i = 0; i<10 && isRunning(); i++) { log.warn("reasoner not yet finished, waiting for 10 seconds (try={})", i+1); try { @@ -936,7 +932,6 @@ public class ReasoningEngine implements TransactionListener { } } - log.info("shutting down reasoning service ..."); reasonerThread.shutdown(); } @@ -970,6 +965,7 @@ public class ReasoningEngine implements TransactionListener { } public void shutdown() { + log.info("REASONER: signalling shutdown to reasoner thread"); shutdown = true; this.interrupt(); } http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java index c6f5a6e..5de904e 100644 --- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java +++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java @@ -18,9 +18,10 @@ package org.apache.marmotta.kiwi.reasoner.model.program; -import org.apache.marmotta.commons.collections.EquivalenceHashSet; +import com.google.common.base.Equivalence; import org.apache.marmotta.commons.sesame.model.StatementCommons; import org.apache.marmotta.kiwi.model.rdf.KiWiTriple; +import org.openrdf.model.Statement; import java.util.Date; import java.util.HashSet; @@ -65,8 +66,11 @@ public class Justification { */ private Date createdAt; + + private static Equivalence<Statement> equivalence = StatementCommons.quadrupleEquivalence(); + public Justification() { - supportingTriples = new EquivalenceHashSet<>(StatementCommons.quadrupleEquivalence()); + supportingTriples = StatementCommons.newQuadrupleSet(); supportingRules = new HashSet<Rule>(); } @@ -120,7 +124,7 @@ public class Justification { //if (id != null ? !id.equals(that.id) : that.id != null) return false; if (!supportingRules.equals(that.supportingRules)) return false; if (!supportingTriples.equals(that.supportingTriples)) return false; - if (!triple.equals(that.triple)) return false; + if (!equivalence.equivalent(this.triple, that.triple)) return false; return true; } @@ -128,7 +132,7 @@ public class Justification { @Override public int hashCode() { int result = 0; // id != null ? id.hashCode() : 0; - result = 31 * result + triple.hashCode(); + result = 31 * result + equivalence.hash(triple); result = 31 * result + supportingTriples.hashCode(); result = 31 * result + supportingRules.hashCode(); return result; http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/engine/ReasoningEngineTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/engine/ReasoningEngineTest.java b/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/engine/ReasoningEngineTest.java index a9a3dcf..75b7cad 100644 --- a/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/engine/ReasoningEngineTest.java +++ b/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/engine/ReasoningEngineTest.java @@ -326,6 +326,9 @@ public class ReasoningEngineTest { log.debug("sleeping for 100ms to let engine finish processing ... "); Thread.sleep(100); } + + log.debug("reasoning finished, running tests"); + con.begin(); List<Statement> inferred4 = Iterations.asList(con.getStatements(a,property,d, true)); http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java b/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java index b08c0cf..c6b7f2e 100644 --- a/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java +++ b/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java @@ -79,6 +79,7 @@ public class KiWiRDFSchemaRepositoryConnectionTest extends RDFSchemaRepositoryCo Sail wsail = new SailWrapper(rsail) { @Override public void shutDown() throws SailException { + rsail.getEngine().shutdown(); try { rsail.getPersistence().dropDatabase(); http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/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 8e329e8..1e5cade 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 @@ -1195,7 +1195,7 @@ public class KiWiConnection { // need to remove from triple batch and from database commitLock.lock(); try { - if(!tripleBatch.remove(triple)) { + if(tripleBatch == null || !tripleBatch.remove(triple)) { requireJDBCConnection(); PreparedStatement deleteTriple = getPreparedStatement("delete.triple"); http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/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 7fc39cd..98ff1b9 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 @@ -444,7 +444,7 @@ public class KiWiPersistence { } } - if(connectionPool != null) { + if(initialized && connectionPool != null) { Connection conn = connectionPool.getConnection(); conn.setAutoCommit(false); @@ -508,6 +508,8 @@ public class KiWiPersistence { public void shutdown() { + initialized = false; + if(!droppedDatabase && !configuration.isCommitSequencesOnCommit()) { log.info("storing in-memory sequences in database ..."); try { @@ -531,7 +533,6 @@ public class KiWiPersistence { connectionPool = null; memorySequences = null; - initialized = false; } /** http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/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 5740b91..6a6a261 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 @@ -56,7 +56,7 @@ public class TripleTable<Triple extends Statement> implements Set<Triple>, Seria private NavigableMap<IntArray,Triple> indexCSPO; public TripleTable() { - data = new EquivalenceHashSet<Triple>(StatementCommons.quadrupleEquivalence()); + data = StatementCommons.newQuadrupleSet(); indexSPOC = new TreeMap<IntArray, Triple>(); indexCSPO = new TreeMap<IntArray, Triple>(); }
