KiWi:
- implement a different model for representing datetime with timezone 
(MARMOTTA-564)


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/7a824559
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/7a824559
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/7a824559

Branch: refs/heads/develop
Commit: 7a824559431331e008abd42421418f7bbe032d30
Parents: 7f80dbd
Author: Sebastian Schaffert <[email protected]>
Authored: Mon Nov 10 18:03:43 2014 +0100
Committer: Sebastian Schaffert <[email protected]>
Committed: Mon Nov 10 18:39:34 2014 +0100

----------------------------------------------------------------------
 commons/marmotta-commons/pom.xml                |  5 ++
 .../commons/sesame/model/LiteralCommons.java    | 12 ++--
 .../apache/marmotta/commons/util/DateUtils.java | 18 ++++-
 .../sesame/model/LiteralCommonsTest.java        |  3 +-
 .../kiwi/loader/generic/KiWiHandler.java        |  5 +-
 .../kiwi/loader/mysql/MySQLLoadUtil.java        | 44 +++++-------
 .../marmotta/kiwi/loader/pgsql/PGCopyUtil.java  | 26 +++----
 .../marmotta/kiwi/loader/PGCopyUtilTest.java    |  8 ++-
 .../kiwi/sparql/builder/SQLBuilder.java         |  1 +
 .../marmotta/kiwi/sparql/builder/ValueType.java | 12 +++-
 .../builder/eval/ValueExpressionEvaluator.java  |  4 ++
 .../kiwi/sparql/function/datetime/NDay.java     |  2 +-
 .../kiwi/sparql/function/datetime/NHours.java   |  2 +-
 .../kiwi/sparql/function/datetime/NMinutes.java |  2 +-
 .../kiwi/sparql/function/datetime/NMonth.java   |  2 +-
 .../kiwi/sparql/function/datetime/NSeconds.java |  2 +-
 .../kiwi/sparql/function/datetime/NYear.java    |  2 +-
 libraries/kiwi/kiwi-triplestore/pom.xml         |  5 ++
 .../org/apache/marmotta/kiwi/io/KiWiIO.java     |  7 +-
 .../kiwi/model/rdf/KiWiDateLiteral.java         | 35 ++++-----
 .../kiwi/model/rdf/KiWiDoubleLiteral.java       | 14 +++-
 .../kiwi/persistence/KiWiConnection.java        | 75 +++++++++++---------
 .../marmotta/kiwi/persistence/KiWiDialect.java  | 10 ++-
 .../marmotta/kiwi/persistence/h2/H2Dialect.java | 12 ++++
 .../kiwi/persistence/mysql/MySQLDialect.java    | 13 ++++
 .../persistence/pgsql/PostgreSQLDialect.java    | 12 ++++
 .../marmotta/kiwi/sail/KiWiValueFactory.java    | 20 +++---
 .../kiwi/persistence/h2/create_base_tables.sql  |  3 +-
 .../kiwi/persistence/h2/statements.properties   | 24 +++----
 .../persistence/h2/upgrade_base_003_004.sql     | 16 +++++
 .../persistence/mysql/create_base_tables.sql    |  3 +-
 .../persistence/mysql/statements.properties     | 24 +++----
 .../persistence/mysql/upgrade_base_003_004.sql  | 16 +++++
 .../persistence/pgsql/create_base_tables.sql    |  3 +-
 .../persistence/pgsql/statements.properties     | 24 +++----
 .../persistence/pgsql/upgrade_base_003_004.sql  | 16 +++++
 .../apache/marmotta/kiwi/test/DialectTest.java  | 10 +--
 .../marmotta/kiwi/test/PersistenceTest.java     | 14 ++--
 .../marmotta/kiwi/test/TestValueFactory.java    |  8 ++-
 parent/pom.xml                                  | 10 ++-
 40 files changed, 337 insertions(+), 187 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/commons/marmotta-commons/pom.xml
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/pom.xml b/commons/marmotta-commons/pom.xml
index 5735f6b..9104224 100644
--- a/commons/marmotta-commons/pom.xml
+++ b/commons/marmotta-commons/pom.xml
@@ -117,6 +117,11 @@
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>commons-validator</groupId>
             <artifactId>commons-validator</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/LiteralCommons.java
----------------------------------------------------------------------
diff --git 
a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/LiteralCommons.java
 
b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/LiteralCommons.java
index a847c6b..ab54cd6 100644
--- 
a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/LiteralCommons.java
+++ 
b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/LiteralCommons.java
@@ -19,6 +19,7 @@ package org.apache.marmotta.commons.sesame.model;
 
 import com.google.common.hash.Hasher;
 import com.google.common.hash.Hashing;
+import org.joda.time.DateTime;
 import org.openrdf.model.Literal;
 import org.openrdf.model.URI;
 
@@ -29,7 +30,6 @@ import java.nio.charset.Charset;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
-import java.util.TimeZone;
 
 /**
  * Utility methods for working with literals.
@@ -83,12 +83,10 @@ public class LiteralCommons {
      * @param type datatype URI of the literal
      * @return a 64bit hash key for the literal
      */
