use of com.sforce.async.AsyncApiException in project components by Talend.
the class SalesforceBulkQueryReader method start.
@Override
public boolean start() throws IOException {
try {
if (bulkRuntime == null) {
ConnectionHolder connectionHolder = ((SalesforceDataprepSource) getCurrentSource()).getConnectionHolder();
bulkRuntime = new SalesforceBulkRuntime(connectionHolder.bulkConnection);
}
executeSalesforceBulkQuery();
bulkResultSet = bulkRuntime.getQueryResultSet(bulkRuntime.nextResultId());
currentRecord = bulkResultSet.next();
boolean start = currentRecord != null;
if (start) {
dataCount++;
}
return start;
} catch (ConnectionException | AsyncApiException e) {
// Wrap the exception in an IOException.
throw new IOException(e);
}
}
use of com.sforce.async.AsyncApiException in project components by Talend.
the class SalesforceSourceOrSink method connectBulk.
protected BulkConnection connectBulk(ConnectorConfig config) throws ComponentException {
final SalesforceConnectionProperties connProps = getConnectionProperties();
/*
* When PartnerConnection is instantiated, a login is implicitly executed and, if successful, a valid session id is
* stored in the ConnectorConfig instance. Use this key to initialize a BulkConnection:
*/
ConnectorConfig bulkConfig = new ConnectorConfig();
setProxy(bulkConfig);
bulkConfig.setSessionId(config.getSessionId());
// For session renew
bulkConfig.setSessionRenewer(config.getSessionRenewer());
bulkConfig.setUsername(config.getUsername());
bulkConfig.setPassword(config.getPassword());
/*
* The endpoint for the Bulk API service is the same as for the normal SOAP uri until the /Soap/ part. From here
* it's '/async/versionNumber'
*/
String soapEndpoint = config.getServiceEndpoint();
// Service endpoint should be like this:
// https://ap1.salesforce.com/services/Soap/u/37.0/00D90000000eSq3
String apiVersion = soapEndpoint.substring(soapEndpoint.lastIndexOf("/services/Soap/u/") + 17);
apiVersion = apiVersion.substring(0, apiVersion.indexOf("/"));
String restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
bulkConfig.setRestEndpoint(restEndpoint);
// This should only be false when doing debugging.
bulkConfig.setCompression(connProps.needCompression.getValue());
bulkConfig.setTraceMessage(connProps.httpTraceMessage.getValue());
bulkConfig.setValidateSchema(false);
try {
return new BulkConnection(bulkConfig);
} catch (AsyncApiException e) {
throw new ComponentException(e);
}
}
use of com.sforce.async.AsyncApiException in project components by Talend.
the class SalesforceBulkExecRuntime method bulkExecute.
public void bulkExecute(RuntimeContainer container) {
TSalesforceBulkExecProperties sprops = (TSalesforceBulkExecProperties) properties;
try {
SalesforceBulkRuntime bulkRuntime = new SalesforceBulkRuntime(connect(container).bulkConnection);
bulkRuntime.setConcurrencyMode(sprops.bulkProperties.concurrencyMode.getValue());
bulkRuntime.setAwaitTime(sprops.bulkProperties.waitTimeCheckBatchState.getValue());
// We only support CSV file for bulk output
bulkRuntime.executeBulk(sprops.module.moduleName.getStringValue(), sprops.outputAction.getValue(), sprops.upsertKeyColumn.getStringValue(), "csv", sprops.bulkFilePath.getStringValue(), sprops.bulkProperties.bytesToCommit.getValue(), sprops.bulkProperties.rowsToCommit.getValue());
// count results
for (int i = 0; i < bulkRuntime.getBatchCount(); i++) {
for (BulkResult result : bulkRuntime.getBatchLog(i)) {
dataCount++;
if ("true".equalsIgnoreCase(String.valueOf(result.getValue("Success")))) {
successCount++;
} else {
rejectCount++;
}
}
}
bulkRuntime.close();
} catch (IOException | AsyncApiException | ConnectionException e) {
throw new ComponentException(e);
}
}
use of com.sforce.async.AsyncApiException in project components by Talend.
the class SalesforceBulkExecReader method start.
@Override
public boolean start() throws IOException {
TSalesforceBulkExecProperties sprops = (TSalesforceBulkExecProperties) properties;
bulkRuntime = new SalesforceBulkRuntime(((SalesforceSource) getCurrentSource()).connect(container).bulkConnection);
bulkRuntime.setConcurrencyMode(sprops.bulkProperties.concurrencyMode.getValue());
bulkRuntime.setAwaitTime(sprops.bulkProperties.waitTimeCheckBatchState.getValue());
try {
// We only support CSV file for bulk output
bulkRuntime.executeBulk(sprops.module.moduleName.getStringValue(), sprops.outputAction.getValue(), sprops.upsertKeyColumn.getStringValue(), "csv", sprops.bulkFilePath.getStringValue(), sprops.bulkProperties.bytesToCommit.getValue(), sprops.bulkProperties.rowsToCommit.getValue());
if (bulkRuntime.getBatchCount() > 0) {
batchIndex = 0;
currentBatchResult = bulkRuntime.getBatchLog(0);
resultIndex = 0;
boolean startable = currentBatchResult.size() > 0;
if (startable) {
countData();
}
return startable;
}
return false;
} catch (AsyncApiException | ConnectionException e) {
throw new IOException(e);
}
}
use of com.sforce.async.AsyncApiException in project components by Talend.
the class SalesforceBulkExecReader method advance.
@Override
public boolean advance() throws IOException {
if (++resultIndex >= currentBatchResult.size()) {
if (++batchIndex >= bulkRuntime.getBatchCount()) {
return false;
} else {
try {
currentBatchResult = bulkRuntime.getBatchLog(batchIndex);
resultIndex = 0;
boolean isAdvanced = currentBatchResult.size() > 0;
if (isAdvanced) {
countData();
}
return isAdvanced;
} catch (AsyncApiException | ConnectionException e) {
throw new IOException(e);
}
}
}
countData();
return true;
}
Aggregations