Search in sources :

Example 1 with QueryResult

use of com.sforce.soap.partner.QueryResult in project teiid by teiid.

the class SalesForce41ExecutionFactory method buildQueryResult.

/*
     * Handles an api difference with {@link QueryResult}.setRecords
     */
@Override
public QueryResult buildQueryResult(SObject[] results) {
    QueryResult result = new QueryResult();
    result.setRecords(results);
    result.setSize(results.length);
    result.setDone(true);
    return result;
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult)

Example 2 with QueryResult

use of com.sforce.soap.partner.QueryResult in project teiid by teiid.

the class SalesForceExecutionFactory method buildQueryResult.

public QueryResult buildQueryResult(SObject[] objects) {
    QueryResult result = new QueryResult();
    result.setRecords(objects);
    result.setSize(objects.length);
    result.setDone(true);
    return result;
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult)

Example 3 with QueryResult

use of com.sforce.soap.partner.QueryResult 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 4 with QueryResult

use of com.sforce.soap.partner.QueryResult 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)

Example 5 with QueryResult

use of com.sforce.soap.partner.QueryResult in project teiid by teiid.

the class TestSalesForceDirectQueryExecution method testSearch.

@Test
public void testSearch() throws Exception {
    String input = "exec native('search;SELECT Account.Id, Account.Type, Account.Name FROM Account')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    QueryResult qr = Mockito.mock(QueryResult.class);
    Mockito.stub(qr.isDone()).toReturn(true);
    SObject[] results = new SObject[1];
    SObject s = new SObject();
    s.setType("Account");
    s.setId("The ID");
    results[0] = s;
    s.addField("Type", "The Type");
    s.addField("Name", "The Name");
    Mockito.stub(qr.getRecords()).toReturn(results);
    Mockito.stub(connection.query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false)).toReturn(qr);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection, Mockito.times(1)).query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false);
    assertArrayEquals(new Object[] { "The ID", "The Type", "The Name" }, (Object[]) execution.next().get(0));
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SObject(com.sforce.soap.partner.sobject.SObject) SObject(com.sforce.soap.partner.sobject.SObject) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Aggregations

QueryResult (com.sforce.soap.partner.QueryResult)11 Test (org.junit.Test)6 SObject (com.sforce.soap.partner.sobject.SObject)5 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)5 ExecutionContext (org.teiid.translator.ExecutionContext)5 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)5 SalesForceExecutionFactory (org.teiid.translator.salesforce.SalesForceExecutionFactory)4 Command (org.teiid.language.Command)2 Select (org.teiid.language.Select)2 ArrayList (java.util.ArrayList)1 ResourceException (javax.resource.ResourceException)1 TranslationUtility (org.teiid.cdk.api.TranslationUtility)1 Delete (org.teiid.language.Delete)1 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)1 Execution (org.teiid.translator.Execution)1 TranslatorException (org.teiid.translator.TranslatorException)1 SalesForce41ExecutionFactory (org.teiid.translator.salesforce.SalesForce41ExecutionFactory)1 SalesForce34ExecutionFactory (org.teiid.translator.salesforce34.SalesForce34ExecutionFactory)1