Search in sources :

Example 6 with QueryResult

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

the class TestSalesForce41ExecutionFactory method testCreateResults.

@Test
public void testCreateResults() {
    SalesForce41ExecutionFactory ef = new SalesForce41ExecutionFactory();
    QueryResult qr = ef.buildQueryResult(new SObject[1]);
    assertTrue(qr.isDone());
    assertEquals(1, qr.getSize());
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) SalesForce41ExecutionFactory(org.teiid.translator.salesforce.SalesForce41ExecutionFactory) Test(org.junit.Test)

Example 7 with QueryResult

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

the class AbstractUpdateExecution method execute.

void execute(Condition criteria, IQueryProvidingVisitor visitor) throws TranslatorException {
    // Salesforce limit
    int batchSize = 2000;
    // Salesforce limit
    int updateSize = 200;
    String[] Ids = null;
    if (visitor.hasOnlyIDCriteria()) {
        try {
            String Id = ((Comparison) criteria).getRightExpression().toString();
            Id = Util.stripQutes(Id);
            Ids = new String[] { Id };
            result = processIds(Ids, visitor);
        } catch (ClassCastException cce) {
            throw new RuntimeException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13008));
        } catch (ResourceException e) {
            throw new TranslatorException(e);
        }
    } else {
        try {
            String query = visitor.getQuery();
            context.logCommand(query);
            QueryResult results = getConnection().query(query, batchSize, Boolean.FALSE);
            ArrayList<String> idList = new ArrayList<String>(results.getRecords().length);
            while (results != null) {
                if (results.getSize() > 0) {
                    for (int i = 0; i < results.getRecords().length; i++) {
                        SObject sObject = results.getRecords()[i];
                        idList.add(sObject.getId());
                        if (idList.size() == updateSize) {
                            Ids = idList.toArray(new String[0]);
                            result += processIds(Ids, visitor);
                            idList.clear();
                        }
                    }
                }
                if (results.isDone()) {
                    break;
                }
                results = connection.queryMore(results.getQueryLocator(), batchSize);
            }
            if (!idList.isEmpty()) {
                Ids = idList.toArray(new String[0]);
                result += processIds(Ids, visitor);
            }
        } catch (ResourceException e) {
            throw new TranslatorException(e);
        }
    }
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) ArrayList(java.util.ArrayList) SObject(com.sforce.soap.partner.sobject.SObject) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 8 with QueryResult

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

the class SalesForce34ExecutionFactory 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 9 with QueryResult

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

the class TestSalesForce34ExecutionFactory method testCreateResults.

@Test
public void testCreateResults() {
    SalesForce34ExecutionFactory ef = new SalesForce34ExecutionFactory();
    QueryResult qr = ef.buildQueryResult(new SObject[1]);
    assertTrue(qr.isDone());
    assertEquals(1, qr.getSize());
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) SalesForce34ExecutionFactory(org.teiid.translator.salesforce34.SalesForce34ExecutionFactory) Test(org.junit.Test)

Example 10 with QueryResult

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

the class TestUpdates method testIds.

@Test
public void testIds() throws Exception {
    Delete delete = (Delete) translationUtility.parseCommand("delete from contacts");
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    SalesForceExecutionFactory config = new SalesForceExecutionFactory();
    DeleteExecutionImpl updateExecution = new DeleteExecutionImpl(config, delete, connection, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class));
    ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
    QueryResult qr = new QueryResult();
    SObject so = new SObject();
    so.setType("Contact");
    so.addField("Id", "x");
    qr.setRecords(new SObject[] { so });
    qr.setSize(1);
    qr.setDone(true);
    Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(qr);
    Mockito.stub(connection.delete(new String[] { "x" })).toReturn(1);
    while (true) {
        try {
            updateExecution.execute();
            org.junit.Assert.assertArrayEquals(new int[] { 1 }, updateExecution.getUpdateCounts());
            break;
        } catch (DataNotAvailableException e) {
            continue;
        }
    }
    Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
    String query = queryArgument.getValue();
    assertEquals("SELECT Id FROM Contact ", query);
}
Also used : Delete(org.teiid.language.Delete) QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) SObject(com.sforce.soap.partner.sobject.SObject) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) 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