Search in sources :

Example 1 with OCollection

use of org.odata4j.core.OCollection in project teiid by teiid.

the class ODataExecutionFactory method retrieveValue.

/**
 * @param value
 * @param expectedType
 * @return
 */
public Object retrieveValue(Object value, Class<?> expectedType) {
    if (value == null) {
        return null;
    }
    if (value instanceof LocalDateTime) {
        DateTime dateTime = ((LocalDateTime) value).toDateTime(DateTimeZone.forTimeZone(this.timeZone));
        return new java.sql.Timestamp(dateTime.getMillis());
    }
    if (value instanceof LocalTime) {
        return new java.sql.Timestamp(((LocalTime) value).toDateTimeToday().getMillis());
    }
    if (value instanceof UnsignedByte) {
        return Short.valueOf(((UnsignedByte) value).shortValue());
    }
    if (expectedType.isArray() && value instanceof OCollection<?>) {
        ArrayList<Object> result = new ArrayList<Object>();
        OCollection<?> arrayValues = (OCollection<?>) value;
        Iterator<?> it = arrayValues.iterator();
        while (it.hasNext()) {
            OSimpleObject<?> item = (OSimpleObject<?>) it.next();
            result.add(retrieveValue(item.getValue(), expectedType.getComponentType()));
        }
        Object target = java.lang.reflect.Array.newInstance(expectedType.getComponentType(), result.size());
        System.arraycopy(result.toArray(), 0, target, 0, result.size());
        value = target;
    }
    return value;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalTime(org.joda.time.LocalTime) OSimpleObject(org.odata4j.core.OSimpleObject) ArrayList(java.util.ArrayList) UnsignedByte(org.odata4j.core.UnsignedByte) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) OCollection(org.odata4j.core.OCollection) OSimpleObject(org.odata4j.core.OSimpleObject)

Aggregations

ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 LocalDateTime (org.joda.time.LocalDateTime)1 LocalTime (org.joda.time.LocalTime)1 OCollection (org.odata4j.core.OCollection)1 OSimpleObject (org.odata4j.core.OSimpleObject)1 UnsignedByte (org.odata4j.core.UnsignedByte)1