[Dive4elements-commits] [PATCH] Fix dateFormat for Oracle by invoking dateValue on demand

Wald Commits scm-commit at wald.intevation.org
Mon Apr 22 16:18:30 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1366640296 -7200
# Node ID efbbfe32e9fe8f3a907d43269a762606be106870
# Parent  153456f8460298e2a72460567f77eb4968847c8d
Fix dateFormat for Oracle by invoking dateValue on demand

    Oracle does not return a date object but a oracle.sql.TIMESTAMP
    object when querying a date. We now convert to a java date
    by inviking the method dateValue if it is available.

diff -r 153456f84602 -r efbbfe32e9fe flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java	Mon Apr 22 13:00:13 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java	Mon Apr 22 16:18:16 2013 +0200
@@ -7,6 +7,9 @@
 import java.util.List;
 import java.util.Map;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 import javax.xml.namespace.QName;
 
 import javax.xml.xpath.XPathFunction;
@@ -297,6 +300,16 @@
     public Object dateFormat(List args) throws XPathFunctionException {
         Object pattern = args.get(0);
         Object date    = args.get(1);
+
+        try {
+            // Oracle does not return a date object but an oracle.sql.TIMESTAMP
+            Method meth = date.getClass().getMethod("dateValue", new Class[] {});
+            date = meth.invoke(date, new Object [] {});
+        } catch (IllegalArgumentException e) {
+        } catch (IllegalAccessException e) {
+        } catch (InvocationTargetException e) {
+        } catch (NoSuchMethodException e) {
+        }
         if (pattern instanceof String && date instanceof Date) {
             try {
                 // TODO: Take locale into account.


More information about the Dive4elements-commits mailing list