Search in sources :

Example 6 with SQLParameter

use of org.teiid.odata.api.SQLParameter in project teiid by teiid.

the class TestODataSQLBuilder method helpTest.

public QueryState helpTest(String url, String sqlExpected, Integer skip, Integer top, Boolean count) throws Exception {
    QueryState state = setup(url);
    Client client = state.client;
    ArgumentCaptor<Query> arg1 = ArgumentCaptor.forClass(Query.class);
    ArgumentCaptor<EntityCollectionResponse> arg6 = ArgumentCaptor.forClass(EntityCollectionResponse.class);
    List<SQLParameter> parameters = new ArrayList<SQLParameter>();
    if (sqlExpected != null) {
        Query actualCommand = (Query) QueryParser.getQueryParser().parseCommand(sqlExpected, new ParseInfo());
        Mockito.verify(client).executeSQL(arg1.capture(), Mockito.eq(parameters), Mockito.eq(count), (Integer) Mockito.eq(skip), (Integer) Mockito.eq(top), (String) Mockito.eq(null), Mockito.anyInt(), arg6.capture());
        Assert.assertEquals(actualCommand.toString(), arg1.getValue().toString());
    }
    state.parameters = parameters;
    state.arg1 = arg1;
    state.arg6 = arg6;
    return state;
}
Also used : Query(org.teiid.query.sql.lang.Query) EntityCollectionResponse(org.teiid.olingo.service.EntityCollectionResponse) SQLParameter(org.teiid.odata.api.SQLParameter) ArrayList(java.util.ArrayList) ParseInfo(org.teiid.query.parser.ParseInfo) Client(org.teiid.odata.api.Client)

Example 7 with SQLParameter

use of org.teiid.odata.api.SQLParameter in project teiid by teiid.

the class LocalClient method executeCall.

@Override
public void executeCall(String sql, List<SQLParameter> parameters, ProcedureReturnType returnType, OperationResponse response) throws SQLException {
    // $NON-NLS-1$
    LogManager.logDetail(LogConstants.CTX_ODATA, "Teiid-Query:", sql);
    final CallableStatement stmt = getConnection().prepareCall(sql);
    int i = 1;
    if (!returnType.hasResultSet()) {
        stmt.registerOutParameter(i++, returnType.getSqlType());
    }
    if (!parameters.isEmpty()) {
        for (SQLParameter param : parameters) {
            stmt.setObject(i++, param.getValue(), param.getSqlType());
        }
    }
    boolean results = stmt.execute();
    if (results) {
        final ResultSet rs = stmt.getResultSet();
        while (rs.next()) {
            response.addRow(rs);
        }
    }
    if (!returnType.hasResultSet()) {
        Object result = stmt.getObject(1);
        response.setReturnValue(result);
    }
}
Also used : CallableStatement(java.sql.CallableStatement) SQLParameter(org.teiid.odata.api.SQLParameter) ResultSet(java.sql.ResultSet) CacheHint(org.teiid.query.sql.lang.CacheHint)

Aggregations

SQLParameter (org.teiid.odata.api.SQLParameter)7 TeiidException (org.teiid.core.TeiidException)2 SubqueryHint (org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)2 Reference (org.teiid.query.sql.symbol.Reference)2 CallableStatement (java.sql.CallableStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 BlobImpl (org.teiid.core.types.BlobImpl)1 ClobImpl (org.teiid.core.types.ClobImpl)1 ClobType (org.teiid.core.types.ClobType)1 InputStreamFactory (org.teiid.core.types.InputStreamFactory)1 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)1 Column (org.teiid.metadata.Column)1 Client (org.teiid.odata.api.Client)1 EntityCollectionResponse (org.teiid.olingo.service.EntityCollectionResponse)1 ParseInfo (org.teiid.query.parser.ParseInfo)1 CacheHint (org.teiid.query.sql.lang.CacheHint)1 Query (org.teiid.query.sql.lang.Query)1 Constant (org.teiid.query.sql.symbol.Constant)1