Search in sources :

Example 16 with SObject

use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.

the class DirectQueryExecution method loadBatch.

private List<List<Object>> loadBatch(QueryResult queryResult) {
    List<List<Object>> batch = new ArrayList<List<Object>>();
    for (SObject sObject : queryResult.getRecords()) {
        Iterator<XmlObject> fields = sObject.getChildren();
        List<Object> row = new ArrayList<Object>();
        while (fields.hasNext()) {
            XmlObject elem = fields.next();
            if (elem.getName().getLocalPart().equals("type")) {
                // $NON-NLS-1$
                continue;
            }
            Object value = elem.getValue();
            row.add(value);
        }
        batch.add(row);
    }
    return batch;
}
Also used : ArrayList(java.util.ArrayList) SObject(com.sforce.soap.partner.sobject.SObject) ArrayList(java.util.ArrayList) List(java.util.List) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject)

Example 17 with SObject

use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.

the class QueryExecutionImpl method extractValuesFromElement.

// TODO: this looks inefficient as getChild is linear
private List<Object[]> extractValuesFromElement(XmlObject sObject, List<Object[]> result, String sObjectName) throws TranslatorException {
    Object[] row = new Object[visitor.getSelectSymbolCount()];
    for (int j = 0; j < visitor.getSelectSymbolCount(); j++) {
        // must be a column reference as we won't allow an agg over a join
        Column element = ((ColumnReference) visitor.getSelectSymbolMetadata(j)).getMetadataObject();
        AbstractMetadataRecord table = element.getParent();
        if (table.getSourceName().equals(sObjectName)) {
            XmlObject child = sObject.getChild(element.getSourceName());
            Object cell = getCellDatum(element.getSourceName(), element.getJavaType(), child);
            setElementValueInColumn(j, cell, row);
        }
    }
    result.add(row);
    return result;
}
Also used : Column(org.teiid.metadata.Column) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 18 with SObject

use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.

the class QueryExecutionImpl method getObjectData.

private List<Object[]> getObjectData(SObject sObject) throws TranslatorException {
    Iterator<XmlObject> topFields = sObject.getChildren();
    ArrayList<XmlObject> children = new ArrayList<XmlObject>();
    while (topFields.hasNext()) {
        children.add(topFields.next());
    }
    logAndMapFields(sObject.getType(), children);
    List<Object[]> result = new ArrayList<Object[]>();
    if (visitor instanceof JoinQueryVisitor) {
        for (int i = 0; i < children.size(); i++) {
            XmlObject element = children.get(i);
            extactJoinResults(element, result);
        }
    }
    return extractDataFromFields(sObject, children, result);
}
Also used : JoinQueryVisitor(org.teiid.translator.salesforce.execution.visitors.JoinQueryVisitor) XmlObject(com.sforce.ws.bind.XmlObject) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject)

Example 19 with SObject

use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.

the class TestQueryExecutionImpl method testJoin.

@Test
public void testJoin() throws Exception {
    // $NON-NLS-1$
    Select command = (Select) translationUtility.parseCommand("select Account.Name, Contact.Id from Account inner join Contact on Account.Id = Contact.AccountId");
    SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);
    QueryResult qr = new QueryResult();
    SObject so = new SObject();
    so.setType("Account");
    so.addField("Name", "account name");
    SObject so1 = new SObject();
    so1.setType("Contact");
    so1.addField("Id", "contact id");
    so.addField("Contacts", so1);
    qr.setRecords(new SObject[] { so });
    qr.setDone(true);
    Mockito.stub(sfc.query("SELECT Account.Name, Contact.Id FROM Contact WHERE Contact.AccountId != NULL", 0, false)).toReturn(qr);
    QueryExecutionImpl qei = new QueryExecutionImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class), new SalesForceExecutionFactory());
    qei.execute();
    assertEquals(Arrays.asList("account name", "contact id"), qei.next());
    assertNull(qei.next());
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) Select(org.teiid.language.Select) SObject(com.sforce.soap.partner.sobject.SObject) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 20 with SObject

use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.

the class TestQueryExecutionImpl method testBatching.

@Test
public void testBatching() throws Exception {
    // $NON-NLS-1$
    Select command = (Select) translationUtility.parseCommand("select Name from Account");
    SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);
    QueryResult qr = new QueryResult();
    SObject so = new SObject();
    so.setType("Account");
    so.addField("Name", null);
    qr.setRecords(new SObject[] { so });
    qr.setDone(false);
    QueryResult finalQr = new QueryResult();
    finalQr.setRecords(new SObject[] { so });
    finalQr.setDone(true);
    Mockito.stub(sfc.query("SELECT Account.Name FROM Account", 0, false)).toReturn(qr);
    Mockito.stub(sfc.queryMore(null, 0)).toReturn(finalQr);
    QueryExecutionImpl qei = new QueryExecutionImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class), new SalesForceExecutionFactory());
    qei.execute();
    assertNotNull(qei.next());
    assertNotNull(qei.next());
    assertNull(qei.next());
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) Select(org.teiid.language.Select) SObject(com.sforce.soap.partner.sobject.SObject) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Aggregations

SObject (com.sforce.soap.partner.sobject.SObject)45 XmlObject (com.sforce.ws.bind.XmlObject)23 Test (org.junit.Test)11 KettleException (org.pentaho.di.core.exception.KettleException)11 ArrayList (java.util.ArrayList)10 ConnectionException (com.sforce.ws.ConnectionException)9 KettleStepException (org.pentaho.di.core.exception.KettleStepException)9 QueryResult (com.sforce.soap.partner.QueryResult)5 IOException (java.io.IOException)5 ResourceException (javax.resource.ResourceException)5 QName (javax.xml.namespace.QName)5 Schema (org.apache.avro.Schema)5 SaveResult (com.sforce.soap.partner.SaveResult)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)4 ExecutionContext (org.teiid.translator.ExecutionContext)4 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 InvalidFieldFault (com.sforce.soap.partner.fault.InvalidFieldFault)3