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());
}
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]);
}
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;
}
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;
}
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();
}
}
}
}
Aggregations