public QueryServiceResponse submitStatement()

in asterixdb-jdbc/asterix-jdbc-driver/src/main/java/org/apache/asterix/jdbc/ADBProtocol.java [214:274]


    public QueryServiceResponse submitStatement(String sql, List<?> args, SubmitStatementOptions options)
            throws SQLException {
        HttpPost httpPost = new HttpPost(queryEndpoint);
        httpPost.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON
                .withParameters(new BasicNameValuePair(FORMAT_LOSSLESS_ADM, Boolean.TRUE.toString())).toString());

        ByteArrayOutputStreamImpl baos = new ByteArrayOutputStreamImpl(512);
        try {
            JsonGenerator jsonGen =
                    driverContext.getGenericObjectWriter().getFactory().createGenerator(baos, JsonEncoding.UTF8);
            jsonGen.writeStartObject();
            jsonGen.writeStringField(CLIENT_TYPE, CLIENT_TYPE_JDBC);
            jsonGen.writeStringField(MODE, MODE_DEFERRED);
            jsonGen.writeStringField(STATEMENT, sql);
            jsonGen.writeBooleanField(SIGNATURE, true);
            jsonGen.writeStringField(PLAN_FORMAT, PLAN_FORMAT_STRING);
            jsonGen.writeNumberField(MAX_WARNINGS, maxWarnings);
            if (options.compileOnly) {
                jsonGen.writeBooleanField(COMPILE_ONLY, true);
            }
            if (options.forceReadOnly) {
                jsonGen.writeBooleanField(READ_ONLY, true);
            }
            if (options.sqlCompatMode) {
                jsonGen.writeBooleanField(SQL_COMPAT, true);
            }
            if (options.timeoutSeconds > 0) {
                jsonGen.writeStringField(TIMEOUT, options.timeoutSeconds + "s");
            }
            if (options.dataverseName != null) {
                jsonGen.writeStringField(DATAVERSE, options.dataverseName);
            }
            if (options.executionId != null) {
                jsonGen.writeStringField(CLIENT_CONTEXT_ID, options.executionId.toString());
            }
            if (args != null && !args.isEmpty()) {
                jsonGen.writeFieldName(ARGS);
                driverContext.getAdmFormatObjectWriter().writeValue(jsonGen, args);
            }
            jsonGen.writeEndObject();
            jsonGen.flush();
        } catch (InvalidDefinitionException e) {
            throw getErrorReporter().errorUnexpectedType(e.getType().getRawClass());
        } catch (IOException e) {
            throw getErrorReporter().errorInRequestGeneration(e);
        }

        if (getLogger().isLoggable(Level.FINE)) {
            getLogger().log(Level.FINE, String.format("%s { %s } with args { %s }",
                    options.compileOnly ? "compile" : "execute", sql, args != null ? args : ""));
        }

        httpPost.setEntity(new EntityTemplateImpl(baos, ContentType.APPLICATION_JSON));
        try (CloseableHttpResponse httpResponse = httpClient.execute(httpPost, httpClientContext)) {
            return handlePostQueryResponse(httpResponse);
        } catch (JsonProcessingException e) {
            throw getErrorReporter().errorInProtocol(e);
        } catch (IOException e) {
            throw getErrorReporter().errorInConnection(e);
        }
    }