use of org.odata4j.core.OSimpleObject 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;
}
use of org.odata4j.core.OSimpleObject in project teiid by teiid.
the class ODataProcedureExecution method execute.
@Override
public void execute() throws TranslatorException {
String URI = this.visitor.buildURL();
Schema schema = visitor.getProcedure().getParent();
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
if (this.visitor.hasCollectionReturn()) {
if (this.visitor.isReturnComplexType()) {
// complex return
this.response = executeWithComplexReturn(this.visitor.getMethod(), URI, null, this.visitor.getReturnEntityTypeName(), edm, null, Status.OK, Status.NO_CONTENT);
} else {
// entity type return
this.response = executeWithReturnEntity(this.visitor.getMethod(), URI, null, this.visitor.getTable().getName(), edm, null, Status.OK, Status.NO_CONTENT);
}
if (this.response != null && this.response.hasError()) {
throw this.response.getError();
}
} else {
try {
BinaryWSProcedureExecution execution = executeDirect(this.visitor.getMethod(), URI, null, getDefaultHeaders());
if (execution.getResponseCode() != Status.OK.getStatusCode()) {
throw buildError(execution);
}
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
ODataVersion version = getODataVersion(execution);
// if the procedure is not void
if (this.visitor.getReturnType() != null) {
FormatParser<? extends OObject> parser = FormatParserFactory.getParser(OSimpleObject.class, FormatType.ATOM, new Settings(version, edm, this.visitor.getProcedure().getName(), // entitykey
null, // isResponse
true, ODataTypeManager.odataType(this.visitor.getReturnType())));
OSimpleObject object = (OSimpleObject) parser.parse(new InputStreamReader(blob.getBinaryStream()));
this.returnValue = this.translator.retrieveValue(object.getValue(), this.visitor.getReturnTypeClass());
}
} catch (SQLException e) {
throw new TranslatorException(e);
}
}
}
Aggregations