use of org.teiid.language.Argument in project teiid by teiid.
the class DirectQueryExecution method buildDataPlayload.
private DataPayload buildDataPlayload(String update) throws TranslatorException {
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(update, ";");
if (!st.hasMoreTokens()) {
throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13004));
}
String type = null;
String id = null;
DataPayload payload = new DataPayload();
while (st.hasMoreElements()) {
String var = st.nextToken();
int index = var.indexOf('=');
if (index == -1) {
continue;
}
String key = var.substring(0, index).trim().toLowerCase();
String value = var.substring(index + 1).trim();
if (key.equalsIgnoreCase(ATTRIBUTES)) {
// $NON-NLS-1$
StringTokenizer attrTokens = new StringTokenizer(value, ",");
int attrCount = 0;
while (attrTokens.hasMoreElements()) {
String name = attrTokens.nextToken().trim();
if (arguments.size() <= attrCount) {
throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13005, name));
}
Argument argument = arguments.get(attrCount++);
Object anObj = argument.getArgumentValue().getValue();
if (anObj == null) {
continue;
}
anObj = Util.stripQutes(anObj.toString());
payload.addField(name, anObj);
}
} else if (key.equalsIgnoreCase(TYPE)) {
type = value;
} else if (key.equalsIgnoreCase(ID)) {
id = value;
}
}
payload.setID(id);
payload.setType(type);
return payload;
}
use of org.teiid.language.Argument in project teiid by teiid.
the class GetDeletedExecutionImpl method execute.
@Override
public void execute(ProcedureExecutionParent procedureExecutionParent) throws TranslatorException {
try {
Call command = parent.getCommand();
List<Argument> params = command.getArguments();
Argument object = params.get(OBJECT);
String objectName = (String) object.getArgumentValue().getValue();
Argument start = params.get(STARTDATE);
Timestamp startTime = (Timestamp) start.getArgumentValue().getValue();
GregorianCalendar startCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
startCalendar.setTime(startTime);
Argument end = params.get(ENDDATE);
Timestamp endTime = (Timestamp) end.getArgumentValue().getValue();
GregorianCalendar endCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
endCalendar.setTime(endTime);
deletedResult = parent.getConnection().getDeleted(objectName, startCalendar, endCalendar);
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.language.Argument in project teiid by teiid.
the class GetUpdatedExecutionImpl method execute.
@Override
public void execute(ProcedureExecutionParent procedureExecutionParent) throws TranslatorException {
try {
Call command = parent.getCommand();
List<Argument> params = command.getArguments();
Argument object = params.get(OBJECT);
String objectName = (String) object.getArgumentValue().getValue();
Argument start = params.get(STARTDATE);
Timestamp startTime = (Timestamp) start.getArgumentValue().getValue();
GregorianCalendar startCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
startCalendar.setTime(startTime);
Argument end = params.get(ENDDATE);
Timestamp endTime = (Timestamp) end.getArgumentValue().getValue();
GregorianCalendar endCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
endCalendar.setTime(endTime);
updatedResult = parent.getConnection().getUpdated(objectName, startCalendar, endCalendar);
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.language.Argument in project teiid by teiid.
the class WSProcedureExecution method execute.
@SuppressWarnings("unchecked")
public void execute() throws TranslatorException {
List<Argument> arguments = this.procedure.getArguments();
String style = (String) arguments.get(0).getArgumentValue().getValue();
String action = (String) arguments.get(1).getArgumentValue().getValue();
XMLType docObject = (XMLType) arguments.get(2).getArgumentValue().getValue();
Source source = null;
try {
Class type = StAXSource.class;
if (executionFactory.getDefaultServiceMode() == Mode.MESSAGE) {
type = DOMSource.class;
}
source = convertToSource(type, docObject);
String endpoint = (String) arguments.get(3).getArgumentValue().getValue();
if (style == null) {
style = executionFactory.getDefaultBinding().getBindingId();
} else {
try {
style = Binding.valueOf(style.toUpperCase()).getBindingId();
} catch (IllegalArgumentException e) {
// $NON-NLS-1$
throw new TranslatorException(WSExecutionFactory.UTIL.getString("invalid_invocation", Arrays.toString(Binding.values())));
}
}
Dispatch dispatch = conn.createDispatch(style, endpoint, type, executionFactory.getDefaultServiceMode());
if (Binding.HTTP.getBindingId().equals(style)) {
if (action == null) {
// $NON-NLS-1$
action = "POST";
}
dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, action);
if (source != null && !"POST".equalsIgnoreCase(action)) {
// $NON-NLS-1$
if (this.executionFactory.getXMLParamName() == null) {
// $NON-NLS-1$
throw new WebServiceException(WSExecutionFactory.UTIL.getString("http_usage_error"));
}
try {
Transformer t = TransformerFactory.newInstance().newTransformer();
StringWriter writer = new StringWriter();
// TODO: prevent this from being too large
t.transform(source, new StreamResult(writer));
// $NON-NLS-1$
String param = Util.httpURLEncode(this.executionFactory.getXMLParamName()) + "=" + Util.httpURLEncode(writer.toString());
endpoint = WSConnection.Util.appendQueryString(endpoint, param);
} catch (TransformerException e) {
throw new WebServiceException(e);
}
}
} else {
if (action != null) {
dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, action);
}
}
if (source == null) {
// JBoss Native DispatchImpl throws exception when the source is null
// $NON-NLS-1$
source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<none/>")));
}
this.returnValue = (Source) dispatch.invoke(source);
} catch (SQLException e) {
throw new TranslatorException(e);
} catch (WebServiceException e) {
throw new TranslatorException(e);
} catch (XMLStreamException e) {
throw new TranslatorException(e);
} finally {
Util.closeSource(source);
}
}
use of org.teiid.language.Argument in project teiid by teiid.
the class TestSimpleDBExecution method testDirectExecution.
@Test
public void testDirectExecution() throws Exception {
SelectResult result = new SelectResult();
result.setItems(mockResult());
String query = "select * from item where attribute > 'name'";
Mockito.stub(connection.performSelect(Mockito.anyString(), Mockito.anyString())).toReturn(result);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
List<Argument> arguments = new ArrayList<Argument>();
Argument arg = new Argument(Direction.IN, String.class, Mockito.mock(ProcedureParameter.class));
arg.setArgumentValue(LanguageFactory.INSTANCE.createLiteral(query, String.class));
arguments.add(arg);
ResultSetExecution exec = translator.createDirectExecution(arguments, cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
List row = exec.next();
Mockito.verify(connection).performSelect("select * from item where attribute > 'name'", null);
Object[] results = (Object[]) row.get(0);
assertEquals("a1", results[0]);
assertEquals("[a2, a22]", results[1]);
}
Aggregations