Search in sources :

Example 1 with Call

use of org.teiid.language.Call 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 2 with Call

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

the class TestConnectorWorkItem method testProcedureBatching.

@Test
public void testProcedureBatching() throws Exception {
    ProcedureExecution exec = new FakeProcedureExecution(2, 1);
    // this has two result set columns and 1 out parameter
    int total_columns = 3;
    // $NON-NLS-1$
    StoredProcedure command = (StoredProcedure) helpGetCommand("{call pm2.spTest8(?)}", EXAMPLE_BQT);
    command.getInputParameters().get(0).setExpression(new Constant(1));
    Call proc = new LanguageBridgeFactory(EXAMPLE_BQT).translate(command);
    ProcedureBatchHandler pbh = new ProcedureBatchHandler(proc, exec);
    assertEquals(total_columns, pbh.padRow(Arrays.asList(null, null)).size());
    List params = pbh.getParameterRow();
    assertEquals(total_columns, params.size());
    // check the parameter value
    assertEquals(Integer.valueOf(0), params.get(2));
    try {
        pbh.padRow(Arrays.asList(1));
        // $NON-NLS-1$
        fail("Expected exception from resultset mismatch");
    } catch (TranslatorException err) {
        assertEquals("TEIID30479 Could not process stored procedure results for EXEC spTest8(1).  Expected 2 result set columns, but was 1.  Please update your models to allow for stored procedure results batching.", // $NON-NLS-1$
        err.getMessage());
    }
}
Also used : Call(org.teiid.language.Call) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) ProcedureExecution(org.teiid.translator.ProcedureExecution) Constant(org.teiid.query.sql.symbol.Constant) List(java.util.List) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) SourceHint(org.teiid.query.sql.lang.SourceHint) Test(org.junit.Test)

Example 3 with Call

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

the class TestProcedureImpl method testGetParameters.

public void testGetParameters() throws Exception {
    Call exec = example();
    assertNotNull(exec.getArguments());
    assertEquals(2, exec.getArguments().size());
}
Also used : Call(org.teiid.language.Call)

Example 4 with Call

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

the class JDBCProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    Call procedure = (Call) command;
    columnDataTypes = procedure.getResultSetColumnTypes();
    // translate command
    TranslatedCommand translatedComm = translateCommand(procedure);
    // create statement or CallableStatement and execute
    String sql = translatedComm.getSql();
    try {
        // create parameter index map
        CallableStatement cstmt = getCallableStatement(sql);
        this.results = this.executionFactory.executeStoredProcedure(cstmt, translatedComm.getPreparedValues(), procedure.getReturnType());
        addStatementWarnings();
    } catch (SQLException e) {
        throw new TranslatorException(JDBCPlugin.Event.TEIID11004, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11004, sql));
    }
}
Also used : Call(org.teiid.language.Call) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) TranslatorException(org.teiid.translator.TranslatorException)

Example 5 with Call

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

the class TestMetadataObject method getProcedureID.

// ################ TEST PROCEDURE AND PARAMETER METADATAID ######################
public Procedure getProcedureID(String procName, int inputParamCount, TranslationUtility transUtil) {
    // $NON-NLS-1$
    StringBuffer sql = new StringBuffer("EXEC ");
    sql.append(procName);
    // $NON-NLS-1$
    sql.append("(");
    for (int i = 0; i < inputParamCount; i++) {
        // $NON-NLS-1$
        sql.append("null");
        if (i < (inputParamCount - 1)) {
            // $NON-NLS-1$
            sql.append(", ");
        }
    }
    // $NON-NLS-1$
    sql.append(")");
    Call proc = (Call) transUtil.parseCommand(sql.toString());
    return proc.getMetadataObject();
}
Also used : Call(org.teiid.language.Call)

Aggregations

Call (org.teiid.language.Call)29 Test (org.junit.Test)12 Argument (org.teiid.language.Argument)9 ArrayList (java.util.ArrayList)8 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)7 ExecutionContext (org.teiid.translator.ExecutionContext)7 Properties (java.util.Properties)6 MetadataFactory (org.teiid.metadata.MetadataFactory)6 TranslatorException (org.teiid.translator.TranslatorException)6 List (java.util.List)5 DataSource (javax.activation.DataSource)5 CommandBuilder (org.teiid.cdk.CommandBuilder)5 RuntimeMetadataImpl (org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl)5 Literal (org.teiid.language.Literal)5 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)5 WSConnection (org.teiid.translator.WSConnection)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Procedure (org.teiid.metadata.Procedure)4 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4