You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2013/02/19 13:52:00 UTC

[40/52] [partial] code contribution, initial import of relevant modules of LMF-3.0.0-SNAPSHOT based on revision 4bf944319368 of the default branch at https://code.google.com/p/lmf/

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java b/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
new file mode 100644
index 0000000..5f71e29
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
@@ -0,0 +1,242 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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.kiwi.sail;
+
+import org.apache.marmotta.kiwi.model.caching.IntArray;
+import org.apache.marmotta.kiwi.model.collection.WeakValueMap;
+import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.apache.marmotta.kiwi.persistence.KiWiConnection;
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
+import org.openrdf.model.Statement;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.sail.SailException;
+import org.openrdf.sail.helpers.NotifyingSailBase;
+
+import java.sql.SQLException;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * An implementation of a KiWi triple store without extended transaction support. The KiWiStore holds a reference to
+ * a KiWiPersistence object to access the database. Each SailConnection will be directly associated with a database
+ * connection and a database transaction.
+ * <p/>
+ * Note that extended KiWi functionality like the reasoner or versioning require the extended transaction support.
+ * In these cases, please see KiWiTransactionalStore.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class KiWiStore extends NotifyingSailBase {
+
+
+    /**
+     * A KiWiConnection used when a value factory is opened directly from the repository via getValueFactory().
+     * The connection will be initialised the first time getValueFactory is called and closed when the KiWiStore
+     * shuts down.
+     */
+    private KiWiConnection valueFactoryConnection;
+
+    /**
+     * The repository-wide value factory, using the valueFactoryConnection above. Will be initialised when
+     * getValueFactory() is called for the first time.
+     */
+    private KiWiValueFactory repositoryValueFactory;
+
+
+    private KiWiPersistence persistence;
+
+    /**
+     * The default context to use when no explicit context is given in createStatement. The KiWi triple store
+     * does not support null values for the context of a triple, so this URL must be set to an appropriate value
+     */
+    private String defaultContext;
+
+    /**
+     * The context to use for storing all inferred triples. The value set here will override all contexts
+     * given to addInferredTriple, because KiWi always stores all inferred triples in the same context.
+     */
+    private String inferredContext;
+
+
+    private boolean initialized = false;
+
+    /**
+     * For some operations (e.g. looking up nodes and triples) we hold a store-wide lock to avoid clashes between
+     * threads. This could probably be relaxed a bit or even dropped altogether, but this approach is safer.
+     */
+    protected ReentrantLock lock;
+
+
+    /**
+     * This is a hash map for storing references to resources that have not yet been persisted. It is used e.g. when
+     * one or more transactions are currently active and request the creation of same resource several times
+     * (via createResource()).
+     * <p/>
+     * The map is implemented as a hash map with weak references, i.e. the entries are volatile and
+     * will be removed by the garbage collector once they are not referred anymore somewhere else (e.g. in a
+     * transaction).
+     * <p/>
+     * The registry is not a proper cache, entries will be removed when they are no longer referred. Also, the
+     * registry should not be used to check for existence of a resource via getResource(), it is purely meant
+     * to ensure that a resource is not created multiple times.
+     */
+    protected WeakValueMap<String,KiWiUriResource>  uriRegistry;
+    protected WeakValueMap<String,KiWiAnonResource> bnodeRegistry;
+    protected WeakValueMap<String,KiWiLiteral>      literalRegistry;
+    protected WeakValueMap<IntArray,Statement>      tripleRegistry;
+
+    public KiWiStore(KiWiPersistence persistence, String defaultContext, String inferredContext) {
+    	this.persistence    = persistence;
+    	this.defaultContext = defaultContext;
+    	this.lock           = new ReentrantLock();
+        this.inferredContext = inferredContext;
+    	
+    	uriRegistry     = new WeakValueMap<String, KiWiUriResource>();
+    	bnodeRegistry   = new WeakValueMap<String, KiWiAnonResource>();
+    	literalRegistry = new WeakValueMap<String, KiWiLiteral>();
+    	tripleRegistry  = new WeakValueMap<IntArray, Statement>();
+
+    }
+
+    public KiWiStore(String name, String jdbcUrl, String db_user, String db_password, KiWiDialect dialect, String defaultContext, String inferredContext) {
+    	this(new KiWiPersistence(name,jdbcUrl,db_user,db_password,dialect), defaultContext, inferredContext);
+    }
+
+
+    /**
+     * Do store-specific operations to initialize the store. The default
+     * implementation of this method does nothing.
+     */
+    @Override
+    protected void initializeInternal() throws SailException {
+        try {
+            persistence.initDatabase();
+            persistence.initialise();
+
+            initialized = true;
+        } catch (SQLException e) {
+            throw new SailException("database error while initialising database",e);
+        }
+    }
+
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+    /**
+     * The default context to use when no explicit context is given in createStatement. The KiWi triple store
+     * does not support null values for the context of a triple, so this URL must be set to an appropriate value
+     */
+    public String getDefaultContext() {
+        return defaultContext;
+    }
+
+
+    /**
+     * The context to use for storing all inferred triples. The value set here will override all contexts
+     * given to addInferredTriple, because KiWi always stores all inferred triples in the same context.
+     */
+    public String getInferredContext() {
+        return inferredContext;
+    }
+
+    /**
+     * Return a reference to the persistence object used by this KiWiStore.
+     * @return
+     */
+    public KiWiPersistence getPersistence() {
+        return persistence;
+    }
+
+    /**
+     * Returns a store-specific SailConnection object.
+     *
+     * @return A connection to the store.
+     */
+    @Override
+    protected KiWiSailConnection getConnectionInternal() throws SailException {
+        return new KiWiSailConnection(this);
+    }
+
+    /**
+     * Do store-specific operations to ensure proper shutdown of the store.
+     */
+    @Override
+    protected void shutDownInternal() throws SailException {
+        closeValueFactory();
+        persistence.shutdown();
+    }
+
+    /**
+     * In case there is a value factory managed by this repository directly, close it (and the underlying database
+     * connection)
+     */
+    public void closeValueFactory() {
+        if(repositoryValueFactory != null) {
+            repositoryValueFactory = null;
+        }
+        if(valueFactoryConnection != null) {
+            try {
+                if(!valueFactoryConnection.isClosed()) {
+                    // connection is autocommit
+                    if(!valueFactoryConnection.getAutoCommit()) {
+                        valueFactoryConnection.commit();
+                    }
+                    valueFactoryConnection.close();
+                }
+            } catch (SQLException ex) {
+                logger.warn("SQL exception ({}) while closing value factory connection",ex.getMessage());
+            } catch (Exception ex) {
+                logger.warn("generic exception ({}) while closing value factory connection",ex.getMessage());
+            }
+        }
+
+    }
+
+    /**
+     * Checks whether this Sail object is writable, i.e. if the data contained in
+     * this Sail object can be changed.
+     */
+    @Override
+    public boolean isWritable() throws SailException {
+        return true;
+    }
+
+    /**
+     * Gets a ValueFactory object that can be used to create URI-, blank node-,
+     * literal- and statement objects.
+     *
+     * @return a ValueFactory object for this Sail object.
+     */
+    @Override
+    public ValueFactory getValueFactory() {
+        if(valueFactoryConnection == null) {
+            try {
+                valueFactoryConnection = persistence.getConnection();
+                valueFactoryConnection.setAutoCommit(true);
+            } catch (SQLException e) {
+                logger.error("could not create database connection",e);
+            }
+        }
+        if(repositoryValueFactory == null) {
+            repositoryValueFactory = new KiWiValueFactory(this, valueFactoryConnection, defaultContext);
+        }
+        return repositoryValueFactory;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java b/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
new file mode 100644
index 0000000..85967e4
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
@@ -0,0 +1,578 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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.kiwi.sail;
+
+import at.newmedialab.sesame.commons.model.LiteralCommons;
+import at.newmedialab.sesame.commons.model.Namespaces;
+import at.newmedialab.sesame.commons.util.DateUtils;
+import org.apache.commons.lang.LocaleUtils;
+import org.apache.marmotta.kiwi.model.caching.IntArray;
+import org.apache.marmotta.kiwi.model.collection.WeakValueMap;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.apache.marmotta.kiwi.persistence.KiWiConnection;
+import org.openrdf.model.BNode;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.repository.RepositoryException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Random;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class KiWiValueFactory implements ValueFactory {
+
+    private static Logger log = LoggerFactory.getLogger(KiWiValueFactory.class);
+
+    private Random anonIdGenerator;
+
+
+    /**
+     * This is a hash map for storing references to resources that have not yet been persisted. It is used e.g. when
+     * one or more transactions are currently active and request the creation of same resource several times
+     * (via createResource()).
+     * <p/°
+     * The map is implemented as a hash map with weak references, i.e. the entries are volatile and
+     * will be removed by the garbage collector once they are not referred anymore somewhere else (e.g. in a
+     * transaction).
+     * <p/>
+     * The registry is not a proper cache, entries will be removed when they are no longer referred. Also, the
+     * registry should not be used to check for existence of a resource via getResource(), it is purely meant
+     * to ensure that a resource is not created multiple times.
+     */
+    private WeakValueMap<String,KiWiUriResource>  uriRegistry;
+    private WeakValueMap<String,KiWiAnonResource> bnodeRegistry;
+    private WeakValueMap<String,KiWiLiteral>      literalRegistry;
+    private WeakValueMap<IntArray,Statement>      tripleRegistry;
+
+    private KiWiConnection connection;
+
+    private ReentrantLock lock;
+
+    private String defaultContext;
+
+
+    public KiWiValueFactory(KiWiStore store, KiWiConnection connection, String defaultContext) {
+        lock = store.lock;
+
+        anonIdGenerator = new Random();
+        uriRegistry     = store.uriRegistry;
+        bnodeRegistry   = store.bnodeRegistry;
+        literalRegistry = store.literalRegistry;
+        tripleRegistry  = store.tripleRegistry;
+
+        this.connection     = connection;
+        this.defaultContext = defaultContext;
+    }
+
+    /**
+     * Creates a new bNode.
+     *
+     * @return An object representing the bNode.
+     */
+    @Override
+    public BNode createBNode() {
+        return createBNode(Long.toHexString(System.currentTimeMillis())+Integer.toHexString(anonIdGenerator.nextInt(1000)));
+    }
+
+    /**
+     * Creates a new URI from the supplied string-representation.
+     *
+     * @param uri A string-representation of a URI.
+     * @return An object representing the URI.
+      */
+    @Override
+    public URI createURI(String uri) {
+        lock.lock();
+        try {
+            // first look in the registry for newly created resources if the resource has already been created and
+            // is still volatile
+            KiWiUriResource result = uriRegistry.get(uri);
+
+            if(result == null) {
+                result = connection.loadUriResource(uri);
+
+                if(result == null) {
+                    result = new KiWiUriResource(uri);
+                    connection.storeNode(result);
+                    uriRegistry.put(uri,result);
+                }
+            }
+
+            return result;
+        } catch (SQLException e) {
+            log.error("database error, could not load URI resource",e);
+            throw new IllegalStateException("database error, could not load URI resource",e);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    /**
+     * Creates a new URI from the supplied namespace and local name. Calling this
+     * method is funtionally equivalent to calling
+     * {@link #createURI(String) createURI(namespace+localName)}, but allows the
+     * ValueFactory to reuse supplied namespace and local name strings whenever
+     * possible. Note that the values returned by {@link org.openrdf.model.URI#getNamespace()} and
+     * {@link org.openrdf.model.URI#getLocalName()} are not necessarily the same as the values that
+     * are supplied to this method.
+     *
+     * @param namespace The URI's namespace.
+     * @param localName The URI's local name.
+     * @throws IllegalArgumentException If the supplied namespace and localname do not resolve to a legal
+     *                                  (absolute) URI.
+     */
+    @Override
+    public URI createURI(String namespace, String localName) {
+        return createURI(namespace+localName);
+    }
+
+    /**
+     * Creates a new blank node with the given node identifier.
+     *
+     * @param nodeID The blank node identifier.
+     * @return An object representing the blank node.
+     */
+    @Override
+    public BNode createBNode(String nodeID) {
+        lock.lock();
+        try {
+            // first look in the registry for newly created resources if the resource has already been created and
+            // is still volatile
+            KiWiAnonResource result = bnodeRegistry.get(nodeID);
+
+            if(result == null) {
+                result = connection.loadAnonResource(nodeID);
+
+                if(result == null) {
+                    result = new KiWiAnonResource(nodeID);
+                    connection.storeNode(result);
+                    bnodeRegistry.put(nodeID,result);
+                }
+            }
+
+            return result;
+        } catch (SQLException e) {
+            log.error("database error, could not load anonymous resource",e);
+            throw new IllegalStateException("database error, could not load anonymous resource",e);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    /**
+     * Creates a new literal representing the specified date that is typed using
+     * the appropriate XML Schema date/time datatype.
+     *
+     * @since 2.7.0
+     */
+    @Override
+    public Literal createLiteral(Date date) {
+        return createLiteral(date, null, LiteralCommons.getXSDType(Date.class));
+    }
+
+    /**
+     * Creates a typed {@link org.openrdf.model.Literal} out of the supplied object, mapping the
+     * runtime type of the object to the appropriate XML Schema type. If no
+     * mapping is available, the method returns a literal with the string
+     * representation of the supplied object as the value, and
+     * {@link org.openrdf.model.vocabulary.XMLSchema#STRING} as the datatype. Recognized types are
+     * {@link Boolean}, {@link Byte}, {@link Double}, {@link Float},
+     * {@link Integer}, {@link Long}, {@link Short}, {@link javax.xml.datatype.XMLGregorianCalendar }
+     * , and {@link java.util.Date}.
+     *
+     * @param object an object to be converted to a typed literal.
+     * @return a typed literal representation of the supplied object.
+     * @since 2.7.0
+     */
+    @Override
+    public Literal createLiteral(Object object) {
+        if(object instanceof XMLGregorianCalendar) {
+            return createLiteral((XMLGregorianCalendar)object);
+        } else {
+            return createLiteral(object,null,null);
+        }
+    }
+
+    /**
+     * Creates a new literal with the supplied label.
+     *
+     * @param label The literal's label.
+     */
+    @Override
+    public Literal createLiteral(String label) {
+        return createLiteral(label, null, LiteralCommons.getXSDType(String.class));
+    }
+
+    /**
+     * Creates a new literal with the supplied label and language attribute.
+     *
+     * @param label    The literal's label.
+     * @param language The literal's language attribute, or <tt>null</tt> if the literal
+     *                 doesn't have a language.
+     */
+    @Override
+    public Literal createLiteral(String label, String language) {
+        return createLiteral(label,language,LiteralCommons.getRDFLangStringType());
+    }
+
+    /**
+     * Creates a new literal with the supplied label and datatype.
+     *
+     * @param label    The literal's label.
+     * @param datatype The literal's datatype, or <tt>null</tt> if the literal doesn't
+     *                 have a datatype.
+     */
+    @Override
+    public Literal createLiteral(String label, URI datatype) {
+        return createLiteral(label,null,datatype.stringValue());
+    }
+
+
+    /**
+     * Internal createLiteral method for different datatypes. This method distinguishes based on the Java class
+     * type and the type argument passed as argument how to load and possibly create the new literal.
+     *
+     * @param value
+     * @param lang
+     * @param type
+     * @param <T>
+     * @return
+     */
+    private <T> KiWiLiteral createLiteral(T value, String lang, String type) {
+        lock.lock();
+        try {
+        	if (lang != null) {
+        		type = LiteralCommons.getRDFLangStringType();
+        	} else if(type == null) {
+                type = LiteralCommons.getXSDType(value.getClass());
+            }
+
+            KiWiLiteral result = null;
+
+            final KiWiUriResource rtype = (KiWiUriResource)createURI(type);
+            final Locale locale;
+            if(lang != null) {
+                locale = LocaleUtils.toLocale(lang);
+            } else 
+            	locale  = null;
+
+
+            // differentiate between the different types of the value
+            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());
+                }
+
+                final String cacheKey = LiteralCommons.createCacheKey(dvalue, type);
+                result = literalRegistry.get(cacheKey);
+                if(result == null) {
+                    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());
+                }
+
+
+                final String cacheKey = LiteralCommons.createCacheKey(Long.toString(ivalue), null, type);
+                result = literalRegistry.get(cacheKey);
+                if(result == null) {
+                    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());
+                }
+
+
+                final String cacheKey = LiteralCommons.createCacheKey(Double.toString(dvalue), null, type);
+                result = literalRegistry.get(cacheKey);
+                if(result == null) {
+                    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());
+                }
+
+
+                final String cacheKey = LiteralCommons.createCacheKey(Boolean.toString(bvalue), null, type);
+                result = literalRegistry.get(cacheKey);
+                if(result == null) {
+                    result = connection.loadLiteral(bvalue);
+
+                    if(result == null) {
+                        result= new KiWiBooleanLiteral(bvalue, rtype);
+                    }
+                }
+            } else {
+            	final String cacheKey = LiteralCommons.createCacheKey(value.toString(), locale, type);
+                result = literalRegistry.get(cacheKey);
+                if(result == null) {
+                    result = connection.loadLiteral(value.toString(), lang, rtype);
+
+                    if(result == null) {
+                        result = new KiWiStringLiteral(value.toString(), locale, rtype);
+                    }
+                }
+            }
+
+            if(result.getId() == null) {
+                connection.storeNode(result);
+            }
+
+            return result;
+
+        } catch (SQLException e) {
+            log.error("database error, could not load literal",e);
+            throw new IllegalStateException("database error, could not load literal",e);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    /**
+     * Creates a new <tt>xsd:boolean</tt>-typed literal representing the
+     * specified value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:boolean</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(boolean value) {
+        return createLiteral(value,null,LiteralCommons.getXSDType(Boolean.class));
+    }
+
+    /**
+     * Creates a new <tt>xsd:byte</tt>-typed literal representing the
+     * specified value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:byte</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(byte value) {
+        return createLiteral((int)value,null,LiteralCommons.getXSDType(Byte.class));
+    }
+
+    /**
+     * Creates a new <tt>xsd:short</tt>-typed literal representing the
+     * specified value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:short</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(short value) {
+        return createLiteral((int)value,null,LiteralCommons.getXSDType(Short.class));
+    }
+
+    /**
+     * Creates a new <tt>xsd:int</tt>-typed literal representing the specified
+     * value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:int</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(int value) {
+        return createLiteral(value,null,LiteralCommons.getXSDType(Integer.class));
+    }
+
+    /**
+     * Creates a new <tt>xsd:long</tt>-typed literal representing the
+     * specified value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:long</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(long value) {
+        return createLiteral(value,null,LiteralCommons.getXSDType(Long.class));
+    }
+
+    /**
+     * Creates a new <tt>xsd:float</tt>-typed literal representing the
+     * specified value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:float</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(float value) {
+        return createLiteral(value,null,LiteralCommons.getXSDType(Float.class));
+    }
+
+    /**
+     * Creates a new <tt>xsd:double</tt>-typed literal representing the
+     * specified value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:double</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(double value) {
+        return createLiteral(value,null,LiteralCommons.getXSDType(Double.class));
+    }
+
+    /**
+     * Creates a new literal representing the specified calendar that is typed
+     * using the appropriate XML Schema date/time datatype.
+     *
+     * @param calendar The value for the literal.
+     * @return An typed literal for the specified calendar.
+     */
+    @Override
+    public Literal createLiteral(XMLGregorianCalendar calendar) {
+        Date value = calendar.toGregorianCalendar().getTime();
+
+        return createLiteral(value,null,LiteralCommons.getXSDType(Date.class));
+    }
+
+    /**
+     * Creates a new statement with the supplied subject, predicate and object.
+     *
+     * @param subject   The statement's subject.
+     * @param predicate The statement's predicate.
+     * @param object    The statement's object.
+     * @return The created statement.
+     */
+    @Override
+    public Statement createStatement(Resource subject, URI predicate, Value object) {
+        return createStatement(subject, predicate, object, createURI(defaultContext));
+    }
+
+    /**
+     * Creates a new statement with the supplied subject, predicate and object
+     * and associated context.
+     *
+     * @param subject   The statement's subject.
+     * @param predicate The statement's predicate.
+     * @param object    The statement's object.
+     * @param context   The statement's context.
+     * @return The created statement.
+     */
+    @Override
+    public Statement createStatement(Resource subject, URI predicate, Value object, Resource context) {
+        lock.lock();
+        try {
+            IntArray cacheKey = IntArray.createSPOCKey(subject,predicate,object,context);
+            Statement result = tripleRegistry.get(cacheKey);
+            if(result == null || ((KiWiTriple)result).isDeleted()) {
+                KiWiResource ksubject   = convert(subject);
+                KiWiUriResource kpredicate = convert(predicate);
+                KiWiNode kobject    = convert(object);
+                KiWiResource    kcontext   = convert(context);
+
+                // test if the triple already exists in the database; if yes, return it
+                List<Statement> triples = connection.listTriples(ksubject,kpredicate,kobject,kcontext,true).asList();
+                if(triples.size() == 1) {
+                    result = triples.get(0);
+                } else {
+                    result = new KiWiTriple(ksubject,kpredicate,kobject,kcontext);
+                    ((KiWiTriple)result).setMarkedForReasoning(true);
+                }
+
+                tripleRegistry.put(cacheKey,result);
+            }
+            return result;
+        } catch (SQLException e) {
+            log.error("database error, could not load triple", e);
+            throw new IllegalStateException("database error, could not load triple",e);
+        } catch (RepositoryException e) {
+            log.error("database error, could not load triple", e);
+            throw new IllegalStateException("database error, could not load triple",e);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+
+    public KiWiResource convert(Resource r) {
+        return (KiWiResource)convert((Value)r);
+    }
+
+    public KiWiUriResource convert(URI r) {
+        return (KiWiUriResource)convert((Value)r);
+    }
+
+    public KiWiNode convert(Value value) {
+        if(value == null) {
+            return null;
+        } else if(value instanceof KiWiNode) {
+            return (KiWiNode)value;
+        } else if(value instanceof URI) {
+            return (KiWiUriResource)createURI(value.stringValue());
+        } else if(value instanceof BNode) {
+            return (KiWiAnonResource)createBNode(value.stringValue());
+        } else if(value instanceof Literal) {
+            Literal l = (Literal)value;
+            return createLiteral(l.getLabel(),l.getLanguage(), l.getDatatype() != null ? l.getDatatype().stringValue(): null);
+        } else {
+            throw new IllegalArgumentException("the value passed as argument does not have the correct type");
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/ehcache-kiwi.xml
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/ehcache-kiwi.xml b/kiwi/kiwi-triplestore/src/main/resources/ehcache-kiwi.xml
new file mode 100644
index 0000000..3bde02c
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/ehcache-kiwi.xml
@@ -0,0 +1,217 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (C) 2013 Salzburg Research.
+
+    Licensed 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.
+
+-->
+<!--
+CacheManager Configuration
+==========================
+An ehcache.xml corresponds to a single CacheManager.
+
+See instructions below or the ehcache schema (ehcache.xsd) on how to configure.
+
+System property tokens can be specified in this file which are replaced when the configuration
+is loaded. For example multicastGroupPort=${multicastGroupPort} can be replaced with the
+System property either from an environment variable or a system property specified with a
+command line switch such as -DmulticastGroupPort=4446.
+
+The attributes of <ehcache> are:
+* name - an optional name for the CacheManager.  The name is optional and primarily used 
+for documentation or to distinguish Terracotta clustered cache state.  With Terracotta 
+clustered caches, a combination of CacheManager name and cache name uniquely identify a 
+particular cache store in the Terracotta clustered memory.
+* updateCheck - an optional boolean flag specifying whether this CacheManager should check
+for new versions of Ehcache over the Internet.  If not specified, updateCheck="true".
+* monitoring - an optional setting that determines whether the CacheManager should 
+automatically register the SampledCacheMBean with the system MBean server.  Currently,
+this monitoring is only useful when using Terracotta and thus the "autodetect" value 
+will detect the presence of Terracotta and register the MBean.  Other allowed values 
+are "on" and "off".  The default is "autodetect".
+-->    
+<ehcache name="kiwi"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         updateCheck="false"
+         xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">
+
+    <!-- 
+    DiskStore configuration
+    =======================
+
+    The diskStore element is optional. To turn off disk store path creation, comment out the diskStore
+    element below.
+
+    Configure it if you have overflowToDisk or diskPersistent enabled for any cache.
+
+    If it is not configured, and a cache is created which requires a disk store, a warning will be
+     issued and java.io.tmpdir will automatically be used.
+
+    diskStore has only one attribute - "path". It is the path to the directory where
+    .data and .index files will be created.
+
+    If the path is one of the following Java System Property it is replaced by its value in the
+    running VM. For backward compatibility these are not specified without being enclosed in the ${token}
+    replacement syntax.
+
+    The following properties are translated:
+    * user.home - KiWiUser's home directory
+    * user.dir - KiWiUser's current working directory
+    * java.io.tmpdir - Default temp file path
+    * ehcache.disk.store.dir - A system property you would normally specify on the command line
+      e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...
+
+    Subdirectories can be specified below the property e.g. java.io.tmpdir/one
+
+    -->
+    <diskStore path="java.io.tmpdir/kiwi-cache"/>
+
+
+    <!-- Cache configuration.
+
+    The following attributes are required.
+
+    name:
+    Sets the name of the cache. This is used to identify the cache. It must be unique.
+
+    maxElementsInMemory:
+    Sets the maximum number of objects that will be created in memory
+
+        maxElementsOnDisk:
+    Sets the maximum number of objects that will be maintained in the DiskStore
+        The default value is zero, meaning unlimited.
+
+    eternal:
+    Sets whether elements are eternal. If eternal,  timeouts are ignored and the
+    element is never expired.
+
+    overflowToDisk:
+    Sets whether elements can overflow to disk when the memory store
+    has reached the maxInMemory limit.
+
+    The following attributes are optional.
+
+    timeToIdleSeconds:
+    Sets the time to idle for an element before it expires.
+    i.e. The maximum amount of time between accesses before an element expires
+    Is only used if the element is not eternal.
+    Optional attribute. A value of 0 means that an Element can idle for infinity.
+    The default value is 0.
+
+    timeToLiveSeconds:
+    Sets the time to live for an element before it expires.
+    i.e. The maximum time between creation time and when an element expires.
+    Is only used if the element is not eternal.
+    Optional attribute. A value of 0 means that and Element can live for infinity.
+    The default value is 0.
+
+    diskPersistent:
+    Whether the disk store persists between restarts of the Virtual Machine.
+    The default value is false.
+
+    diskExpiryThreadIntervalSeconds:
+    The number of seconds between runs of the disk expiry thread. The default value
+    is 120 seconds.
+
+    memoryStoreEvictionPolicy:
+    Policy would be enforced upon reaching the maxElementsInMemory limit. Default
+    policy is Least Recently Used (specified as LRU). Other policies available -
+    First In First Out (specified as FIFO) and Less Frequently Used
+    (specified as LFU)
+
+    -->
+
+    <!--
+    Mandatory Default Cache configuration. These settings will be applied to caches
+    created programmtically using CacheManager.add(String cacheName)
+    -->
+    <defaultCache
+            maxElementsInMemory="20000"
+            eternal="true"
+            overflowToDisk="false"
+            memoryStoreEvictionPolicy="LRU"
+            />
+
+    <!--
+       a cache from database ID to KiWiNode; should be very large since this kind of lookup is a very frequent operation
+    -->
+    <cache name="node-cache"
+           maxElementsInMemory="500000"
+           eternal="true"
+           overflowToDisk="false"
+           memoryStoreEvictionPolicy="LFU"/>
+
+    <!--
+        a cache from database ID to KiWiTriple; should be fairly large since it can speed up loading query results
+        from the database by avoiding reconstructing each triple from the database result
+    -->
+    <cache name="triple-cache"
+           maxElementsInMemory="100000"
+           overflowToDisk="false"
+           timeToLiveSeconds="3600"
+           memoryStoreEvictionPolicy="LFU"/>
+
+    <!--
+        the cache used for triple queries (getStatements) by the KiWi triplestore; this can be helpful if the same
+        query is repeated very often, but needs not be very big
+    -->
+    <cache name="query-cache"
+           statistics="true"
+           maxElementsInMemory="10000"
+           timeToLiveSeconds="3600"
+           overflowToDisk="false"/>
+
+    <!-- a cache from URI to KiWiUriResource -->
+    <cache name="uri-cache"
+           maxElementsInMemory="50000"
+           eternal="true"
+           overflowToDisk="false"
+           memoryStoreEvictionPolicy="LFU"/>
+
+    <!-- a cache from anonymous ID to KiWiAnonResource -->
+    <cache name="bnode-cache"
+           maxElementsInMemory="5000"
+           eternal="true"
+           overflowToDisk="false"
+           memoryStoreEvictionPolicy="LFU"/>
+
+
+    <!-- a cache from literal cache key to KiWiLiteral -->
+    <cache name="literal-cache"
+           maxElementsInMemory="50000"
+           eternal="true"
+           overflowToDisk="false"
+           memoryStoreEvictionPolicy="LFU"/>
+
+
+    <cache name="namespace-prefix-cache"
+           maxElementsInMemory="100"
+           eternal="true"
+           overflowToDisk="false"
+           memoryStoreEvictionPolicy="LFU"/>
+
+    <cache name="namespace-uri-cache"
+           maxElementsInMemory="100"
+           eternal="true"
+           overflowToDisk="false"
+           memoryStoreEvictionPolicy="LFU"/>
+
+    <!--  uncomment to enable cache debugging -->
+<!-- 
+	<cacheManagerPeerListenerFactory
+	    class="org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory"
+	    properties="monitorAddress=localhost, monitorPort=9889" />
+-->
+
+</ehcache>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql
new file mode 100644
index 0000000..ea348b5
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql
@@ -0,0 +1,68 @@
+CREATE SEQUENCE seq_nodes;
+CREATE SEQUENCE seq_triples;
+CREATE SEQUENCE seq_namespaces;
+
+CREATE TABLE nodes (
+  id        bigint     NOT NULL,
+  ntype     char(8)    NOT NULL,
+  svalue    varchar(65536) NOT NULL,
+  dvalue    double precision,
+  ivalue    bigint,
+  tvalue    timestamp,
+  bvalue    boolean,
+  ltype     bigint     REFERENCES nodes(id),
+  lang      varchar(5),
+  createdAt timestamp  NOT NULL DEFAULT now(),
+  PRIMARY KEY(id)
+);
+
+CREATE TABLE triples (
+  id        bigint     NOT NULL,
+  subject   bigint     NOT NULL REFERENCES nodes(id),
+  predicate bigint     NOT NULL REFERENCES nodes(id),
+  object    bigint     NOT NULL REFERENCES nodes(id),
+  context   bigint     NOT NULL REFERENCES nodes(id),
+  creator   bigint     REFERENCES nodes(id),
+  inferred  boolean    DEFAULT false,
+  deleted   boolean    DEFAULT false,
+  createdAt timestamp  NOT NULL DEFAULT now(),
+  deletedAt timestamp,
+  PRIMARY KEY(id),
+  CHECK ( (deleted AND deletedAt IS NOT NULL) OR ((NOT deleted) AND deletedAt IS NULL) )
+);
+
+CREATE TABLE namespaces (
+  id        bigint        NOT NULL,
+  prefix    varchar(256)  NOT NULL,
+  uri       varchar(2048) NOT NULL,
+  createdAt timestamp  NOT NULL DEFAULT now(),
+  PRIMARY KEY(id)
+);
+
+-- A table for storing metadata about the current database, e.g. version numbers for each table
+CREATE TABLE metadata (
+  id        integer       NOT NULL AUTO_INCREMENT,
+  mkey      varchar(16)   NOT NULL,
+  mvalue    varchar(256)  NOT NULL,
+  PRIMARY KEY(id)
+);
+
+-- Indexes for accessing nodes and triples efficiently
+CREATE INDEX idx_node_content ON nodes(svalue);
+CREATE INDEX idx_literal_lang ON nodes(lang);
+
+CREATE INDEX idx_triples_s ON triples(subject);
+CREATE INDEX idx_triples_o ON triples(object);
+CREATE INDEX idx_triples_sp ON triples(subject,predicate);
+CREATE INDEX idx_triples_po ON triples(predicate,object);
+CREATE INDEX idx_triples_spo ON triples(subject,predicate,object);
+CREATE INDEX idx_triples_cs ON triples(context,subject);
+CREATE INDEX idx_triples_csp ON triples(context,subject,predicate);
+CREATE INDEX idx_triples_cspo ON triples(context,subject,predicate,object);
+
+CREATE INDEX idx_namespaces_uri ON namespaces(uri);
+CREATE INDEX idx_namespaces_prefix ON namespaces(prefix);
+
+-- insert initial metadata
+INSERT INTO metadata(mkey,mvalue) VALUES ('version','1');
+INSERT INTO metadata(mkey,mvalue) VALUES ('created',FORMATDATETIME(now(),'yyyy-MM-dd HH:mm:ss z','en') );
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/drop_base_tables.sql
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/drop_base_tables.sql b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/drop_base_tables.sql
new file mode 100644
index 0000000..f584509
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/drop_base_tables.sql
@@ -0,0 +1,27 @@
+
+DROP INDEX IF EXISTS idx_node_content;
+DROP INDEX idx_literal_lang;
+
+DROP INDEX IF EXISTS idx_triples_s;
+DROP INDEX IF EXISTS idx_triples_o;
+DROP INDEX IF EXISTS idx_triples_sp;
+DROP INDEX IF EXISTS idx_triples_po;
+DROP INDEX IF EXISTS idx_triples_spo;
+DROP INDEX IF EXISTS idx_triples_cs;
+DROP INDEX IF EXISTS idx_triples_csp;
+DROP INDEX IF EXISTS idx_triples_cspo;
+
+DROP INDEX IF EXISTS idx_namespaces_uri;
+DROP INDEX IF EXISTS idx_namespaces_prefix;
+
+
+DROP TABLE IF EXISTS triples;
+DROP TABLE IF EXISTS namespaces;
+DROP TABLE IF EXISTS nodes;
+DROP TABLE IF EXISTS metadata;
+
+DROP SEQUENCE IF EXISTS seq_nodes;
+DROP SEQUENCE IF EXISTS seq_triples;
+DROP SEQUENCE IF EXISTS seq_namespaces;
+
+DROP ALL OBJECTS DELETE FILES;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
new file mode 100644
index 0000000..c2ca835
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
@@ -0,0 +1,72 @@
+#
+# Copyright (C) 2013 Salzburg Research.
+#
+# Licensed 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.
+#
+
+# get metainformation
+meta.tables            = SHOW TABLES;
+meta.version           = SELECT mvalue FROM metadata WHERE mkey = 'version';
+
+# get sequence numbers
+seq.nodes              = SELECT nextval('seq_nodes')
+seq.triples            = SELECT nextval('seq_triples')
+seq.namespaces         = SELECT nextval('seq_namespaces')
+
+# load entities
+load.node_by_id        = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE id = ?
+
+load.uri_by_uri        = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'uri' AND svalue = ?
+
+load.bnode_by_anonid   = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'bnode' AND svalue = ?
+
+load.literal_by_v     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE svalue = ? AND lang IS NULL AND ltype IS NULL
+load.literal_by_vl    = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE svalue = ? AND lang = ?
+load.literal_by_vt    = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE svalue = ? AND ltype = ?
+
+load.literal_by_iv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE ivalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_dv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE dvalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_tv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE tvalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_bv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE bvalue = ? AND lang IS NULL AND ltype = ?
+
+
+load.namespace_prefix  = SELECT id,prefix,uri,createdAt FROM namespaces WHERE prefix = ?;
+load.namespace_uri     = SELECT id,prefix,uri,createdAt FROM namespaces WHERE uri = ?;
+
+load.triple_by_id      = SELECT id,subject,predicate,object,context,deleted,inferred,creator,createdAt,deletedAt FROM triples WHERE id = ?
+
+
+# store entities
+store.uri              = INSERT INTO nodes (id,ntype,svalue,createdAt) VALUES (?,'uri',?,?)
+store.bnode            = INSERT INTO nodes (id,ntype,svalue,createdAt) VALUES (?,'bnode',?,?)
+store.sliteral      = INSERT INTO nodes (id,ntype,svalue,lang,ltype,createdAt) VALUES (?,'string',?,?,?,?)
+
+store.iliteral       = INSERT INTO nodes (id,ntype,svalue,dvalue,ivalue,ltype,createdAt) VALUES (?,'int',?,?,?,?,?)
+store.dliteral       = INSERT INTO nodes (id,ntype,svalue,dvalue,ltype,createdAt) VALUES (?,'double',?,?,?,?)
+store.bliteral       = INSERT INTO nodes (id,ntype,svalue,bvalue,ltype,createdAt) VALUES (?,'boolean',?,?,?,?)
+store.tliteral       = INSERT INTO nodes (id,ntype,svalue,tvalue,ltype,createdAt) VALUES (?,'date',?,?,?,?)
+
+store.namespace      = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES (?,?,?,?)
+
+store.triple         = INSERT INTO triples (id,subject,predicate,object,context,inferred,createdAt) VALUES (?,?,?,?,?,?,?)
+
+
+query.size           = SELECT count(*) FROM triples WHERE deleted = false
+query.size_ctx       = SELECT count(*) FROM triples WHERE context = ? AND deleted = false
+query.contexts       = SELECT DISTINCT context FROM triples WHERE deleted = false
+query.namespaces     = SELECT id,prefix,uri,createdAt FROM namespaces
+
+
+# delete entities
+delete.triple        = UPDATE triples SET deleted = true, deletedAt = now() WHERE id = ?
+delete.namespace     = DELETE FROM namespaces WHERE id = ?

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql
new file mode 100644
index 0000000..30d28ea
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql
@@ -0,0 +1,78 @@
+CREATE TABLE seq_nodes (id BIGINT NOT NULL);
+INSERT INTO seq_nodes(id) VALUES (0);
+
+CREATE TABLE seq_triples (id BIGINT NOT NULL);
+INSERT INTO seq_triples VALUES (0);
+
+CREATE TABLE seq_namespaces (id BIGINT NOT NULL);
+INSERT INTO seq_namespaces(id) VALUES (0);
+
+-- Sequences in MySQL:
+-- UPDATE sequence SET id=LAST_INSERT_ID(id+1);
+-- SELECT LAST_INSERT_ID();
+
+
+CREATE TABLE nodes (
+  id        bigint     NOT NULL,
+  ntype     char(8)    NOT NULL,
+  svalue    text       NOT NULL,
+  dvalue    double precision,
+  ivalue    bigint,
+  tvalue    datetime   DEFAULT NULL,
+  bvalue    boolean,
+  ltype     bigint     REFERENCES nodes(id),
+  lang      varchar(5),
+  createdAt timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  PRIMARY KEY(id)
+) CHARACTER SET utf8 COLLATE utf8_bin;
+
+CREATE TABLE triples (
+  id        bigint     NOT NULL,
+  subject   bigint     NOT NULL REFERENCES nodes(id),
+  predicate bigint     NOT NULL REFERENCES nodes(id),
+  object    bigint     NOT NULL REFERENCES nodes(id),
+  context   bigint     NOT NULL REFERENCES nodes(id),
+  creator   bigint     REFERENCES nodes(id),
+  inferred  boolean    DEFAULT false,
+  deleted   boolean    DEFAULT false,
+  createdAt timestamp  NOT NULL DEFAULT now(),
+  deletedAt timestamp,
+  PRIMARY KEY(id)
+) CHARACTER SET utf8 COLLATE utf8_bin;
+
+CREATE TABLE namespaces (
+  id        bigint        NOT NULL,
+  prefix    varchar(256)  NOT NULL,
+  uri       varchar(2048) NOT NULL,
+  createdAt timestamp     NOT NULL DEFAULT now(),
+  PRIMARY KEY(id)
+) CHARACTER SET utf8 COLLATE utf8_bin;
+
+
+-- A table for storing metadata about the current database, e.g. version numbers for each table
+CREATE TABLE metadata (
+  id        integer       NOT NULL AUTO_INCREMENT,
+  mkey      varchar(16)   NOT NULL,
+  mvalue    varchar(256)  NOT NULL,
+  PRIMARY KEY(id)
+) CHARACTER SET utf8 COLLATE utf8_bin;
+
+-- Indexes for accessing nodes and triples efficiently
+CREATE INDEX idx_node_content ON nodes(svalue(256));
+CREATE INDEX idx_literal_lang ON nodes(lang);
+
+CREATE INDEX idx_triples_s ON triples(subject);
+CREATE INDEX idx_triples_o ON triples(object);
+CREATE INDEX idx_triples_sp ON triples(subject,predicate);
+CREATE INDEX idx_triples_po ON triples(predicate,object);
+CREATE INDEX idx_triples_spo ON triples(subject,predicate,object);
+CREATE INDEX idx_triples_cs ON triples(context,subject);
+CREATE INDEX idx_triples_csp ON triples(context,subject,predicate);
+CREATE INDEX idx_triples_cspo ON triples(context,subject,predicate,object);
+
+CREATE INDEX idx_namespaces_uri ON namespaces(uri);
+CREATE INDEX idx_namespaces_prefix ON namespaces(prefix);
+
+-- insert initial metadata
+INSERT INTO metadata(mkey,mvalue) VALUES ('version','1');
+INSERT INTO metadata(mkey,mvalue) VALUES ('created',DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s') );

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/drop_base_tables.sql
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/drop_base_tables.sql b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/drop_base_tables.sql
new file mode 100644
index 0000000..48f8c2e
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/drop_base_tables.sql
@@ -0,0 +1,26 @@
+
+DROP INDEX idx_node_content ON nodes;
+DROP INDEX idx_literal_lang ON nodes;
+
+DROP INDEX idx_triples_s ON triples;
+DROP INDEX idx_triples_o ON triples;
+DROP INDEX idx_triples_sp ON triples;
+DROP INDEX idx_triples_po ON triples;
+DROP INDEX idx_triples_spo ON triples;
+DROP INDEX idx_triples_cs ON triples;
+DROP INDEX idx_triples_csp ON triples;
+DROP INDEX idx_triples_cspo ON triples;
+
+DROP INDEX idx_namespaces_uri ON namespaces;
+DROP INDEX idx_namespaces_prefix ON namespaces;
+
+
+DROP TABLE IF EXISTS triples;
+DROP TABLE IF EXISTS namespaces;
+DROP TABLE IF EXISTS nodes;
+DROP TABLE IF EXISTS metadata;
+
+DROP TABLE IF EXISTS seq_nodes;
+DROP TABLE IF EXISTS seq_triples;
+DROP TABLE IF EXISTS seq_namespaces;
+

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
new file mode 100644
index 0000000..139ffa4
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
@@ -0,0 +1,76 @@
+#
+# Copyright (C) 2013 Salzburg Research.
+#
+# Licensed 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.
+#
+
+# get metainformation
+meta.tables            = SHOW TABLES;
+meta.version           = SELECT mvalue FROM metadata WHERE mkey = 'version';
+
+# get sequence numbers
+seq.nodes.prep         = UPDATE seq_nodes SET id=LAST_INSERT_ID(id+1);
+seq.nodes              = SELECT LAST_INSERT_ID();
+
+seq.triples.prep       = UPDATE seq_triples SET id=LAST_INSERT_ID(id+1);
+seq.triples            = SELECT LAST_INSERT_ID();
+
+seq.namespaces.prep    = UPDATE seq_namespaces SET id=LAST_INSERT_ID(id+1);
+seq.namespaces         = SELECT LAST_INSERT_ID();
+
+# load entities
+load.node_by_id        = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE id = ?
+
+load.uri_by_uri        = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'uri' AND svalue = ?
+
+load.bnode_by_anonid   = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'bnode' AND svalue = ?
+
+load.literal_by_v     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE ntype='string' AND svalue = ? AND lang IS NULL AND ltype IS NULL
+load.literal_by_vl    = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE svalue = ? AND lang = ?
+load.literal_by_vt    = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE svalue = ? AND ltype = ?
+
+load.literal_by_iv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE ivalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_dv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE dvalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_tv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE tvalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_bv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE bvalue = ? AND lang IS NULL AND ltype = ?
+
+
+load.namespace_prefix  = SELECT id,prefix,uri,createdAt FROM namespaces WHERE prefix = ?;
+load.namespace_uri     = SELECT id,prefix,uri,createdAt FROM namespaces WHERE uri = ?;
+
+load.triple_by_id      = SELECT id,subject,predicate,object,context,deleted,inferred,creator,createdAt,deletedAt FROM triples WHERE id = ?
+
+
+# store entities
+store.uri              = INSERT INTO nodes (id,ntype,svalue,createdAt) VALUES (?,'uri',?,?)
+store.bnode            = INSERT INTO nodes (id,ntype,svalue,createdAt) VALUES (?,'bnode',?,?)
+store.sliteral      = INSERT INTO nodes (id,ntype,svalue,lang,ltype,createdAt) VALUES (?,'string',?,?,?,?)
+
+store.iliteral       = INSERT INTO nodes (id,ntype,svalue,dvalue,ivalue,ltype,createdAt) VALUES (?,'int',?,?,?,?,?)
+store.dliteral       = INSERT INTO nodes (id,ntype,svalue,dvalue,ltype,createdAt) VALUES (?,'double',?,?,?,?)
+store.bliteral       = INSERT INTO nodes (id,ntype,svalue,bvalue,ltype,createdAt) VALUES (?,'boolean',?,?,?,?)
+store.tliteral       = INSERT INTO nodes (id,ntype,svalue,tvalue,ltype,createdAt) VALUES (?,'date',?,?,?,?)
+
+store.namespace      = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES (?,?,?,?)
+
+store.triple         = INSERT INTO triples (id,subject,predicate,object,context,inferred,createdAt) VALUES (?,?,?,?,?,?,?)
+
+
+query.size           = SELECT count(*) FROM triples WHERE deleted = false
+query.size_ctx       = SELECT count(*) FROM triples WHERE context = ? AND deleted = false
+query.contexts       = SELECT DISTINCT context FROM triples WHERE deleted = false
+query.namespaces     = SELECT id,prefix,uri,createdAt FROM namespaces
+
+# delete entities
+delete.triple        = UPDATE triples SET deleted = true, deletedAt = now() WHERE id = ?
+delete.namespace     = DELETE FROM namespaces WHERE id = ?

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql
new file mode 100644
index 0000000..1d90ef7
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql
@@ -0,0 +1,73 @@
+CREATE SEQUENCE seq_nodes;
+CREATE SEQUENCE seq_triples;
+CREATE SEQUENCE seq_namespaces;
+
+CREATE TYPE nodetype AS ENUM ('uri','bnode','string','int','double','date','boolean');
+
+CREATE TABLE nodes (
+  id        bigint     NOT NULL,
+  ntype     nodetype   NOT NULL,
+  svalue    text       NOT NULL,
+  dvalue    double precision,
+  ivalue    bigint,
+  tvalue    timestamp,
+  bvalue    boolean,
+  ltype     bigint     REFERENCES nodes(id),
+  lang      varchar(5),
+  createdAt timestamp  NOT NULL DEFAULT now(),
+  PRIMARY KEY(id)
+);
+
+CREATE TABLE triples (
+  id        bigint     NOT NULL,
+  subject   bigint     NOT NULL REFERENCES nodes(id),
+  predicate bigint     NOT NULL REFERENCES nodes(id),
+  object    bigint     NOT NULL REFERENCES nodes(id),
+  context   bigint     NOT NULL REFERENCES nodes(id),
+  creator   bigint     REFERENCES nodes(id),
+  inferred  boolean    DEFAULT false,
+  deleted   boolean    DEFAULT false,
+  createdAt timestamp  NOT NULL DEFAULT now(),
+  deletedAt timestamp,
+  PRIMARY KEY(id),
+  CHECK ( (deleted AND deletedAt IS NOT NULL) OR ((NOT deleted) AND deletedAt IS NULL) )
+);
+
+CREATE TABLE namespaces (
+  id        bigint        NOT NULL,
+  prefix    varchar(256)  NOT NULL,
+  uri       varchar(2048) NOT NULL,
+  createdAt timestamp  NOT NULL DEFAULT now(),
+  PRIMARY KEY(id)
+);
+
+-- A table for storing metadata about the current database, e.g. version numbers for each table
+CREATE TABLE metadata (
+  id        serial        NOT NULL,
+  mkey      varchar(16)   NOT NULL,
+  mvalue    varchar(256)  NOT NULL,
+  PRIMARY KEY(id)
+);
+
+-- Indexes for accessing nodes and triples efficiently
+CREATE INDEX idx_node_content ON nodes USING hash(svalue);
+CREATE INDEX idx_literal_lang ON nodes(lang) WHERE ntype = 'string';
+
+CREATE INDEX idx_triples_s ON triples(subject) WHERE deleted = false;
+CREATE INDEX idx_triples_o ON triples(object) WHERE deleted = false;
+CREATE INDEX idx_triples_sp ON triples(subject,predicate) WHERE deleted = false;
+CREATE INDEX idx_triples_po ON triples(predicate,object) WHERE deleted = false;
+CREATE INDEX idx_triples_spo ON triples(subject,predicate,object) WHERE deleted = false;
+CREATE INDEX idx_triples_cs ON triples(context,subject) WHERE deleted = false;
+CREATE INDEX idx_triples_csp ON triples(context,subject,predicate) WHERE deleted = false;
+CREATE INDEX idx_triples_cspo ON triples(context,subject,predicate,object) WHERE deleted = false;
+
+CREATE INDEX idx_namespaces_uri ON namespaces(uri);
+CREATE INDEX idx_namespaces_prefix ON namespaces(prefix);
+
+
+-- a function for cleaning up table rows without incoming references
+
+-- insert initial metadata
+INSERT INTO metadata(mkey,mvalue) VALUES ('version','1');
+INSERT INTO metadata(mkey,mvalue) VALUES ('created',to_char(now(),'yyyy-MM-DD HH:mm:ss TZ') );
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/drop_base_tables.sql
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/drop_base_tables.sql b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/drop_base_tables.sql
new file mode 100644
index 0000000..4ed55ff
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/drop_base_tables.sql
@@ -0,0 +1,27 @@
+DROP INDEX idx_node_content;
+DROP INDEX idx_literal_lang;
+
+DROP INDEX idx_triples_s;
+DROP INDEX idx_triples_o;
+DROP INDEX idx_triples_sp;
+DROP INDEX idx_triples_po;
+DROP INDEX idx_triples_spo;
+DROP INDEX idx_triples_cs;
+DROP INDEX idx_triples_csp;
+DROP INDEX idx_triples_cspo;
+
+DROP INDEX idx_namespaces_uri;
+DROP INDEX idx_namespaces_prefix;
+
+
+DROP TABLE IF EXISTS triples;
+DROP TABLE IF EXISTS namespaces;
+DROP TABLE IF EXISTS nodes;
+DROP TABLE IF EXISTS metadata;
+
+DROP SEQUENCE IF EXISTS seq_nodes;
+DROP SEQUENCE IF EXISTS seq_triples;
+DROP SEQUENCE IF EXISTS seq_namespaces;
+
+DROP TYPE IF EXISTS nodetype;
+

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
new file mode 100644
index 0000000..2c77bdd
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
@@ -0,0 +1,68 @@
+#
+# Copyright (C) 2013 Salzburg Research.
+#
+# Licensed 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.
+#
+
+# get metainformation
+meta.tables            = select tablename from pg_tables where schemaname='public';
+meta.version           = SELECT mvalue FROM metadata WHERE mkey = 'version';
+
+# get sequence numbers
+seq.nodes              = SELECT nextval('seq_nodes')
+seq.triples            = SELECT nextval('seq_triples')
+seq.namespaces         = SELECT nextval('seq_namespaces')
+
+# load entities
+load.node_by_id        = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE id = ?
+
+load.uri_by_uri        = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'uri' AND svalue = ?
+
+load.bnode_by_anonid   = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'bnode' AND svalue = ?
+
+load.literal_by_v     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE svalue = ? AND lang IS NULL AND ltype IS NULL
+load.literal_by_vl    = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE svalue = ? AND lang = ?
+load.literal_by_vt    = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE svalue = ? AND ltype = ?
+
+load.literal_by_iv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE ivalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_dv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE dvalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_tv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE tvalue = ? AND lang IS NULL AND ltype = ?
+load.literal_by_bv     = SELECT id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes WHERE bvalue = ? AND lang IS NULL AND ltype = ?
+
+load.namespace_prefix  = SELECT id,prefix,uri,createdAt FROM namespaces WHERE prefix = ?;
+load.namespace_uri     = SELECT id,prefix,uri,createdAt FROM namespaces WHERE uri = ?;
+
+load.triple_by_id      = SELECT id,subject,predicate,object,context,deleted,inferred,creator,createdAt,deletedAt FROM triples WHERE id = ?
+
+# store entities
+store.uri              = INSERT INTO nodes (id,ntype,svalue,createdAt) VALUES (?,'uri',?,?)
+store.bnode            = INSERT INTO nodes (id,ntype,svalue,createdAt) VALUES (?,'bnode',?,?)
+store.sliteral       = INSERT INTO nodes (id,ntype,svalue,lang,ltype,createdAt) VALUES (?,'string',?,?,?,?)
+
+store.iliteral       = INSERT INTO nodes (id,ntype,svalue,dvalue,ivalue,ltype,createdAt) VALUES (?,'int',?,?,?,?,?)
+store.dliteral       = INSERT INTO nodes (id,ntype,svalue,dvalue,ltype,createdAt) VALUES (?,'double',?,?,?,?)
+store.bliteral       = INSERT INTO nodes (id,ntype,svalue,bvalue,ltype,createdAt) VALUES (?,'boolean',?,?,?,?)
+store.tliteral       = INSERT INTO nodes (id,ntype,svalue,tvalue,ltype,createdAt) VALUES (?,'date',?,?,?,?)
+
+store.namespace      = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES (?,?,?,?)
+
+store.triple         = INSERT INTO triples (id,subject,predicate,object,context,inferred,createdAt) VALUES (?,?,?,?,?,?,?)
+
+query.size           = SELECT count(*) FROM triples WHERE deleted = false
+query.size_ctx       = SELECT count(*) FROM triples WHERE context = ? AND deleted = false
+query.contexts       = SELECT DISTINCT context FROM triples WHERE deleted = false
+query.namespaces     = SELECT id,prefix,uri,createdAt FROM namespaces
+
+# delete entities
+delete.triple        = UPDATE triples SET deleted = true, deletedAt = now() WHERE id = ?
+delete.namespace     = DELETE FROM namespaces WHERE id = ?

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java b/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java
new file mode 100644
index 0000000..97651ec
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2013 Salzburg Research.
+ *
+ *  Licensed 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.kiwi.test;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
+import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect;
+import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Test if the dialects returns correct values
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+@RunWith(Parameterized.class)
+public class DialectTest {
+
+    public KiWiDialect dialect;
+
+
+    /**
+     * Return database configurations if the appropriate parameters have been set.
+     *
+     * @return an array (database name)
+     */
+    @Parameterized.Parameters(name="Database Test {index}: {0}")
+    public static Iterable<Object[]> databases() {
+        String[] databases = {"H2", "PostgreSQL", "MySQL"};
+
+        List<Object[]> result = new ArrayList<Object[]>(databases.length);
+        for(String database : databases) {
+                result.add(new Object[] {
+                        database
+                });
+        }
+        return result;
+    }
+
+    public DialectTest(String database) {
+        if("H2".equals(database)) {
+            this.dialect = new H2Dialect();
+        } else if("MySQL".equals(database)) {
+            this.dialect = new MySQLDialect();
+        } else if("PostgreSQL".equals(database)) {
+            this.dialect = new PostgreSQLDialect();
+        }
+    }
+
+    @Test
+    public void testListProperties() {
+        Set<String> keys = dialect.getStatementIdentifiers();
+
+        Assert.assertThat(keys,hasItem("load.node_by_id"));
+
+    }
+
+
+    @Test
+    public void testGetStatement() {
+        String queryVersion = dialect.getStatement("meta.version");
+
+        Assert.assertEquals("SELECT mvalue FROM metadata WHERE mkey = 'version';", queryVersion);
+    }
+
+
+    @Test
+    public void testGetCreateScript() {
+        String createScript = dialect.getCreateScript("base");
+
+        Assert.assertNotNull(createScript);
+        Assert.assertFalse("".equals(createScript));
+    }
+
+
+    @Test
+    public void testGetMigrateScript() {
+        String migrateScript = dialect.getMigrationScript(1,"base");
+
+        Assert.assertNotNull(migrateScript);
+        Assert.assertTrue("".equals(migrateScript));
+    }
+
+
+
+
+}