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());
}
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);
}
}
}
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;
}
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());
}
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);
}
Aggregations