Search in sources :

Example 1 with Argument

use of org.teiid.language.Argument in project teiid by teiid.

the class S3ProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    List<Argument> arguments = this.command.getArguments();
    if (command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.SAVEFILE)) {
        this.execution = saveFile(arguments);
        this.execution.execute();
        if (this.execution.getResponseCode() != 200) {
            throw new TranslatorException(S3ExecutionFactory.UTIL.gs("error_writing", this.endpoint, this.execution.getResponseCode(), getErrorDescription()));
        }
    } else if (command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.DELETEFILE)) {
        this.execution = deleteFile(arguments);
        this.execution.execute();
        if (this.execution.getResponseCode() != 204) {
            throw new TranslatorException(S3ExecutionFactory.UTIL.gs("error_deleting", this.endpoint, this.execution.getResponseCode(), getErrorDescription()));
        }
    } else if (command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.GETFILE) || command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.GETTEXTFILE)) {
        if (command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.GETTEXTFILE)) {
            this.isText = true;
        }
        this.execution = getFile(arguments);
        this.execution.execute();
        if (this.execution.getResponseCode() != 200) {
            throw new TranslatorException(S3ExecutionFactory.UTIL.gs("error_reading", this.endpoint, this.execution.getResponseCode(), getErrorDescription()));
        }
    } else if (command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.LISTBUCKET)) {
        this.execution = listBucket(arguments);
        this.execution.execute();
        if (this.execution.getResponseCode() != 200) {
            throw new TranslatorException(S3ExecutionFactory.UTIL.gs("error_list", this.endpoint, this.execution.getResponseCode(), getErrorDescription()));
        }
    }
}
Also used : Argument(org.teiid.language.Argument) TranslatorException(org.teiid.translator.TranslatorException)

Example 2 with Argument

use of org.teiid.language.Argument in project teiid by teiid.

the class S3ProcedureExecution method invokeHTTP.

protected BinaryWSProcedureExecution invokeHTTP(String method, String uri, Object payload, Map<String, String> headers) throws TranslatorException {
    Map<String, List<String>> targetHeaders = new HashMap<String, List<String>>();
    headers.forEach((k, v) -> targetHeaders.put(k, Arrays.asList(v)));
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_WS, MessageLevel.DETAIL)) {
        try {
            LogManager.logDetail(LogConstants.CTX_WS, "Source-URL=", // $NON-NLS-1$ //$NON-NLS-2$
            URLDecoder.decode(uri, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
        }
    }
    List<Argument> parameters = new ArrayList<Argument>();
    parameters.add(new Argument(Direction.IN, new Literal(method, TypeFacility.RUNTIME_TYPES.STRING), null));
    parameters.add(new Argument(Direction.IN, new Literal(payload, TypeFacility.RUNTIME_TYPES.OBJECT), null));
    parameters.add(new Argument(Direction.IN, new Literal(uri, TypeFacility.RUNTIME_TYPES.STRING), null));
    parameters.add(new Argument(Direction.IN, new Literal(true, TypeFacility.RUNTIME_TYPES.BOOLEAN), null));
    // the engine currently always associates out params at resolve time even if the
    // values are not directly read by the call
    parameters.add(new Argument(Direction.OUT, TypeFacility.RUNTIME_TYPES.STRING, null));
    Call call = this.ef.getLanguageFactory().createCall("invokeHttp", parameters, null);
    BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.ec, null, this.conn);
    execution.setUseResponseContext(true);
    execution.setCustomHeaders(targetHeaders);
    return execution;
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) HashMap(java.util.HashMap) Literal(org.teiid.language.Literal) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Argument

use of org.teiid.language.Argument in project teiid by teiid.

the class DirectQueryExecution method doDelete.

private void doDelete() throws TranslatorException {
    List<String> ids = new ArrayList<String>();
    for (Argument arg : arguments) {
        Object val = arg.getArgumentValue().getValue();
        if (val != null) {
            ids.add(Util.stripQutes(val.toString()));
        }
    }
    try {
        this.updateCount = this.connection.delete(ids.toArray(new String[ids.size()]));
        this.updateQuery = true;
    } catch (ResourceException e) {
        throw new TranslatorException(e);
    }
}
Also used : Argument(org.teiid.language.Argument) ArrayList(java.util.ArrayList) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 4 with Argument

use of org.teiid.language.Argument in project teiid by teiid.

the class ODataProcedureExecution method getQueryParameters.

static String getQueryParameters(Call obj) throws EdmPrimitiveTypeException {
    StringBuilder sb = new StringBuilder();
    final List<Argument> params = obj.getArguments();
    if (params != null && params.size() != 0) {
        Argument param = null;
        for (int i = 0; i < params.size(); i++) {
            param = params.get(i);
            if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) {
                if (i != 0) {
                    // $NON-NLS-1$
                    sb.append("&");
                }
                sb.append(WSConnection.Util.httpURLEncode(param.getMetadataObject().getName()));
                sb.append(Tokens.EQ);
                sb.append(WSConnection.Util.httpURLEncode(ODataTypeManager.convertToODataURIValue(param.getArgumentValue().getValue(), ODataTypeManager.odataType(param.getType()).getFullQualifiedName().getFullQualifiedNameAsString())));
            }
        }
    }
    return sb.toString();
}
Also used : Argument(org.teiid.language.Argument)

Example 5 with Argument

use of org.teiid.language.Argument in project teiid by teiid.

the class JDBCBaseExecution method bind.

/**
 * Bind the values in the TranslatedCommand to the PreparedStatement
 */
protected void bind(PreparedStatement stmt, List<?> params, List<?> batchValues) throws SQLException {
    for (int i = 0; i < params.size(); i++) {
        Object paramValue = params.get(i);
        Object value = null;
        Class<?> paramType = null;
        if (paramValue instanceof Literal) {
            Literal litParam = (Literal) paramValue;
            value = litParam.getValue();
            paramType = litParam.getType();
        } else if (paramValue instanceof Argument) {
            Argument arg = (Argument) paramValue;
            value = ((Literal) arg.getExpression()).getValue();
            paramType = arg.getType();
        } else {
            Parameter param = (Parameter) paramValue;
            if (batchValues == null) {
                // $NON-NLS-1$
                throw new AssertionError("Expected batchValues when using a Parameter");
            }
            value = batchValues.get(param.getValueIndex());
            paramType = param.getType();
        }
        this.executionFactory.bindValue(stmt, value, paramType, i + 1);
    }
    if (batchValues != null) {
        stmt.addBatch();
    }
}
Also used : Argument(org.teiid.language.Argument) Literal(org.teiid.language.Literal) Parameter(org.teiid.language.Parameter)

Aggregations

Argument (org.teiid.language.Argument)27 TranslatorException (org.teiid.translator.TranslatorException)13 Literal (org.teiid.language.Literal)12 ArrayList (java.util.ArrayList)9 Call (org.teiid.language.Call)9 SQLException (java.sql.SQLException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 List (java.util.List)4 Test (org.junit.Test)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4 DBCollection (com.mongodb.DBCollection)3 IOException (java.io.IOException)3 Timestamp (java.sql.Timestamp)3 HashMap (java.util.HashMap)3 StringTokenizer (java.util.StringTokenizer)3 ResourceException (javax.resource.ResourceException)3 DB (com.mongodb.DB)2 DBObject (com.mongodb.DBObject)2 SObject (com.sforce.soap.partner.sobject.SObject)2 XmlObject (com.sforce.ws.bind.XmlObject)2