@Override public ArrayList<RemoteObject> deserializeArray(String queryScope, String input) { String bodyFormat = getDeserializationBodyFormat(); if (XML.equals(bodyFormat)) { return deserializeArrayAsXml(queryScope, input); } else if (JSON.equals(bodyFormat)) { return deserializeArrayAsJson(queryScope, input); } else { return deserializeArrayAsJson(queryScope, input); } }
@Override public RemoteObject deserialize(String queryScope, String input) { String bodyFormat = getDeserializationBodyFormat(); // TODO parse role if auth object Parser parser = null; if (XML.equals(bodyFormat)) { parser = createXmlParser(queryScope, input); } else if (JSON.equals(bodyFormat)) { parser = createJsonParser(queryScope, input); } else { parser = createJsonParser(queryScope, input); } return deserialize(queryScope, parser); }
@Override protected Type visitGenericLiteral(GenericLiteral node, AnalysisContext context) { Type type = typeManager.getType(parseTypeSignature(node.getType())); if (type == null) { throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType()); } if (!JSON.equals(type)) { try { functionRegistry.getCoercion(VARCHAR, type); } catch (IllegalArgumentException e) { throw new SemanticException(TYPE_MISMATCH, node, "No literal form for type %s", type); } } expressionTypes.put(node, type); return type; }
@Override protected Object visitGenericLiteral(GenericLiteral node, ConnectorSession session) { Type type = metadata.getType(parseTypeSignature(node.getType())); if (type == null) { throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType()); } if (JSON.equals(type)) { ScalarFunctionImplementation operator = metadata .getFunctionRegistry() .getScalarFunctionImplementation( new Signature( "json_parse", SCALAR, JSON.getTypeSignature(), VARCHAR.getTypeSignature())); try { return ExpressionInterpreter.invoke( session, operator, ImmutableList.<Object>of(utf8Slice(node.getValue()))); } catch (Throwable throwable) { throw Throwables.propagate(throwable); } } ScalarFunctionImplementation operator; try { Signature signature = metadata.getFunctionRegistry().getCoercion(VARCHAR, type); operator = metadata.getFunctionRegistry().getScalarFunctionImplementation(signature); } catch (IllegalArgumentException e) { throw new SemanticException(TYPE_MISMATCH, node, "No literal form for type %s", type); } try { return ExpressionInterpreter.invoke( session, operator, ImmutableList.<Object>of(utf8Slice(node.getValue()))); } catch (Throwable throwable) { throw Throwables.propagate(throwable); } }
@Override public String serialize() { String bodyFormat = getSerializationBodyFormat(); SerializerBuilder builder = null; String recordSelector = HttpAdapter.createResponseWrangling(this).getRecordSelector(); if (XML.equals(bodyFormat)) { builder = new XmlSerializer.XmlSerializerBuilder(recordSelector); } else if (JSON.equals(bodyFormat)) { builder = new JsonSerializer.JsonSerializerBuilder(recordSelector); } else if (FORM_ENCODED.equals(bodyFormat)) { builder = new FormEncodedSerializer.FormEncodedSerializerBuilder(recordSelector); } final RouterAdapter routerAdapter = RemoteRailsConfig.getRouterAdapterByClass(this.getClass()); if (builder != null && routerAdapter != null) { builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("id"), "id"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("comments"), "comments"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("currency"), "currency"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("last_price"), "last_price"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("last_qty"), "last_qty"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("price"), "price"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("quantity"), "quantity"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("side"), "side"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("status"), "status"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("symbol"), "symbol"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("transact_time"), "transact_time"); return builder.create().serialize(this); } else { return super.serialize(); } }