use of org.talend.components.salesforce.runtime.common.ConnectionHolder in project components by Talend.
the class SalesforceReader method getConnection.
protected PartnerConnection getConnection() throws IOException {
if (connection == null) {
ConnectionHolder ch = ((SalesforceSource) getCurrentSource()).connect(container);
connection = ch.connection;
if (ch.bulkConnection != null) {
LOGGER.info(MESSAGES.getMessage("info.bulkConnectionUsage"));
}
}
return connection;
}
use of org.talend.components.salesforce.runtime.common.ConnectionHolder in project components by Talend.
the class SalesforceServerTimeStampReader method start.
@Override
public boolean start() throws IOException {
ConnectionHolder ch = ((SalesforceSource) getCurrentSource()).connect(container);
PartnerConnection connection = ch.connection;
if (ch.bulkConnection != null) {
LOGGER.info(MESSAGES.getMessage("info.bulkConnectionUsage"));
}
try {
Calendar serverTimestamp = connection.getServerTimestamp().getTimestamp();
if (serverTimestamp != null) {
long timestamp = serverTimestamp.getTimeInMillis();
result = new GenericData.Record(properties.schema.schema.getValue());
result.put(0, timestamp);
}
if (result != null) {
dataCount++;
return true;
} else {
return false;
}
} catch (ConnectionException e) {
throw new IOException(e);
}
}
use of org.talend.components.salesforce.runtime.common.ConnectionHolder in project components by Talend.
the class SalesforceDataprepSource method connect.
ConnectionHolder connect(RuntimeContainer container) throws IOException {
SalesforceRuntimeCommon.enableTLSv11AndTLSv12ForJava7();
final ConnectionHolder ch = new ConnectionHolder();
ConnectorConfig config = new ConnectorConfig();
config.setUsername(datastore.userId.getValue());
String password = datastore.password.getValue();
String securityKey = datastore.securityKey.getValue();
if (!StringUtils.isEmpty(securityKey)) {
password = password + securityKey;
}
config.setPassword(password);
// Notes on how to test this
// http://thysmichels.com/2014/02/15/salesforce-wsc-partner-connection-session-renew-when-session-timeout/
config.setSessionRenewer(new SessionRenewer() {
@Override
public SessionRenewalHeader renewSession(ConnectorConfig connectorConfig) throws ConnectionException {
LOG.debug("renewing session...");
SessionRenewalHeader header = new SessionRenewalHeader();
connectorConfig.setSessionId(null);
PartnerConnection connection = doConnection(connectorConfig);
// update the connection session header
ch.connection.setSessionHeader(connection.getSessionHeader().getSessionId());
header.name = new QName("urn:partner.soap.sforce.com", "SessionHeader");
header.headerElement = connection.getSessionHeader();
LOG.debug("session renewed!");
return header;
}
});
config.setConnectionTimeout(timeout);
// This should only be false when doing debugging.
config.setCompression(true);
config.setUseChunkedPost(true);
config.setValidateSchema(false);
try {
ch.connection = doConnection(config);
ch.bulkConnection = connectBulk(ch.connection.getConfig());
return ch;
} catch (ConnectionException e) {
throw new IOException(e);
}
}
use of org.talend.components.salesforce.runtime.common.ConnectionHolder in project components by Talend.
the class SalesforceSourceOrSinkTest method testGuessSchema.
/**
* Checks {@link SalesforceSourceOrSink#guessSchema(String)} returns the
* {@link org.apache.avro.Schema} with date and string type
*/
@Test
public void testGuessSchema() throws Exception {
String field0Name = "Id";
String field1Name = "LastModifiedDate";
String field2Name = "LastActivityDate";
String drivingEntity = "Account";
String soql = new StringBuilder().append("SELECT").append(" ").append(field0Name).append(",").append(SPACE).append(field1Name).append(",").append(SPACE).append(field2Name).append(SPACE).append("FROM").append(SPACE).append(drivingEntity).toString();
final PartnerConnection partnerConnectionMock = Mockito.mock(PartnerConnection.class);
class SalesforceSourceOrSinkChild extends SalesforceSourceOrSink {
@Override
protected ConnectionHolder connect(RuntimeContainer container) {
ConnectionHolder connectionHolder = new ConnectionHolder();
connectionHolder.connection = partnerConnectionMock;
return connectionHolder;
}
}
Field field0 = new Field();
field0.setName(field0Name);
field0.setType(FieldType.string);
Field field1 = new Field();
field1.setName(field1Name);
field1.setType(FieldType.date);
Field field2 = new Field();
field2.setName(field2Name);
field2.setType(FieldType.date);
Field[] fields = new Field[3];
fields[0] = field0;
fields[1] = field1;
fields[2] = field2;
DescribeSObjectResult describeSObjectResult = new DescribeSObjectResult();
describeSObjectResult.setFields(fields);
Mockito.when(partnerConnectionMock.describeSObject(drivingEntity)).thenReturn(describeSObjectResult);
SalesforceSourceOrSinkChild salesforceSourceOrSinkChild = new SalesforceSourceOrSinkChild();
salesforceSourceOrSinkChild.initialize(runtimeContainerMock, properties);
Schema resultSchema = salesforceSourceOrSinkChild.guessSchema(soql);
LOGGER.debug("result schema: " + resultSchema.toString());
Assert.assertEquals("GuessedSchema", resultSchema.getName());
Assert.assertEquals(field0Name, resultSchema.getFields().get(0).name());
Assert.assertEquals(field1Name, resultSchema.getFields().get(1).name());
Assert.assertEquals("java.util.Date", AvroUtils.unwrapIfNullable(resultSchema.getFields().get(1).schema()).getProp("java-class"));
Assert.assertEquals("yyyy-MM-dd", resultSchema.getFields().get(1).getProp(SchemaConstants.TALEND_COLUMN_PATTERN));
Assert.assertEquals(field2Name, resultSchema.getFields().get(2).name());
Assert.assertEquals("java.util.Date", AvroUtils.unwrapIfNullable(resultSchema.getFields().get(2).schema()).getProp("java-class"));
Assert.assertEquals("yyyy-MM-dd", resultSchema.getFields().get(2).getProp(SchemaConstants.TALEND_COLUMN_PATTERN));
}
Aggregations