package org.embulk.input.salesforce_bulk;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sforce.async.AsyncApiException;
import com.sforce.async.AsyncExceptionCode;
import com.sforce.async.BatchInfo;
import com.sforce.async.BatchStateEnum;
import com.sforce.async.BulkConnection;
import com.sforce.async.ContentType;
import com.sforce.async.CSVReader;
import com.sforce.async.JobInfo;
import com.sforce.async.JobStateEnum;
import com.sforce.async.OperationEnum;
import com.sforce.async.QueryResultList;
import com.sforce.soap.partner.PartnerConnection;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
/**
* SalesforceBulkWrapper.
*
* -- example:
*
* {@code
* SalesforceBulkWrapper sfbw = new SalesforceBulkWrapper(
* USER_NAME,
* PASSWORD,
* AUTH_ENDPOINT_URL,
* IS_COMPRESSION,
* POLLING_INTERVAL_MILLISECOND);
* List
*/
public class SalesforceBulkWrapper implements AutoCloseable {
// コネクション
private PartnerConnection partnerConnection;
private BulkConnection bulkConnection;
// Bulk 接続設定
private boolean isCompression;
private int pollingIntervalMillisecond;
private boolean queryAll;
private static final String API_VERSION = "39.0";
private static final String AUTH_ENDPOINT_URL_DEFAULT =
"https://login.salesforce.com/services/Soap/u/" + API_VERSION;
private static final boolean IS_COMPRESSION_DEFAULT = true;
private static final int POLLING_INTERVAL_MILLISECOND_DEFAULT = 30000;
private static final boolean QUERY_ALL_DEFAULT = false;
/**
* Constructor
*/
public SalesforceBulkWrapper(String userName, String password)
throws AsyncApiException, ConnectionException {
this(userName,
password,
AUTH_ENDPOINT_URL_DEFAULT,
IS_COMPRESSION_DEFAULT,
POLLING_INTERVAL_MILLISECOND_DEFAULT,
QUERY_ALL_DEFAULT);
}
/**
* Constructor
*/
public SalesforceBulkWrapper(
String userName,
String password,
String authEndpointUrl,
boolean isCompression,
int pollingIntervalMillisecond,
boolean queryAll)
throws AsyncApiException, ConnectionException {
partnerConnection = createPartnerConnection(
authEndpointUrl,
userName,
password);
bulkConnection = createBulkConnection(partnerConnection.getConfig());
this.pollingIntervalMillisecond = pollingIntervalMillisecond;
this.queryAll = queryAll;
}
public List