-    public static final String createCacheKey(Date date, String type) {
-        GregorianCalendar cal = new 
GregorianCalendar(TimeZone.getTimeZone("UTC"));
-        cal.setTime(date);
+    public static final String createCacheKey(DateTime date, String type) {
+        GregorianCalendar cal = date.toGregorianCalendar();
 
-        XMLGregorianCalendar xml_cal = 
dtf.newXMLGregorianCalendar(cal).normalize();
-        xml_cal.setTimezone(0);
+        XMLGregorianCalendar xml_cal = dtf.newXMLGregorianCalendar(cal);
 
         return createCacheKey(xml_cal.toXMLFormat(), (String)null, type);
     }
@@ -141,7 +139,7 @@ public class LiteralCommons {
             return Namespaces.NS_XSD+"double";
         } else if(Float.class.isAssignableFrom(javaClass) || 
float.class.isAssignableFrom(javaClass)) {
             return Namespaces.NS_XSD+"float";
-        } else if(Date.class.isAssignableFrom(javaClass)) {
+        } else if(Date.class.isAssignableFrom(javaClass) || 
DateTime.class.isAssignableFrom(javaClass)) {
             return Namespaces.NS_XSD+"dateTime";
         } else if(Boolean.class.isAssignableFrom(javaClass) || 
boolean.class.isAssignableFrom(javaClass)) {
             return Namespaces.NS_XSD+"boolean";

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/util/DateUtils.java
----------------------------------------------------------------------
diff --git 
a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/util/DateUtils.java
 
b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/util/DateUtils.java
index b025e7a..fa42508 100644
--- 
a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/util/DateUtils.java
+++ 
b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/util/DateUtils.java
@@ -17,6 +17,8 @@
  */
 package org.apache.marmotta.commons.util;
 
+import org.joda.time.DateTime;
+
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.XMLGregorianCalendar;
@@ -157,7 +159,7 @@ public class DateUtils {
         c.setTimeZone(TimeZone.getTimeZone("UTC"));
         c.setTime(date);
         try {
-            return getDatatypeFactory().newXMLGregorianCalendar(c).normalize();
+            return getDatatypeFactory().newXMLGregorianCalendar(c);
         } catch (DatatypeConfigurationException e) {
             return null;
         }
@@ -173,4 +175,18 @@ public class DateUtils {
         long seconds = date.getTime() / 1000L;
         return new Date(seconds * 1000L);
     }
+
+    /**
+     * Transform a Java date into a XML calendar. Useful for working with date 
literals.
+     * @param date
+     * @return
+     */
+    public static XMLGregorianCalendar getXMLCalendar(DateTime date) {
+        GregorianCalendar c = date.toGregorianCalendar();
+        try {
+            return getDatatypeFactory().newXMLGregorianCalendar(c);
+        } catch (DatatypeConfigurationException e) {
+            return null;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/sesame/model/LiteralCommonsTest.java
----------------------------------------------------------------------
diff --git 
a/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/sesame/model/LiteralCommonsTest.java
 
b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/sesame/model/LiteralCommonsTest.java
index 3199050..79da89b 100644
--- 
a/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/sesame/model/LiteralCommonsTest.java
+++ 
b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/sesame/model/LiteralCommonsTest.java
@@ -19,6 +19,7 @@ package org.apache.marmotta.commons.sesame.model;
 
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.marmotta.commons.util.DateUtils;
+import org.joda.time.DateTime;
 import org.junit.Assert;
 import org.junit.Test;
 import org.openrdf.model.Literal;
@@ -83,7 +84,7 @@ public class LiteralCommonsTest {
 
 
         // create a Date literal and test whether the hash key is correct 
between the different methods
-        Date value4 = new Date();
+        DateTime value4 = DateTime.now();
         String datatype4 = LiteralCommons.getXSDType(value4.getClass());
         Literal literal4 = vf.createLiteral(DateUtils.getXMLCalendar(value4));
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
 
b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
index 38cb456..8701dfe 100644
--- 
a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
+++ 
b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
@@ -21,7 +21,6 @@ import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import org.apache.marmotta.commons.sesame.model.Namespaces;
 import org.apache.marmotta.commons.sesame.tripletable.IntArray;
-import org.apache.marmotta.commons.util.DateUtils;
 import org.apache.marmotta.kiwi.loader.KiWiLoaderConfiguration;
 import org.apache.marmotta.kiwi.model.rdf.*;
 import org.apache.marmotta.kiwi.persistence.KiWiConnection;
@@ -30,6 +29,8 @@ import 
org.apache.marmotta.kiwi.persistence.registry.DBTripleRegistry;
 import org.apache.marmotta.kiwi.persistence.registry.KiWiTripleRegistry;
 import org.apache.marmotta.kiwi.persistence.registry.LocalTripleRegistry;
 import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.joda.time.DateTime;
+import org.joda.time.format.ISODateTimeFormat;
 import org.openrdf.model.*;
 import org.openrdf.model.impl.URIImpl;
 import org.openrdf.rio.RDFHandler;
@@ -354,7 +355,7 @@ public class KiWiHandler implements RDFHandler {
                     }
                 } else if(type.equals(Namespaces.NS_XSD+"dateTime") || 
type.equals(Namespaces.NS_XSD+"date") || type.equals(Namespaces.NS_XSD+"time")) 
{
                     // parse if necessary
-                    final Date dvalue = DateUtils.parseDate(value.toString());
+                    final DateTime dvalue = 
ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(value.toString());
 
                     result = connection.loadLiteral(dvalue);
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/mysql/MySQLLoadUtil.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/mysql/MySQLLoadUtil.java
 
b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/mysql/MySQLLoadUtil.java
index 957800d..85d1343 100644
--- 
a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/mysql/MySQLLoadUtil.java
+++ 
b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/mysql/MySQLLoadUtil.java
@@ -19,20 +19,8 @@ package org.apache.marmotta.kiwi.loader.mysql;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.math.NumberUtils;
-import org.apache.marmotta.kiwi.loader.csv.LanguageProcessor;
-import org.apache.marmotta.kiwi.loader.csv.NodeIDProcessor;
-import org.apache.marmotta.kiwi.loader.csv.NodeTypeProcessor;
-import org.apache.marmotta.kiwi.loader.csv.SQLBooleanProcessor;
-import org.apache.marmotta.kiwi.loader.csv.SQLTimestampProcessor;
-import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
-import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.apache.marmotta.kiwi.loader.csv.*;
+import org.apache.marmotta.kiwi.model.rdf.*;
 import org.openrdf.model.URI;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -68,6 +56,7 @@ public class MySQLLoadUtil {
             new Optional(),                           // dvalue
             new Optional(),                           // ivalue
             new SQLTimestampProcessor(),              // tvalue
+            new Optional(),                           // tzoffset
             new Optional(new SQLBooleanProcessor()),  // bvalue
             new Optional(new NodeIDProcessor()),      // ltype
             new Optional(new LanguageProcessor()),    // lang
@@ -140,28 +129,28 @@ public class MySQLLoadUtil {
         CsvListWriter writer = new CsvListWriter(out, nodesPreference);
 
         // reuse the same array to avoid unnecessary object allocation
-        Object[] rowArray = new Object[10];
+        Object[] rowArray = new Object[11];
         List<Object> row = Arrays.asList(rowArray);
 
         for(KiWiNode n : nodeBacklog) {
             if(n instanceof KiWiUriResource) {
                 KiWiUriResource u = (KiWiUriResource)n;
-                createNodeList(rowArray, u.getId(), u.getClass(), 
u.stringValue(), null, null, null, null, null, null, u.getCreated());
+                createNodeList(rowArray, u.getId(), u.getClass(), 
u.stringValue(), null, null, null, null, null, null, null, u.getCreated());
             } else if(n instanceof KiWiAnonResource) {
                 KiWiAnonResource a = (KiWiAnonResource)n;
-                createNodeList(rowArray, a.getId(), a.getClass(), 
a.stringValue(), null, null, null, null, null, null, a.getCreated());
+                createNodeList(rowArray, a.getId(), a.getClass(), 
a.stringValue(), null, null, null, null, null, null, null, a.getCreated());
             } else if(n instanceof KiWiIntLiteral) {
                 KiWiIntLiteral l = (KiWiIntLiteral)n;
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), l.getDoubleContent(), l.getIntContent(), null, null, 
l.getDatatype(), l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), l.getDoubleContent(), l.getIntContent(), null, null, null, 
l.getDatatype(), l.getLocale(), l.getCreated());
             } else if(n instanceof KiWiDoubleLiteral) {
                 KiWiDoubleLiteral l = (KiWiDoubleLiteral)n;
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), l.getDoubleContent(), null, null, null, l.getDatatype(), 
l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), l.getDoubleContent(), null, null, null, null, l.getDatatype(), 
l.getLocale(), l.getCreated());
             } else if(n instanceof KiWiBooleanLiteral) {
                 KiWiBooleanLiteral l = (KiWiBooleanLiteral)n;
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), null, null, null, l.booleanValue(), l.getDatatype(), 
l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), null, null, null, null, l.booleanValue(), l.getDatatype(), 
l.getLocale(), l.getCreated());
             } else if(n instanceof KiWiDateLiteral) {
                 KiWiDateLiteral l = (KiWiDateLiteral)n;
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), null, null, l.getDateContent(), null, l.getDatatype(), 
l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), null, null, l.getDateContent().toDate(), 
l.getDateContent().getZone().getOffset(l.getDateContent()), null, 
l.getDatatype(), l.getLocale(), l.getCreated());
             } else if(n instanceof KiWiStringLiteral) {
                 KiWiStringLiteral l = (KiWiStringLiteral)n;
 
@@ -175,7 +164,7 @@ public class MySQLLoadUtil {
                         // ignore, keep NaN
                     }
                 }
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), dbl_value, lng_value, null, null, l.getDatatype(), 
l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), dbl_value, lng_value, null, null, null, l.getDatatype(), 
l.getLocale(), l.getCreated());
             } else {
                 log.warn("unknown node type, cannot flush to import stream: 
{}", n.getClass());
             }
@@ -187,17 +176,18 @@ public class MySQLLoadUtil {
         return IOUtils.toInputStream(out.toString());
     }
 
-    private static void createNodeList(Object[] a, Long id, Class type, String 
content, Double dbl, Long lng, Date date, Boolean bool, URI dtype, Locale lang, 
Date created) {
+    private static void createNodeList(Object[] a, Long id, Class type, String 
content, Double dbl, Long lng, Date date, Integer tzoffset, Boolean bool, URI 
dtype, Locale lang, Date created) {
         a[0] = id;
         a[1] = type;
         a[2] = content;
         a[3] = dbl;
         a[4] = lng;
         a[5] = date;
-        a[6] = bool;
-        a[7] = dtype;
-        a[8] = lang;
-        a[9] = created;
+        a[6] = tzoffset;
+        a[7] = bool;
+        a[8] = dtype;
+        a[9] = lang;
+        a[10] = created;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/pgsql/PGCopyUtil.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/pgsql/PGCopyUtil.java
 
b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/pgsql/PGCopyUtil.java
index 31936cc..3a38196 100644
--- 
a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/pgsql/PGCopyUtil.java
+++ 
b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/pgsql/PGCopyUtil.java
@@ -58,6 +58,7 @@ public class PGCopyUtil {
             new Optional(),                           // dvalue
             new Optional(),                           // ivalue
             new SQLTimestampProcessor(),              // tvalue
+            new Optional(),                           // tzoffset
             new Optional(new SQLBooleanProcessor()),  // bvalue
             new Optional(new NodeIDProcessor()),      // ltype
             new Optional(new LanguageProcessor()),    // lang
@@ -145,22 +146,22 @@ public class PGCopyUtil {
         for(KiWiNode n : nodeBacklog) {
             if(n instanceof KiWiUriResource) {
                 KiWiUriResource u = (KiWiUriResource)n;
-                createNodeList(rowArray, u.getId(), u.getClass(), 
u.stringValue(), null, null, null, null, null, null, u.getCreated());
+                createNodeList(rowArray, u.getId(), u.getClass(), 
u.stringValue(), null, null, null, null, null, null, null, u.getCreated());
             } else if(n instanceof KiWiAnonResource) {
                 KiWiAnonResource a = (KiWiAnonResource)n;
-                createNodeList(rowArray, a.getId(), a.getClass(), 
a.stringValue(), null, null, null, null, null, null, a.getCreated());
+                createNodeList(rowArray, a.getId(), a.getClass(), 
a.stringValue(), null, null, null, null, null, null, null, a.getCreated());
             } else if(n instanceof KiWiIntLiteral) {
                 KiWiIntLiteral l = (KiWiIntLiteral)n;
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), l.getDoubleContent(), l.getIntContent(), null, null, 
l.getDatatype(), l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), l.getDoubleContent(), l.getIntContent(), null, null, null, 
l.getDatatype(), l.getLocale(), l.getCreated());
             } else if(n instanceof KiWiDoubleLiteral) {
                 KiWiDoubleLiteral l = (KiWiDoubleLiteral)n;
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), l.getDoubleContent(), null, null, null, l.getDatatype(), 
l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), l.getDoubleContent(), null, null, null, null, l.getDatatype(), 
l.getLocale(), l.getCreated());
             } else if(n instanceof KiWiBooleanLiteral) {
                 KiWiBooleanLiteral l = (KiWiBooleanLiteral)n;
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), null, null, null, l.booleanValue(), l.getDatatype(), 
l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), null, null, null, null, l.booleanValue(), l.getDatatype(), 
l.getLocale(), l.getCreated());
             } else if(n instanceof KiWiDateLiteral) {
                 KiWiDateLiteral l = (KiWiDateLiteral)n;
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), null, null, l.getDateContent(), null, l.getDatatype(), 
l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), null, null, l.getDateContent().toDate(), 
l.getDateContent().getZone().getOffset(l.getDateContent()), null, 
l.getDatatype(), l.getLocale(), l.getCreated());
             } else if(n instanceof KiWiStringLiteral) {
                 KiWiStringLiteral l = (KiWiStringLiteral)n;
 
@@ -174,7 +175,7 @@ public class PGCopyUtil {
                         // ignore, keep NaN
                     }
                 }
