Search in sources :

Example 21 with Argument

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) Argument(org.teiid.language.Argument) TranslatorException(org.teiid.translator.TranslatorException) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject)

Example 22 with Argument

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);
    }
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) GregorianCalendar(java.util.GregorianCalendar) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException) Timestamp(java.sql.Timestamp)

Example 23 with Argument

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);
    }
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) GregorianCalendar(java.util.GregorianCalendar) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException) Timestamp(java.sql.Timestamp)

Example 24 with Argument

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);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) Argument(org.teiid.language.Argument) WebServiceException(javax.xml.ws.WebServiceException) StreamResult(javax.xml.transform.stream.StreamResult) SQLException(java.sql.SQLException) Dispatch(javax.xml.ws.Dispatch) StAXSource(javax.xml.transform.stax.StAXSource) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StAXSource(javax.xml.transform.stax.StAXSource) XMLType(org.teiid.core.types.XMLType) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) TranslatorException(org.teiid.translator.TranslatorException) TransformerException(javax.xml.transform.TransformerException)

Example 25 with Argument

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]);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Argument(org.teiid.language.Argument) ArrayList(java.util.ArrayList) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

Argument (org.teiid.language.Argument)27 TranslatorException (org.teiid.translator.TranslatorException)13 Literal (org.teiid.language.Literal)12 ArrayList (java.util.ArrayList)9 Call (org.teiid.language.Call)9 SQLException (java.sql.SQLException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 List (java.util.List)4 Test (org.junit.Test)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4 DBCollection (com.mongodb.DBCollection)3 IOException (java.io.IOException)3 Timestamp (java.sql.Timestamp)3 HashMap (java.util.HashMap)3 StringTokenizer (java.util.StringTokenizer)3 ResourceException (javax.resource.ResourceException)3 DB (com.mongodb.DB)2 DBObject (com.mongodb.DBObject)2 SObject (com.sforce.soap.partner.sobject.SObject)2 XmlObject (com.sforce.ws.bind.XmlObject)2