use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class SalesforceConnectionImpl method upsert.
public int upsert(DataPayload data) throws ResourceException {
SObject toCreate = new SObject();
toCreate.setType(data.getType());
for (DataPayload.Field field : data.getMessageElements()) {
toCreate.addField(field.name, field.value);
}
SObject[] objects = new SObject[] { toCreate };
UpsertResult[] results;
try {
results = partnerConnection.upsert(ID_FIELD_NAME, objects);
} catch (InvalidFieldFault e) {
throw new ResourceException(e);
} catch (InvalidSObjectFault e) {
throw new ResourceException(e);
} catch (InvalidIdFault e) {
throw new ResourceException(e);
} catch (UnexpectedErrorFault e) {
throw new ResourceException(e);
} catch (ConnectionException e) {
throw new ResourceException(e);
}
for (UpsertResult result : results) {
if (!result.isSuccess()) {
throw new ResourceException(result.getErrors()[0].getMessage());
}
}
return results.length;
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class QueryExecutionImpl method loadBatch.
private void loadBatch() throws TranslatorException {
try {
if (null != resultBatch) {
// if we have an old batch, then we have to get new results
results = connection.queryMore(results.getQueryLocator(), context.getBatchSize());
}
resultBatch = new ArrayList<List<Object>>();
topResultIndex = 0;
for (SObject sObject : results.getRecords()) {
if (sObject == null) {
continue;
}
List<Object[]> result = getObjectData(sObject);
for (Iterator<Object[]> i = result.iterator(); i.hasNext(); ) {
resultBatch.add(Arrays.asList(i.next()));
}
}
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class TestUpdates method testIds.
@Test
public void testIds() throws Exception {
Delete delete = (Delete) translationUtility.parseCommand("delete from contacts");
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
SalesForceExecutionFactory config = new SalesForceExecutionFactory();
DeleteExecutionImpl updateExecution = new DeleteExecutionImpl(config, delete, connection, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class));
ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
QueryResult qr = new QueryResult();
SObject so = new SObject();
so.setType("Contact");
so.addField("Id", "x");
qr.setRecords(new SObject[] { so });
qr.setSize(1);
qr.setDone(true);
Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(qr);
Mockito.stub(connection.delete(new String[] { "x" })).toReturn(1);
while (true) {
try {
updateExecution.execute();
org.junit.Assert.assertArrayEquals(new int[] { 1 }, updateExecution.getUpdateCounts());
break;
} catch (DataNotAvailableException e) {
continue;
}
}
Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
String query = queryArgument.getValue();
assertEquals("SELECT Id FROM Contact ", query);
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class QueryExecutionImpl method extractDataFromFields.
private List<Object[]> extractDataFromFields(SObject sObject, List<XmlObject> fields, List<Object[]> result) throws TranslatorException {
Map<String, Integer> fieldToIndexMap = sObjectToResponseField.get(sObject.getType());
int aggCount = 0;
for (int j = 0; j < visitor.getSelectSymbolCount(); j++) {
Expression ex = visitor.getSelectSymbolMetadata(j);
if (ex instanceof ColumnReference) {
Column element = ((ColumnReference) ex).getMetadataObject();
Table table = (Table) element.getParent();
if (table.getSourceName().equals(sObject.getType()) || AGGREGATE_RESULT.equalsIgnoreCase(sObject.getType())) {
Integer index = fieldToIndexMap.get(element.getSourceName());
if (null == index) {
// $NON-NLS-1$
throw new TranslatorException(SalesForcePlugin.Util.getString("SalesforceQueryExecutionImpl.missing.field") + element.getSourceName());
}
Object cell = getCellDatum(element.getSourceName(), element.getJavaType(), fields.get(index));
setValueInColumn(j, cell, result);
}
} else if (ex instanceof AggregateFunction) {
String name = SelectVisitor.AGG_PREFIX + (aggCount++);
Integer index = fieldToIndexMap.get(name);
if (null == index) {
// $NON-NLS-1$
throw new TranslatorException(SalesForcePlugin.Util.getString("SalesforceQueryExecutionImpl.missing.field") + ex);
}
Object cell = getCellDatum(name, ex.getType(), fields.get(index));
setValueInColumn(j, cell, result);
}
}
return result;
}
use of com.sforce.soap.partner.sobject.SObject in project components by Talend.
the class SObjectAdapterFactoryTest method testConvertToAvroBasic.
@Test
public void testConvertToAvroBasic() throws IOException {
converter.setSchema(SCHEMA);
assertNotNull(converter.getSchema());
assertEquals(SObject.class, converter.getDatumClass());
SObject sObject = new SObject("Account");
sObject.addField("Id", "12345");
sObject.addField("Name", "Qwerty");
sObject.addField("FieldX", 42);
sObject.addField("FieldY", true);
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(42), indexedRecord.get(2));
assertEquals(Boolean.TRUE, indexedRecord.get(3));
}
Aggregations