Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java @ 5784:efbbfe32e9fe
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.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 22 Apr 2013 16:18:16 +0200 |
parents | 619da3fa7a8b |
children |
comparison
equal
deleted
inserted
replaced
5783:153456f84602 | 5784:efbbfe32e9fe |
---|---|
4 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import java.util.Collection; | 5 import java.util.Collection; |
6 import java.util.Date; | 6 import java.util.Date; |
7 import java.util.List; | 7 import java.util.List; |
8 import java.util.Map; | 8 import java.util.Map; |
9 | |
10 import java.lang.reflect.InvocationTargetException; | |
11 import java.lang.reflect.Method; | |
9 | 12 |
10 import javax.xml.namespace.QName; | 13 import javax.xml.namespace.QName; |
11 | 14 |
12 import javax.xml.xpath.XPathFunction; | 15 import javax.xml.xpath.XPathFunction; |
13 import javax.xml.xpath.XPathFunctionException; | 16 import javax.xml.xpath.XPathFunctionException; |
295 } | 298 } |
296 | 299 |
297 public Object dateFormat(List args) throws XPathFunctionException { | 300 public Object dateFormat(List args) throws XPathFunctionException { |
298 Object pattern = args.get(0); | 301 Object pattern = args.get(0); |
299 Object date = args.get(1); | 302 Object date = args.get(1); |
303 | |
304 try { | |
305 // Oracle does not return a date object but an oracle.sql.TIMESTAMP | |
306 Method meth = date.getClass().getMethod("dateValue", new Class[] {}); | |
307 date = meth.invoke(date, new Object [] {}); | |
308 } catch (IllegalArgumentException e) { | |
309 } catch (IllegalAccessException e) { | |
310 } catch (InvocationTargetException e) { | |
311 } catch (NoSuchMethodException e) { | |
312 } | |
300 if (pattern instanceof String && date instanceof Date) { | 313 if (pattern instanceof String && date instanceof Date) { |
301 try { | 314 try { |
302 // TODO: Take locale into account. | 315 // TODO: Take locale into account. |
303 return new SimpleDateFormat((String)pattern).format((Date)date); | 316 return new SimpleDateFormat((String)pattern).format((Date)date); |
304 } | 317 } |