-                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), dbl_value, lng_value, null, null, l.getDatatype(), 
l.getLocale(), l.getCreated());
+                createNodeList(rowArray, l.getId(), l.getClass(), 
l.getContent(), dbl_value, lng_value, null, null, null, l.getDatatype(), 
l.getLocale(), l.getCreated());
             } else {
                 log.warn("unknown node type, cannot flush to import stream: 
{}", n.getClass());
             }
@@ -184,16 +185,17 @@ public class PGCopyUtil {
         writer.close();
     }
 
-    private static void createNodeList(Object[] a, Long id, Class type, String 
content, Double dbl, Long lng, Date date, Boolean bool, URI dtype, Locale lang, 
Date created) {
+    private static void createNodeList(Object[] a, Long id, Class type, String 
content, Double dbl, Long lng, Date date, Integer tzoffset, Boolean bool, URI 
dtype, Locale lang, Date created) {
         a[0] = id;
         a[1] = type;
         a[2] = content;
         a[3] = dbl;
         a[4] = lng;
         a[5] = date;
-        a[6] = bool;
-        a[7] = dtype;
-        a[8] = lang != null ? lang.getLanguage() : "";
-        a[9] = created;
+        a[6] = tzoffset;
+        a[7] = bool;
+        a[8] = dtype;
+        a[9] = lang != null ? lang.getLanguage() : "";
+        a[10] = created;
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-loader/src/test/java/org/apache/marmotta/kiwi/loader/PGCopyUtilTest.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-loader/src/test/java/org/apache/marmotta/kiwi/loader/PGCopyUtilTest.java
 
b/libraries/kiwi/kiwi-loader/src/test/java/org/apache/marmotta/kiwi/loader/PGCopyUtilTest.java
index 1400c4f..37607e6 100644
--- 
a/libraries/kiwi/kiwi-loader/src/test/java/org/apache/marmotta/kiwi/loader/PGCopyUtilTest.java
+++ 
b/libraries/kiwi/kiwi-loader/src/test/java/org/apache/marmotta/kiwi/loader/PGCopyUtilTest.java
@@ -26,6 +26,7 @@ import 
org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
 import org.apache.marmotta.kiwi.sail.KiWiStore;
 import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
 import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.joda.time.DateTime;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -41,7 +42,10 @@ import java.io.IOException;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
 
 import static org.junit.Assert.assertTrue;
 
@@ -182,7 +186,7 @@ public class PGCopyUtilTest {
                 break;
             case 5: object = new KiWiBooleanLiteral(rnd.nextBoolean(), 
TYPE_BOOL);
                 break;
-            case 6: object = new KiWiDateLiteral(new Date(), TYPE_DATE);
+            case 6: object = new 
KiWiDateLiteral(DateTime.now().withMillisOfSecond(0), TYPE_DATE);
                 break;
             default: object = new KiWiUriResource("http://localhost/"+ 
RandomStringUtils.randomAlphanumeric(8));
                 break;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
index 0f9cbbb..581e6ad 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
@@ -378,6 +378,7 @@ public class SQLBuilder {
                                     
p.getConditions().add(sv.getExpressions().get(0) + " = " + sv.getAlias() + 
".dvalue");
                                     break;
                                 case DATE:
+                                case TZDATE:
                                     
p.getConditions().add(sv.getExpressions().get(0) + " = " + sv.getAlias() + 
".tvalue");
                                     break;
                                 case BOOL:

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
index 55df538..4d1ed87 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
@@ -23,5 +23,15 @@ package org.apache.marmotta.kiwi.sparql.builder;
 * @author Sebastian Schaffert ([email protected])
 */
 public enum ValueType {
-    DOUBLE, INT, DATE, BOOL, STRING, NODE, TERM, URI, BNODE, NONE
+    DOUBLE, // double, float or decimal value
+    INT,    // long or integer value
+    DATE,   // UTC date, dateTime or time
+    TZDATE, // date, dateTime or time with timezone
+    BOOL,   // boolean value
+    STRING, // string value
+    NODE,   // database node ID of existing node
+    TERM,   // value of constructed term
+    URI,    // constructed URI
+    BNODE,  // constructed BNODE
+    NONE    // not projected
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
index 1e651bf..1bc0036 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
@@ -604,6 +604,10 @@ public class ValueExpressionEvaluator extends 
QueryModelVisitorBase<RuntimeExcep
                         Preconditions.checkState(var != null, "no alias 
available for variable");
                         builder.append(var).append(".tvalue");
                         break;
+                    case TZDATE:
+                        Preconditions.checkState(var != null, "no alias 
available for variable");
+                        builder.append(parent.getDialect().getDateTimeTZ(var));
+                        break;
                     case URI:
                         Preconditions.checkState(var != null, "no alias 
available for variable");
                         builder.append(var).append(".svalue");

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NDay.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NDay.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NDay.java
index f1e70c4..9d144f3 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NDay.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NDay.java
@@ -81,7 +81,7 @@ public class NDay extends Day implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.DATE;
+        return ValueType.TZDATE;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NHours.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NHours.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NHours.java
index 5cedf083..5e3fe1b 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NHours.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NHours.java
@@ -81,7 +81,7 @@ public class NHours extends Hours implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.DATE;
+        return ValueType.TZDATE;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMinutes.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMinutes.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMinutes.java
index 4dd255b..b751226 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMinutes.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMinutes.java
@@ -81,7 +81,7 @@ public class NMinutes extends Minutes implements 
NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.DATE;
+        return ValueType.TZDATE;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMonth.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMonth.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMonth.java
index 8db6b13..6ee8d66 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMonth.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NMonth.java
@@ -81,7 +81,7 @@ public class NMonth extends Month implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.DATE;
+        return ValueType.TZDATE;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
index db2bce5..930de6d 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
@@ -81,7 +81,7 @@ public class NSeconds extends Seconds implements 
NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.DATE;
+        return ValueType.TZDATE;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NYear.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NYear.java
 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NYear.java
index 1bf044b..39e79e7 100644
--- 
a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NYear.java
+++ 
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NYear.java
@@ -81,7 +81,7 @@ public class NYear extends Year implements NativeFunction {
      */
     @Override
     public ValueType getArgumentType(int arg) {
-        return ValueType.DATE;
+        return ValueType.TZDATE;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/pom.xml 
b/libraries/kiwi/kiwi-triplestore/pom.xml
index 5185eeb..9981144 100644
--- a/libraries/kiwi/kiwi-triplestore/pom.xml
+++ b/libraries/kiwi/kiwi-triplestore/pom.xml
@@ -119,6 +119,11 @@
             <artifactId>commons-lang3</artifactId>
         </dependency>
         <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.marmotta</groupId>
             <artifactId>marmotta-commons</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
index 29506c6..51254f6 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
@@ -22,6 +22,8 @@ import org.apache.marmotta.commons.io.DataIO;
 import org.apache.marmotta.commons.vocabulary.SCHEMA;
 import org.apache.marmotta.commons.vocabulary.XSD;
 import org.apache.marmotta.kiwi.model.rdf.*;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
 import org.openrdf.model.vocabulary.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -438,7 +440,8 @@ public class KiWiIO {
             out.writeLong(-1L);
         } else {
             out.writeLong(literal.getId());
-            out.writeLong(literal.getDateContent().getTime());
+            out.writeLong(literal.getDateContent().getMillis());
+            
out.writeInt(literal.getDateContent().getZone().getOffset(literal.getDateContent()));
             writeURI(out, literal.getType());
             out.writeLong(literal.getCreated().getTime());
         }
@@ -458,7 +461,7 @@ public class KiWiIO {
         if(id == -1) {
             return null;
         } else {
-            Date content = new Date(input.readLong());
+            DateTime content = new DateTime(input.readLong(), 
DateTimeZone.forOffsetMillis(input.readInt()));
 
             KiWiUriResource dtype = readURI(input);
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDateLiteral.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDateLiteral.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDateLiteral.java
index 0eda440..f28d3dc 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDateLiteral.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDateLiteral.java
@@ -19,14 +19,14 @@ package org.apache.marmotta.kiwi.model.rdf;
 
 import org.apache.marmotta.commons.util.DateUtils;
 import org.apache.marmotta.commons.vocabulary.XSD;
+import org.joda.time.DateTime;
+import org.joda.time.format.ISODateTimeFormat;
 import org.openrdf.model.Literal;
 
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.XMLGregorianCalendar;
 import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
 
 /**
  * Add file description here!
@@ -38,7 +38,7 @@ public class KiWiDateLiteral extends KiWiStringLiteral {
        private static final long serialVersionUID = -7710255732571214481L;
 
 
-       private Date dateContent;
+       private DateTime dateContent;
 
 
     private static DatatypeFactory dtf;
@@ -55,29 +55,29 @@ public class KiWiDateLiteral extends KiWiStringLiteral {
     }
 
 
-    public KiWiDateLiteral(Date dateContent, KiWiUriResource type) {
-        
super(DateUtils.getXMLCalendar(DateUtils.getDateWithoutFraction(dateContent)).toXMLFormat(),null,type);
+    public KiWiDateLiteral(DateTime dateContent, KiWiUriResource type) {
+        
super(DateUtils.getXMLCalendar(dateContent.withMillisOfSecond(0)).toXMLFormat(),null,type);
         setDateContent(dateContent);
     }
 
-    public KiWiDateLiteral(Date dateContent, KiWiUriResource type, Date 
created) {
-        
super(DateUtils.getXMLCalendar(DateUtils.getDateWithoutFraction(dateContent)).toXMLFormat(),null,type,
 created);
+    public KiWiDateLiteral(DateTime dateContent, KiWiUriResource type, Date 
created) {
+        
super(DateUtils.getXMLCalendar(dateContent.withMillisOfSecond(0)).toXMLFormat(),null,type,
 created);
         setDateContent(dateContent);
     }
 
 
-    public Date getDateContent() {
-        return new Date(dateContent.getTime());
+    public DateTime getDateContent() {
+        return dateContent;
     }
 
-    public void setDateContent(Date dateContent) {
-        this.dateContent = DateUtils.getDateWithoutFraction(dateContent);
+    public void setDateContent(DateTime dateContent) {
+        this.dateContent = dateContent.withMillisOfSecond(0);
         if(XSD.DateTime.equals(getDatatype())) {
             this.content = 
DateUtils.getXMLCalendar(this.dateContent).toXMLFormat();
         } else if(XSD.Date.equals(getDatatype())) {
-            this.content = DateUtils.ISO8601FORMAT_DATE.format(dateContent);
+            this.content = ISODateTimeFormat.date().print(dateContent);
         } else if(XSD.Time.equals(getDatatype())) {
-            this.content = DateUtils.ISO8601FORMAT_TIME.format(dateContent);
+            this.content = ISODateTimeFormat.time().print(dateContent);
         }
     }
 
@@ -98,7 +98,7 @@ public class KiWiDateLiteral extends KiWiStringLiteral {
      */
     @Override
     public void setContent(String content) {
-        setDateContent(DateUtils.parseDate(content));
+        
setDateContent(ISODateTimeFormat.dateTimeParser().parseDateTime(content));
     }
 
 
@@ -126,12 +126,7 @@ public class KiWiDateLiteral extends KiWiStringLiteral {
      */
     @Override
     public XMLGregorianCalendar calendarValue() {
-        GregorianCalendar cal = new 
GregorianCalendar(TimeZone.getTimeZone("UTC"));
-        cal.setTime(getDateContent());
-
-        XMLGregorianCalendar xml_cal = 
dtf.newXMLGregorianCalendar(cal).normalize();
-        xml_cal.setTimezone(0);
-        return xml_cal;
+        return DateUtils.getXMLCalendar(dateContent);
     }
 
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDoubleLiteral.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDoubleLiteral.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDoubleLiteral.java
index 56968ba..2f367d6 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDoubleLiteral.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiDoubleLiteral.java
@@ -17,6 +17,9 @@
  */
 package org.apache.marmotta.kiwi.model.rdf;
 
+import org.apache.marmotta.commons.vocabulary.XSD;
+
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -46,14 +49,14 @@ public class KiWiDoubleLiteral extends KiWiStringLiteral {
 
     public KiWiDoubleLiteral(Double content, KiWiUriResource type) {
         super();
-        setDoubleContent(content);
         setType(type);
+        setDoubleContent(content);
      }
 
     public KiWiDoubleLiteral(Double content, KiWiUriResource type, Date 
created) {
         super(created);
-        setDoubleContent(content);
         setType(type);
+        setDoubleContent(content);
     }
 
 
@@ -63,7 +66,12 @@ public class KiWiDoubleLiteral extends KiWiStringLiteral {
 
     public void setDoubleContent(Double doubleContent) {
         this.doubleContent = doubleContent;
-        this.content       = doubleContent.toString();
+
+        if(XSD.Decimal.equals(getType())) {
+            this.content = new BigDecimal(doubleContent).toString();
+        } else {
+            this.content = doubleContent.toString();
+        }
     }
 
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/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 23231eb..b5203c5 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
@@ -26,13 +26,14 @@ import org.apache.commons.lang3.math.NumberUtils;
 import org.apache.marmotta.commons.sesame.model.LiteralCommons;
 import org.apache.marmotta.commons.sesame.model.Namespaces;
 import org.apache.marmotta.commons.sesame.tripletable.TripleTable;
-import org.apache.marmotta.commons.util.DateUtils;
 import org.apache.marmotta.kiwi.caching.CacheManager;
 import org.apache.marmotta.kiwi.config.KiWiConfiguration;
 import org.apache.marmotta.kiwi.exception.ResultInterruptedException;
 import org.apache.marmotta.kiwi.model.rdf.*;
 import org.apache.marmotta.kiwi.persistence.util.ResultSetIteration;
 import org.apache.marmotta.kiwi.persistence.util.ResultTransformerFunction;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
 import org.openrdf.model.Literal;
 import org.openrdf.model.Resource;
 import org.openrdf.model.Statement;
@@ -111,6 +112,8 @@ public class KiWiConnection implements AutoCloseable {
      */
     private static Map<String,Locale> localeMap = new HashMap<String, 
Locale>();
 
+    private static Calendar calendarUTC = 
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+
 
     private Map<String,PreparedStatement> statementCache;
 
@@ -729,9 +732,9 @@ public class KiWiConnection implements AutoCloseable {
      * @return a KiWiDateLiteral with the correct date, or null if it does not 
exist
      * @throws SQLException
      */
-    public KiWiDateLiteral loadLiteral(Date date) throws SQLException {
+    public KiWiDateLiteral loadLiteral(DateTime date) throws SQLException {
         // look in cache
-        KiWiLiteral element = 
literalCache.get(LiteralCommons.createCacheKey(DateUtils.getDateWithoutFraction(date),Namespaces.NS_XSD
 + "dateTime"));
+        KiWiLiteral element = 
literalCache.get(LiteralCommons.createCacheKey(date.withMillisOfSecond(0),Namespaces.NS_XSD
 + "dateTime"));
         if(element != null && element instanceof KiWiDateLiteral) {
             return (KiWiDateLiteral)element;
         }
@@ -749,8 +752,9 @@ public class KiWiConnection implements AutoCloseable {
 
             // otherwise prepare a query, depending on the parameters given
             PreparedStatement query = 
getPreparedStatement("load.literal_by_tv");
-            query.setTimestamp(1, new 
Timestamp(DateUtils.getDateWithoutFraction(date).getTime()));
-            query.setLong(2,ltype.getId());
+            query.setTimestamp(1, new Timestamp(date.getMillis()), 
calendarUTC);
+            query.setInt(2, date.getZone().getOffset(date)/1000);
+            query.setLong(3,ltype.getId());
 
             // run the database query and if it yields a result, construct a 
new node; the method call will take care of
             // caching the constructed node for future calls
@@ -970,7 +974,7 @@ public class KiWiConnection implements AutoCloseable {
             PreparedStatement insertNode = getPreparedStatement("store.uri");
             insertNode.setLong(1,node.getId());
             insertNode.setString(2,uriResource.stringValue());
-            insertNode.setTimestamp(3, new 
Timestamp(uriResource.getCreated().getTime()));
+            insertNode.setTimestamp(3, new 
Timestamp(uriResource.getCreated().getTime()), calendarUTC);
 
             insertNode.executeUpdate();
 
@@ -980,7 +984,7 @@ public class KiWiConnection implements AutoCloseable {
             PreparedStatement insertNode = getPreparedStatement("store.bnode");
             insertNode.setLong(1,node.getId());
             insertNode.setString(2,anonResource.stringValue());
-            insertNode.setTimestamp(3, new 
Timestamp(anonResource.getCreated().getTime()));
+            insertNode.setTimestamp(3, new 
Timestamp(anonResource.getCreated().getTime()), calendarUTC);
 
             insertNode.executeUpdate();
         } else if(node instanceof KiWiDateLiteral) {
@@ -989,12 +993,13 @@ public class KiWiConnection implements AutoCloseable {
             PreparedStatement insertNode = 
getPreparedStatement("store.tliteral");
             insertNode.setLong(1,node.getId());
             insertNode.setString(2, dateLiteral.stringValue());
-            insertNode.setTimestamp(3, new 
Timestamp(dateLiteral.getDateContent().getTime()));
+            insertNode.setTimestamp(3, new 
Timestamp(dateLiteral.getDateContent().getMillis()), calendarUTC);
+            insertNode.setInt(4, 
dateLiteral.getDateContent().getZone().getOffset(dateLiteral.getDateContent())/1000);
             if(dateLiteral.getType() != null)
-                insertNode.setLong(4,dateLiteral.getType().getId());
+                insertNode.setLong(5,dateLiteral.getType().getId());
             else
                 throw new IllegalStateException("a date literal must have a 
datatype");
-            insertNode.setTimestamp(5, new 
Timestamp(dateLiteral.getCreated().getTime()));
+            insertNode.setTimestamp(6, new 
Timestamp(dateLiteral.getCreated().getTime()), calendarUTC);
 
             insertNode.executeUpdate();
         } else if(node instanceof KiWiIntLiteral) {
@@ -1009,7 +1014,7 @@ public class KiWiConnection implements AutoCloseable {
                 insertNode.setLong(5,intLiteral.getType().getId());
             else
                 throw new IllegalStateException("an integer literal must have 
a datatype");
-            insertNode.setTimestamp(6, new 
Timestamp(intLiteral.getCreated().getTime()));
+            insertNode.setTimestamp(6, new 
Timestamp(intLiteral.getCreated().getTime()), calendarUTC);
 
             insertNode.executeUpdate();
         } else if(node instanceof KiWiDoubleLiteral) {
@@ -1023,7 +1028,7 @@ public class KiWiConnection implements AutoCloseable {
                 insertNode.setLong(4,doubleLiteral.getType().getId());
             else
                 throw new IllegalStateException("a double literal must have a 
datatype");
-            insertNode.setTimestamp(5, new 
Timestamp(doubleLiteral.getCreated().getTime()));
+            insertNode.setTimestamp(5, new 
Timestamp(doubleLiteral.getCreated().getTime()), calendarUTC);
 
             insertNode.executeUpdate();
         } else if(node instanceof KiWiBooleanLiteral) {
@@ -1037,7 +1042,7 @@ public class KiWiConnection implements AutoCloseable {
                 insertNode.setLong(4,booleanLiteral.getType().getId());
             else
                 throw new IllegalStateException("a boolean literal must have a 
datatype");
-            insertNode.setTimestamp(5, new 
Timestamp(booleanLiteral.getCreated().getTime()));
+            insertNode.setTimestamp(5, new 
Timestamp(booleanLiteral.getCreated().getTime()), calendarUTC);
 
             insertNode.executeUpdate();
         } else if(node instanceof KiWiStringLiteral) {
@@ -1079,7 +1084,7 @@ public class KiWiConnection implements AutoCloseable {
             } else {
                 insertNode.setObject(6, null);
             }
-            insertNode.setTimestamp(7, new 
Timestamp(stringLiteral.getCreated().getTime()));
+            insertNode.setTimestamp(7, new 
Timestamp(stringLiteral.getCreated().getTime()), calendarUTC);
 
             insertNode.executeUpdate();
         } else {
@@ -1777,8 +1782,8 @@ public class KiWiConnection implements AutoCloseable {
      * @return
      */
     protected KiWiNode constructNodeFromDatabase(ResultSet row) throws 
SQLException {
-        // column order; 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt
-        //               1 ,2    ,3     ,4     ,5     ,6     ,7     ,8   ,9    
,10
+        // column order; 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt
+        //               1 ,2    ,3     ,4     ,5     ,6     ,7        ,8   ,9 
   ,10    .11
 
         long id = row.getLong(1);
 
@@ -1791,64 +1796,64 @@ public class KiWiConnection implements AutoCloseable {
 
         String ntype = row.getString(2);
         if("uri".equals(ntype)) {
-            KiWiUriResource result = new KiWiUriResource(row.getString(3),new 
Date(row.getTimestamp(10).getTime()));
+            KiWiUriResource result = new KiWiUriResource(row.getString(3),new 
Date(row.getTimestamp(11, calendarUTC).getTime()));
             result.setId(id);
 
             cacheNode(result);
             return result;
         } else if("bnode".equals(ntype)) {
-            KiWiAnonResource result = new KiWiAnonResource(row.getString(3), 
new Date(row.getTimestamp(10).getTime()));
+            KiWiAnonResource result = new KiWiAnonResource(row.getString(3), 
new Date(row.getTimestamp(11, calendarUTC).getTime()));
             result.setId(id);
 
             cacheNode(result);
             return result;
         } else if("string".equals(ntype)) {
-            final KiWiStringLiteral result = new 
KiWiStringLiteral(row.getString(3), new Date(row.getTimestamp(10).getTime()));
+            final KiWiStringLiteral result = new 
KiWiStringLiteral(row.getString(3), new Date(row.getTimestamp(11, 
calendarUTC).getTime()));
             result.setId(id);
 
-            if(row.getString(8) != null) {
-                result.setLocale(getLocale(row.getString(8)));
+            if(row.getString(9) != null) {
+                result.setLocale(getLocale(row.getString(9)));
             }
-            if(row.getLong(9) != 0) {
-                result.setType((KiWiUriResource) loadNodeById(row.getLong(9)));
+            if(row.getLong(10) != 0) {
+                result.setType((KiWiUriResource) 
loadNodeById(row.getLong(10)));
             }
 
             cacheNode(result);
             return result;
         } else if("int".equals(ntype)) {
-            KiWiIntLiteral result = new KiWiIntLiteral(row.getLong(4), null, 
new Date(row.getTimestamp(10).getTime()));
+            KiWiIntLiteral result = new KiWiIntLiteral(row.getLong(4), null, 
new Date(row.getTimestamp(11, calendarUTC).getTime()));
             result.setId(id);
-            if(row.getLong(9) != 0) {
-                result.setType((KiWiUriResource) loadNodeById(row.getLong(9)));
+            if(row.getLong(10) != 0) {
+                result.setType((KiWiUriResource) 
loadNodeById(row.getLong(10)));
             }
 
             cacheNode(result);
             return result;
         } else if("double".equals(ntype)) {
-            KiWiDoubleLiteral result = new KiWiDoubleLiteral(row.getDouble(5), 
null, new Date(row.getTimestamp(10).getTime()));
+            KiWiDoubleLiteral result = new KiWiDoubleLiteral(row.getDouble(5), 
null, new Date(row.getTimestamp(11, calendarUTC).getTime()));
             result.setId(id);
-            if(row.getLong(9) != 0) {
-                result.setType((KiWiUriResource) loadNodeById(row.getLong(9)));
+            if(row.getLong(10) != 0) {
+                result.setType((KiWiUriResource) 
loadNodeById(row.getLong(10)));
             }
 
             cacheNode(result);
             return result;
         } else if("boolean".equals(ntype)) {
-            KiWiBooleanLiteral result = new 
KiWiBooleanLiteral(row.getBoolean(7),null,new 
Date(row.getTimestamp(10).getTime()));
+            KiWiBooleanLiteral result = new 
KiWiBooleanLiteral(row.getBoolean(8),null,new Date(row.getTimestamp(11, 
calendarUTC).getTime()));
             result.setId(id);
 
-            if(row.getLong(9) != 0) {
-                result.setType((KiWiUriResource) loadNodeById(row.getLong(9)));
+            if(row.getLong(10) != 0) {
+                result.setType((KiWiUriResource) 
loadNodeById(row.getLong(10)));
             }
 
             cacheNode(result);
             return result;
         } else if("date".equals(ntype)) {
-            KiWiDateLiteral result = new KiWiDateLiteral(new 
Date(row.getTimestamp(6).getTime()), null, new 
Date(row.getTimestamp(10).getTime()));
+            KiWiDateLiteral result = new KiWiDateLiteral(new 
DateTime(row.getTimestamp(6, calendarUTC).getTime(), 
DateTimeZone.forOffsetMillis(row.getInt(7)*1000)), null, new 
Date(row.getTimestamp(11, calendarUTC).getTime()));
             result.setId(id);
 
-            if(row.getLong(9) != 0) {
-                result.setType((KiWiUriResource) loadNodeById(row.getLong(9)));
+            if(row.getLong(10) != 0) {
+                result.setType((KiWiUriResource) 
loadNodeById(row.getLong(10)));
             }
 
             cacheNode(result);

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
index d54df6d..ca99645 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiDialect.java
@@ -37,7 +37,7 @@ public abstract class KiWiDialect {
 
     private static Logger log = LoggerFactory.getLogger(KiWiDialect.class);
 
-    private final static int VERSION = 2;
+    public final static int VERSION = 4;
 
     private Properties statements;
 
@@ -207,6 +207,14 @@ public abstract class KiWiDialect {
 
 
     /**
+     * Return the SQL timezone value for a KiWiDateLiteral, corrected by the 
timezone offset. In PostgreSQL, this is
+     * e.g. computed by (ALIAS.tvalue + ALIAS.tzoffset * INTERVAL '1 second')
+     * @param alias
+     * @return
+     */
+    public abstract String getDateTimeTZ(String alias);
+
+    /**
      * Get the query string that can be used for validating that a JDBC 
connection to this database is still valid.
      * Typically, this should be an inexpensive operation like "SELECT 1",
      * @return

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/h2/H2Dialect.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/h2/H2Dialect.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/h2/H2Dialect.java
index 05913b2..7ed0b09 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/h2/H2Dialect.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/h2/H2Dialect.java
@@ -105,6 +105,18 @@ public class H2Dialect extends KiWiDialect {
         }
     }
 
+    /**
+     * Return the SQL timezone value for a KiWiDateLiteral, corrected by the 
timezone offset. In PostgreSQL, this is
+     * e.g. computed by (ALIAS.tvalue + ALIAS.tzoffset * INTERVAL '1 second')
+     *
+     * @param alias
+     * @return
+     */
+    @Override
+    public String getDateTimeTZ(String alias) {
+        return String.format("DATEADD('SECOND', %s.tzoffset, %s.tvalue)");
+    }
+
 
     /**
      * Get the query string that can be used for validating that a JDBC 
connection to this database is still valid.

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/mysql/MySQLDialect.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/mysql/MySQLDialect.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/mysql/MySQLDialect.java
index 82ed3f6..c8c4e50 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/mysql/MySQLDialect.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/mysql/MySQLDialect.java
@@ -118,6 +118,19 @@ public class MySQLDialect extends KiWiDialect {
         }
     }
 
+
+    /**
+     * Return the SQL timezone value for a KiWiDateLiteral, corrected by the 
timezone offset. In PostgreSQL, this is
+     * e.g. computed by (ALIAS.tvalue + ALIAS.tzoffset * INTERVAL '1 second')
+     *
+     * @param alias
+     * @return
+     */
+    @Override
+    public String getDateTimeTZ(String alias) {
+        return String.format("DATE_ADD(%s.tvalue, INTERVAL %s.tzoffset 
SECOND)");
+    }
+
     /**
      * Get the query string that can be used for validating that a JDBC 
connection to this database is still valid.
      * Typically, this should be an inexpensive operation like "SELECT 1",

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
index 28fa98e..a2645d6 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
@@ -110,6 +110,18 @@ public class PostgreSQLDialect extends KiWiDialect {
     }
 
     /**
+     * Return the SQL timezone value for a KiWiDateLiteral, corrected by the 
timezone offset. In PostgreSQL, this is
+     * e.g. computed by (ALIAS.tvalue + ALIAS.tzoffset * INTERVAL '1 second')
+     *
+     * @param alias
+     * @return
+     */
+    @Override
+    public String getDateTimeTZ(String alias) {
+        return String.format("%s.tvalue + %s.tzoffset * INTERVAL '1 second'", 
alias, alias);
+    }
+
+    /**
      * Get the query string that can be used for validating that a JDBC 
connection to this database is still valid.
      * Typically, this should be an inexpensive operation like "SELECT 1",
      *

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
index a7086b3..54ae3f1 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
@@ -20,13 +20,14 @@ package org.apache.marmotta.kiwi.sail;
 import org.apache.marmotta.commons.sesame.model.LiteralCommons;
 import org.apache.marmotta.commons.sesame.model.Namespaces;
 import org.apache.marmotta.commons.sesame.tripletable.IntArray;
-import org.apache.marmotta.commons.util.DateUtils;
 import org.apache.marmotta.kiwi.model.rdf.*;
 import org.apache.marmotta.kiwi.persistence.KiWiConnection;
 import org.apache.marmotta.kiwi.persistence.registry.CacheTripleRegistry;
 import org.apache.marmotta.kiwi.persistence.registry.DBTripleRegistry;
 import org.apache.marmotta.kiwi.persistence.registry.KiWiTripleRegistry;
 import org.apache.marmotta.kiwi.persistence.registry.LocalTripleRegistry;
+import org.joda.time.DateTime;
+import org.joda.time.format.ISODateTimeFormat;
 import org.openrdf.model.*;
 import org.openrdf.model.impl.ContextStatementImpl;
 import org.slf4j.Logger;
@@ -34,10 +35,7 @@ import org.slf4j.LoggerFactory;
 
 import javax.xml.datatype.XMLGregorianCalendar;
 import java.sql.SQLException;
-import java.util.Date;
-import java.util.IllformedLocaleException;
-import java.util.Locale;
-import java.util.Random;
+import java.util.*;
 
 /**
  * Add file description here!
@@ -311,13 +309,15 @@ public class KiWiValueFactory implements ValueFactory {
                     if(result == null) {
                         result = new KiWiStringLiteral(value.toString(), 
locale, rtype);
                     }
-                } else if(value instanceof Date || 
type.equals(Namespaces.NS_XSD+"dateTime") || 
type.equals(Namespaces.NS_XSD+"date") || type.equals(Namespaces.NS_XSD+"time")) 
{
+                } else if(value instanceof Date || value instanceof DateTime 
||type.equals(Namespaces.NS_XSD+"dateTime") || 
type.equals(Namespaces.NS_XSD+"date") || type.equals(Namespaces.NS_XSD+"time")) 
{
                     // parse if necessary
-                    final Date dvalue;
-                    if(value instanceof Date) {
-                        dvalue = (Date)value;
+                    final DateTime dvalue;
+                    if(value instanceof DateTime) {
+                        dvalue = ((DateTime) value).withMillisOfDay(0);
+                    } else if(value instanceof Date || value instanceof 
Calendar) {
+                        dvalue = new DateTime(value);
                     } else {
-                        dvalue = DateUtils.parseDate(value.toString());
+                        dvalue = 
ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(value.toString()).withMillisOfSecond(0);
                     }
 
                     result = connection.loadLiteral(dvalue);

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql
 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql
index 368b5cc..0ad3970 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/create_base_tables.sql
@@ -20,6 +20,7 @@ CREATE TABLE nodes (
   dvalue    double precision,
   ivalue    bigint,
   tvalue    timestamp,
+  tzoffset  INT,
   bvalue    boolean,
   ltype     bigint     REFERENCES nodes(id),
   lang      varchar(5),
@@ -81,5 +82,5 @@ 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','3');
+INSERT INTO metadata(mkey,mvalue) VALUES ('version','4');
 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/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
index 8e1a747..753c574 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
@@ -25,21 +25,21 @@ meta.get               = SELECT mvalue FROM metadata WHERE 
mkey = ?;
 
 
 # load entities
-load.node_by_id        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes 
WHERE id = ?
-load.nodes_by_ids        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes 
WHERE id IN(%s) LIMIT %d
+load.node_by_id        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE id = ?
+load.nodes_by_ids        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE id IN(%s) LIMIT %d
 
-load.uri_by_uri        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes 
WHERE ntype = 'uri' AND svalue = ?
+load.uri_by_uri        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE ntype = 'uri' AND svalue = ?
 
-load.bnode_by_anonid   = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes 
WHERE ntype = 'bnode' AND svalue = ?
+load.bnode_by_anonid   = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,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 OR lang = '') 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_v     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE ntype = 'string' AND svalue = ? AND (lang IS NULL OR lang = '') AND 
ltype IS NULL
+load.literal_by_vl    = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE svalue = ? AND lang = ?
+load.literal_by_vt    = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,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 OR lang = '') 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 OR lang = '') 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 OR lang = '') 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 OR lang = '') AND ltype = ?
+load.literal_by_iv     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE ivalue = ? AND (lang IS NULL OR lang = '') AND ltype = ?
+load.literal_by_dv     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE dvalue = ? AND (lang IS NULL OR lang = '') AND ltype = ?
+load.literal_by_tv     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE tvalue = ? AND tzoffset = ? AND (lang IS NULL OR lang = '') AND 
ltype = ?
+load.literal_by_bv     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE bvalue = ? AND (lang IS NULL OR lang = '') AND ltype = ?
 
 
 load.namespace_prefix  = SELECT id,prefix,uri,createdAt FROM namespaces WHERE 
prefix = ?;
@@ -56,7 +56,7 @@ store.sliteral       = INSERT INTO nodes 
(id,ntype,svalue,dvalue,ivalue,lang,lty
 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.tliteral       = INSERT INTO nodes 
(id,ntype,svalue,tvalue,tzoffset,ltype,createdAt) VALUES (?,'date',?,?,?,?,?)
 
 store.namespace      = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES 
(?,?,?,?)
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/upgrade_base_003_004.sql
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/upgrade_base_003_004.sql
 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/upgrade_base_003_004.sql
new file mode 100644
index 0000000..af19d5f
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/upgrade_base_003_004.sql
@@ -0,0 +1,16 @@
+-- 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.
+
+ALTER TABLE nodes ADD tzoffset int default 0 AFTER tvalue;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql
 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql
index fc8c722..440a56d 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/create_base_tables.sql
@@ -20,6 +20,7 @@ CREATE TABLE nodes (
   dvalue    double precision,
   ivalue    bigint,
   tvalue    datetime   DEFAULT NULL,
+  tzoffset  INT,
   bvalue    boolean,
   ltype     bigint     REFERENCES nodes(id),
   lang      varchar(5),
@@ -80,5 +81,5 @@ 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','3');
+INSERT INTO metadata(mkey,mvalue) VALUES ('version','4');
 INSERT INTO metadata(mkey,mvalue) VALUES 
('created',DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s') );

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
index 0963ab5..40be33b 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
@@ -24,21 +24,21 @@ meta.update            = UPDATE metadata SET mvalue = ? 
WHERE mkey = ?;
 meta.get               = SELECT mvalue FROM metadata WHERE mkey = ?;
 
 # load entities
-load.node_by_id        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes 
WHERE id = ?
-load.nodes_by_ids        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes 
WHERE id IN(%s) LIMIT %d
+load.node_by_id        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE id = ?
+load.nodes_by_ids        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE id IN(%s) LIMIT %d
 
-load.uri_by_uri        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes 
WHERE ntype = 'uri' AND svalue = ?
+load.uri_by_uri        = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE ntype = 'uri' AND svalue = ?
 
-load.bnode_by_anonid   = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,bvalue,lang,ltype,createdAt FROM nodes 
WHERE ntype = 'bnode' AND svalue = ?
+load.bnode_by_anonid   = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,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 OR lang = '') 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_v     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE ntype='string' AND svalue = ? AND (lang IS NULL OR lang = '') AND 
ltype IS NULL
+load.literal_by_vl    = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE svalue = ? AND lang = ?
+load.literal_by_vt    = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,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 OR lang = '') 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 OR lang = '') 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 OR lang = '') 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 OR lang = '') AND ltype = ?
+load.literal_by_iv     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE ivalue = ? AND (lang IS NULL OR lang = '') AND ltype = ?
+load.literal_by_dv     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE dvalue = ? AND (lang IS NULL OR lang = '') AND ltype = ?
+load.literal_by_tv     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE tvalue = ? AND tzoffset = ? AND (lang IS NULL OR lang = '') AND 
ltype = ?
+load.literal_by_bv     = SELECT 
id,ntype,svalue,ivalue,dvalue,tvalue,tzoffset,bvalue,lang,ltype,createdAt FROM 
nodes WHERE bvalue = ? AND (lang IS NULL OR lang = '') AND ltype = ?
 
 
 load.namespace_prefix  = SELECT id,prefix,uri,createdAt FROM namespaces WHERE 
prefix = ?;
@@ -55,7 +55,7 @@ store.sliteral       = INSERT INTO nodes 
(id,ntype,svalue,dvalue,ivalue,lang,lty
 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.tliteral       = INSERT INTO nodes 
(id,ntype,svalue,tvalue,tzoffset,ltype,createdAt) VALUES (?,'date',?,?,?,?,?)
 
 store.namespace      = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES 
(?,?,?,?)
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/upgrade_base_003_004.sql
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/upgrade_base_003_004.sql
 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/upgrade_base_003_004.sql
new file mode 100644
index 0000000..3783dac
--- /dev/null
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/upgrade_base_003_004.sql
@@ -0,0 +1,16 @@
+-- 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.
+
+ALTER TABLE nodes ADD COLUMN tzoffset int default 0 AFTER tvalue;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7a824559/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql
 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql
index 06b422f..bad2d05 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/create_base_tables.sql
@@ -24,6 +24,7 @@ CREATE TABLE nodes (
   dvalue    double precision,
   ivalue    bigint,
   tvalue    timestamp,
+  tzoffset  INT4,
   bvalue    boolean,
   ltype     bigint     REFERENCES nodes(id),
   lang      varchar(5),
@@ -102,5 +103,5 @@ DO INSTEAD NOTHING;
 -- a function for cleaning up table rows without incoming references
 
 -- insert initial metadata
-INSERT INTO metadata(mkey,mvalue) VALUES ('version','3');
+INSERT INTO metadata(mkey,mvalue) VALUES ('version','4');
 INSERT INTO metadata(mkey,mvalue) VALUES ('created',to_char(now(),'yyyy-MM-DD 
HH:mm:ss TZ') );
\ No newline at end of file

Reply via email to