Search in sources :

Example 6 with AsyncApiException

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);
    }
}
Also used : SalesforceBulkRuntime(org.talend.components.salesforce.runtime.SalesforceBulkRuntime) IOException(java.io.IOException) ConnectionException(com.sforce.ws.ConnectionException) AsyncApiException(com.sforce.async.AsyncApiException) ConnectionHolder(org.talend.components.salesforce.runtime.common.ConnectionHolder)

Example 7 with AsyncApiException

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);
    }
}
Also used : SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) ConnectorConfig(com.sforce.ws.ConnectorConfig) ComponentException(org.talend.components.api.exception.ComponentException) BulkConnection(com.sforce.async.BulkConnection) AsyncApiException(com.sforce.async.AsyncApiException)

Example 8 with AsyncApiException

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);
    }
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException) AsyncApiException(com.sforce.async.AsyncApiException) ConnectionException(com.sforce.ws.ConnectionException) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)

Example 9 with AsyncApiException

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);
    }
}
Also used : IOException(java.io.IOException) AsyncApiException(com.sforce.async.AsyncApiException) ConnectionException(com.sforce.ws.ConnectionException) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)

Example 10 with AsyncApiException

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;
}
Also used : IOException(java.io.IOException) AsyncApiException(com.sforce.async.AsyncApiException) ConnectionException(com.sforce.ws.ConnectionException)

Aggregations

AsyncApiException (com.sforce.async.AsyncApiException)10 IOException (java.io.IOException)6 ConnectionException (com.sforce.ws.ConnectionException)5 ComponentException (org.talend.components.api.exception.ComponentException)3 BulkConnection (com.sforce.async.BulkConnection)2 ConnectorConfig (com.sforce.ws.ConnectorConfig)2 TSalesforceBulkExecProperties (org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)2 BatchInfo (com.sforce.async.BatchInfo)1 BatchInfoList (com.sforce.async.BatchInfoList)1 JobInfo (com.sforce.async.JobInfo)1 QueryResultList (com.sforce.async.QueryResultList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Predicate (org.apache.gobblin.source.extractor.watermark.Predicate)1 Test (org.junit.Test)1 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)1 SalesforceBulkRuntime (org.talend.components.salesforce.runtime.SalesforceBulkRuntime)1 ConnectionHolder (org.talend.components.salesforce.runtime.common.ConnectionHolder)1 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)1