use of com.sforce.async.JobInfo in project components by Talend.
the class SalesforceBulkRuntime method closeJob.
/**
* Close the job
*
* @throws AsyncApiException
* @throws ConnectionException
*/
public void closeJob() throws AsyncApiException, ConnectionException {
JobInfo closeJob = new JobInfo();
closeJob.setId(job.getId());
closeJob.setState(JobStateEnum.Closed);
try {
bulkConnection.updateJob(closeJob);
} catch (AsyncApiException sfException) {
if (AsyncExceptionCode.InvalidSessionId.equals(sfException.getExceptionCode())) {
SalesforceRuntimeCommon.renewSession(bulkConnection.getConfig());
closeJob();
} else if (AsyncExceptionCode.InvalidJobState.equals(sfException.getExceptionCode())) {
// Job is already closed on Salesforce side. We don't need to close it again.
return;
}
throw sfException;
}
}
use of com.sforce.async.JobInfo in project components by Talend.
the class SalesforceBulkRuntime method createJob.
/**
* Create a new job using the Bulk API.
*
* @return The JobInfo for the new job.
* @throws AsyncApiException
* @throws ConnectionException
*/
private JobInfo createJob() throws AsyncApiException, ConnectionException {
JobInfo job = new JobInfo();
if (concurrencyMode != null) {
job.setConcurrencyMode(concurrencyMode);
}
job.setObject(sObjectType);
job.setOperation(operation);
if (OperationEnum.upsert.equals(operation)) {
job.setExternalIdFieldName(externalIdFieldName);
}
job.setContentType(contentType);
job = createJob(job);
return job;
}
use of com.sforce.async.JobInfo in project teiid by teiid.
the class TestQueryExecutionImpl method testBulkFlow.
@Test
public void testBulkFlow() throws Exception {
// $NON-NLS-1$
Select command = (Select) translationUtility.parseCommand("select Name from Account");
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
JobInfo jobInfo = Mockito.mock(JobInfo.class);
Mockito.when(connection.createBulkJob(Mockito.anyString(), Mockito.eq(OperationEnum.query), Mockito.eq(true))).thenReturn(jobInfo);
final BatchResultInfo info = new BatchResultInfo("x");
Mockito.when(connection.getBatchQueryResults(Mockito.anyString(), Mockito.eq(info))).thenAnswer(new Answer<BulkBatchResult>() {
boolean first = true;
@Override
public BulkBatchResult answer(InvocationOnMock invocation) throws Throwable {
if (first) {
first = false;
throw new DataNotAvailableException();
}
if (info.getAndIncrementResultNum() == 0) {
final Iterator<List<String>> i = Arrays.asList(Arrays.asList("Name"), Arrays.asList("X")).iterator();
return new BulkBatchResult() {
@Override
public List<String> nextRecord() throws IOException {
if (!i.hasNext()) {
return null;
}
return i.next();
}
@Override
public void close() {
}
};
}
return null;
}
});
Mockito.when(connection.addBatch("SELECT Account.Name FROM Account", jobInfo)).thenReturn(info);
ExecutionContext mock = Mockito.mock(ExecutionContext.class);
Mockito.stub(mock.getSourceHints()).toReturn(Arrays.asList("bulk"));
QueryExecutionImpl execution = new QueryExecutionImpl(command, connection, Mockito.mock(RuntimeMetadata.class), mock, new SalesForceExecutionFactory());
execution.execute();
try {
execution.next();
fail();
} catch (DataNotAvailableException e) {
}
List<?> row = execution.next();
assertEquals(Arrays.asList("X"), row);
assertNull(execution.next());
}
use of com.sforce.async.JobInfo in project tdi-studio-se by Talend.
the class SalesforceBulkAPI method closeJob.
private void closeJob() throws AsyncApiException, ConnectionException {
JobInfo closeJob = new JobInfo();
closeJob.setId(job.getId());
closeJob.setState(JobStateEnum.Closed);
connection.updateJob(closeJob);
}
use of com.sforce.async.JobInfo in project tdi-studio-se by Talend.
the class SalesforceBulkAPI method doBulkQuery.
public void doBulkQuery(String moduleName, String queryStatement, int secToWait) throws AsyncApiException, InterruptedException, ConnectionException {
job = new JobInfo();
job.setObject(moduleName);
job.setOperation(OperationEnum.query);
if (concurrencyMode != null) {
job.setConcurrencyMode(concurrencyMode);
}
job.setContentType(ContentType.CSV);
job = connection.createJob(job);
job = connection.getJobStatus(job.getId());
batchInfoList = new ArrayList<BatchInfo>();
BatchInfo info = null;
ByteArrayInputStream bout = new ByteArrayInputStream(queryStatement.getBytes());
info = connection.createBatchFromStream(job, bout);
while (true) {
// default is 30 sec
Thread.sleep(secToWait * 1000);
info = connection.getBatchInfo(job.getId(), info.getId());
if (info.getState() == BatchStateEnum.Completed) {
QueryResultList list = connection.getQueryResultList(job.getId(), info.getId());
queryResultIDs = list.getResult();
break;
} else if (info.getState() == BatchStateEnum.Failed) {
throw new RuntimeException("-------------- failed ----------" + info);
} else {
System.out.println("-------------- waiting ----------" + info);
}
}
batchInfoList.add(info);
// For TDI-27909
closeJob();
}
Aggregations