Search in sources :

Example 1 with AtomicValue

use of net.sf.saxon.value.AtomicValue in project teiid by teiid.

the class XQueryEvaluator method convertToAtomicValue.

public static AtomicValue convertToAtomicValue(Object value) throws TransformerException {
    if (value instanceof java.util.Date) {
        // special handling for time types
        java.util.Date d = (java.util.Date) value;
        DateTimeValue tdv = DateTimeValue.fromJavaDate(d);
        if (value instanceof Date) {
            value = new DateValue(tdv.getYear(), tdv.getMonth(), tdv.getDay(), tdv.getTimezoneInMinutes(), true);
        } else if (value instanceof Time) {
            value = new TimeValue(tdv.getHour(), tdv.getMinute(), tdv.getSecond(), tdv.getMicrosecond(), tdv.getTimezoneInMinutes());
        } else if (value instanceof Timestamp) {
            Timestamp ts = (Timestamp) value;
            value = tdv.add(DayTimeDurationValue.fromMicroseconds(ts.getNanos() / 1000));
        }
        return (AtomicValue) value;
    }
    JPConverter converter = JPConverter.allocate(value.getClass(), null, null);
    return (AtomicValue) converter.convert(value, null);
}
Also used : JPConverter(net.sf.saxon.expr.JPConverter) DateTimeValue(net.sf.saxon.value.DateTimeValue) DateValue(net.sf.saxon.value.DateValue) Time(java.sql.Time) AtomicValue(net.sf.saxon.value.AtomicValue) Timestamp(java.sql.Timestamp) Date(java.sql.Date) TimeValue(net.sf.saxon.value.TimeValue) DateTimeValue(net.sf.saxon.value.DateTimeValue)

Aggregations

Date (java.sql.Date)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 JPConverter (net.sf.saxon.expr.JPConverter)1 AtomicValue (net.sf.saxon.value.AtomicValue)1 DateTimeValue (net.sf.saxon.value.DateTimeValue)1 DateValue (net.sf.saxon.value.DateValue)1 TimeValue (net.sf.saxon.value.TimeValue)1