Search in sources :

Example 16 with Argument

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

the class TestMongoDBDirectQueryExecution method testShellDirect.

@Test
public void testShellDirect() throws Exception {
    Command cmd = this.utility.parseCommand("SELECT * FROM Customers");
    MongoDBConnection connection = Mockito.mock(MongoDBConnection.class);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    DBCollection dbCollection = Mockito.mock(DBCollection.class);
    DB db = Mockito.mock(DB.class);
    Mockito.stub(db.getCollection("MyTable")).toReturn(dbCollection);
    Mockito.stub(db.collectionExists(Mockito.anyString())).toReturn(true);
    Mockito.stub(connection.getDatabase()).toReturn(db);
    Argument arg = new Argument(Direction.IN, null, String.class, null);
    arg.setArgumentValue(new Literal("$ShellCmd;MyTable;remove;{ qty: { $gt: 20 }}", String.class));
    ResultSetExecution execution = this.translator.createDirectExecution(Arrays.asList(arg), cmd, context, this.utility.createRuntimeMetadata(), connection);
    execution.execute();
    Mockito.verify(dbCollection).remove(QueryBuilder.start("qty").greaterThan(20).get());
}
Also used : DBCollection(com.mongodb.DBCollection) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Argument(org.teiid.language.Argument) Command(org.teiid.language.Command) MongoDBConnection(org.teiid.mongodb.MongoDBConnection) Literal(org.teiid.language.Literal) DB(com.mongodb.DB) Test(org.junit.Test)

Example 17 with Argument

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

the class LoopbackExecution method getOutputParameterValues.

@Override
public List<?> getOutputParameterValues() throws TranslatorException {
    Call proc = (Call) this.command;
    int count = proc.getReturnType() != null ? 1 : 0;
    for (Argument param : proc.getArguments()) {
        if (param.getDirection() == Direction.INOUT || param.getDirection() == Direction.OUT) {
            count++;
        }
    }
    return Arrays.asList(new Object[count]);
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument)

Example 18 with Argument

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

the class BaseQueryExecution method invokeHTTP.

protected BinaryWSProcedureExecution invokeHTTP(String method, String uri, String payload, Map<String, List<String>> headers) throws TranslatorException {
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)) {
        try {
            LogManager.logDetail(LogConstants.CTX_ODATA, "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.STRING), 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.translator.getLanguageFactory().createCall(ODataExecutionFactory.INVOKE_HTTP, parameters, null);
    BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.executionContext, null, this.connection);
    execution.setUseResponseContext(true);
    execution.setCustomHeaders(headers);
    execution.execute();
    return execution;
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Literal(org.teiid.language.Literal) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 19 with Argument

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

the class BaseQueryExecution method executeDirect.

protected BinaryWSProcedureExecution executeDirect(String method, String uri, String payload, Map<String, List<String>> headers) throws TranslatorException {
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)) {
        try {
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logDetail(LogConstants.CTX_ODATA, "Source-URL=", 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.STRING), 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.translator.getLanguageFactory().createCall(ODataExecutionFactory.INVOKE_HTTP, parameters, null);
    BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.executionContext, null, this.connection);
    execution.setUseResponseContext(true);
    execution.setCustomHeaders(headers);
    execution.execute();
    return execution;
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Literal(org.teiid.language.Literal) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 20 with Argument

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

the class ODataProcedureVisitor method visit.

@Override
public void visit(Call obj) {
    Procedure proc = obj.getMetadataObject();
    this.method = proc.getProperty(ODataMetadataProcessor.HTTP_METHOD, false);
    this.procedure = proc;
    this.buffer.append(obj.getProcedureName());
    final List<Argument> params = obj.getArguments();
    if (params != null && params.size() != 0) {
        // $NON-NLS-1$
        this.buffer.append("?");
        Argument param = null;
        StringBuilder temp = new StringBuilder();
        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$
                    this.buffer.append("&");
                }
                this.buffer.append(WSConnection.Util.httpURLEncode(param.getMetadataObject().getName()));
                this.buffer.append(Tokens.EQ);
                this.executionFactory.convertToODataInput(param.getArgumentValue(), temp);
                this.buffer.append(WSConnection.Util.httpURLEncode(temp.toString()));
                temp.setLength(0);
            }
        }
    }
    // this is collection based result
    if (proc.getResultSet() != null) {
        this.returnsTable = true;
        this.returnEntityTypeName = proc.getProperty(ODataMetadataProcessor.ENTITY_TYPE, false);
        this.entity = getTableWithEntityType(proc.getParent(), returnEntityTypeName);
        this.isComplexReturnType = (this.entity == null);
        this.returnColumns = proc.getResultSet().getColumns();
    } else {
        for (ProcedureParameter param : proc.getParameters()) {
            if (param.getType().equals(ProcedureParameter.Type.ReturnValue)) {
                this.returnType = param.getRuntimeType();
                this.returnTypeClass = param.getJavaType();
            }
        }
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Argument(org.teiid.language.Argument) Procedure(org.teiid.metadata.Procedure)

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