use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class TestSalesForceDirectQueryExecution method testSearch.
@Test
public void testSearch() throws Exception {
String input = "exec native('search;SELECT Account.Id, Account.Type, Account.Name FROM Account')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
QueryResult qr = Mockito.mock(QueryResult.class);
Mockito.stub(qr.isDone()).toReturn(true);
SObject[] results = new SObject[1];
SObject s = new SObject();
s.setType("Account");
s.setId("The ID");
results[0] = s;
s.addField("Type", "The Type");
s.addField("Name", "The Name");
Mockito.stub(qr.getRecords()).toReturn(results);
Mockito.stub(connection.query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false)).toReturn(qr);
DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection, Mockito.times(1)).query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false);
assertArrayEquals(new Object[] { "The ID", "The Type", "The Name" }, (Object[]) execution.next().get(0));
}
use of com.sforce.soap.partner.sobject.SObject in project components by Talend.
the class SObjectAdapterFactoryTest method testConvertToAvroForNestedObjects.
@Test
public void testConvertToAvroForNestedObjects() throws Exception {
Schema schema = //
SchemaBuilder.builder().record("Schema").fields().name("Id").prop(SchemaConstants.TALEND_COLUMN_IS_KEY, "true").type().stringType().noDefault().name("Name").type(AvroUtils._string()).noDefault().name("FieldA").type(AvroUtils._int()).noDefault().name("Member_Name").type(AvroUtils._string()).noDefault().name("Member_FieldA").type(AvroUtils._string()).noDefault().name("Member_Contact_Name").type(AvroUtils._string()).noDefault().name("Member_Contact_FieldA").type(AvroUtils._string()).noDefault().endRecord();
schema.addProp(SalesforceSchemaConstants.COLUMNNAME_DELIMTER, "_");
schema.addProp(SalesforceSchemaConstants.VALUE_DELIMITER, "|");
converter.setSchema(schema);
SObject sObject = new SObject("Campaign");
sObject.addField("Id", "12345");
sObject.addField("Name", "Qwerty");
// Intentionally add another value to check that it is skipped by converter
sObject.addField("FieldA", 300);
sObject.addField("FieldA", 400);
SObject sObject1 = new SObject("CampaignMember");
sObject1.addField("Id", "10001");
sObject1.addField("Name", "Member A");
sObject1.addField("FieldA", 10);
sObject.addField("Member", sObject1);
SObject sObject11 = new SObject("Contact");
sObject11.addField("Id", "20001");
sObject11.addField("Name", "Contact A");
sObject11.addField("FieldA", "foo");
sObject1.addField("Contact", sObject11);
SObject sObject2 = new SObject("CampaignMember");
sObject2.addField("Id", "10002");
sObject2.addField("Name", "Member B");
sObject2.addField("FieldA", 20);
sObject.addField("Member", sObject2);
SObject sObject21 = new SObject("Contact");
sObject21.addField("Id", "20002");
sObject21.addField("Name", "Contact B");
sObject21.addField("FieldA", "bar");
sObject2.addField("Contact", sObject21);
IndexedRecord indexedRecord = converter.convertToAvro(sObject);
assertNotNull(indexedRecord);
assertNotNull(indexedRecord.getSchema());
assertEquals(schema, indexedRecord.getSchema());
assertEquals("12345", indexedRecord.get(0));
assertEquals("Qwerty", indexedRecord.get(1));
assertEquals(Integer.valueOf(300), indexedRecord.get(2));
assertEquals("Member A|Member B", indexedRecord.get(3));
assertEquals("10|20", indexedRecord.get(4));
assertEquals("Contact A|Contact B", indexedRecord.get(5));
assertEquals("foo|bar", indexedRecord.get(6));
}
use of com.sforce.soap.partner.sobject.SObject in project components by Talend.
the class SObjectAdapterFactoryTest method testIndexedRecordUnmodifiable.
@Test(expected = IndexedRecordConverter.UnmodifiableAdapterException.class)
public void testIndexedRecordUnmodifiable() throws IOException {
converter.setSchema(SCHEMA);
SObject sObject = new SObject("Account");
sObject.addField("Id", "12345");
sObject.addField("Name", "Qwerty");
IndexedRecord indexedRecord = converter.convertToAvro(sObject);
indexedRecord.put(1, "Asdfgh");
}
use of com.sforce.soap.partner.sobject.SObject in project components by Talend.
the class SalesforceWriter method doUpdate.
private SaveResult[] doUpdate() throws IOException {
if (updateItems.size() > 0) {
// Clean the feedback records at each batch write.
cleanWrites();
SObject[] upds = new SObject[updateItems.size()];
for (int i = 0; i < updateItems.size(); i++) {
upds[i] = createSObject(updateItems.get(i));
}
String[] changedItemKeys = new String[upds.length];
for (int ix = 0; ix < upds.length; ++ix) {
changedItemKeys[ix] = upds[ix].getId();
}
SaveResult[] saveResults;
try {
saveResults = connection.update(upds);
upds = null;
if (saveResults != null && saveResults.length != 0) {
int batch_idx = -1;
for (int i = 0; i < saveResults.length; i++) {
++batch_idx;
if (saveResults[i].getSuccess()) {
handleSuccess(updateItems.get(i), saveResults[i].getId(), null);
} else {
handleReject(updateItems.get(i), saveResults[i].getErrors(), changedItemKeys, batch_idx);
}
}
}
updateItems.clear();
return saveResults;
} catch (ConnectionException e) {
throw new IOException(e);
}
}
return null;
}
use of com.sforce.soap.partner.sobject.SObject in project components by Talend.
the class SalesforceWriter method createSObject.
private SObject createSObject(IndexedRecord input) {
SObject so = new SObject();
so.setType(sprops.module.moduleName.getStringValue());
nullValueFields.clear();
for (Schema.Field f : input.getSchema().getFields()) {
// For "Id" column, we should ignore it for "INSERT" action
if (!("Id".equals(f.name()) && SalesforceOutputProperties.OutputAction.INSERT.equals(sprops.outputAction.getValue()))) {
Object value = input.get(f.pos());
Schema.Field se = moduleSchema.getField(f.name());
if (se != null) {
if (value != null && !value.toString().isEmpty()) {
addSObjectField(so, se.schema(), se.name(), value);
} else {
if (UPDATE.equals(sprops.outputAction.getValue())) {
nullValueFields.add(f.name());
}
}
}
}
}
if (!sprops.ignoreNull.getValue()) {
so.setFieldsToNull(nullValueFields.toArray(new String[0]));
}
return so;
}
Aggregations