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