use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class DirectQueryExecution method loadBatch.
private List<List<Object>> loadBatch(QueryResult queryResult) {
List<List<Object>> batch = new ArrayList<List<Object>>();
for (SObject sObject : queryResult.getRecords()) {
Iterator<XmlObject> fields = sObject.getChildren();
List<Object> row = new ArrayList<Object>();
while (fields.hasNext()) {
XmlObject elem = fields.next();
if (elem.getName().getLocalPart().equals("type")) {
// $NON-NLS-1$
continue;
}
Object value = elem.getValue();
row.add(value);
}
batch.add(row);
}
return batch;
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class QueryExecutionImpl method extractValuesFromElement.
// TODO: this looks inefficient as getChild is linear
private List<Object[]> extractValuesFromElement(XmlObject sObject, List<Object[]> result, String sObjectName) throws TranslatorException {
Object[] row = new Object[visitor.getSelectSymbolCount()];
for (int j = 0; j < visitor.getSelectSymbolCount(); j++) {
// must be a column reference as we won't allow an agg over a join
Column element = ((ColumnReference) visitor.getSelectSymbolMetadata(j)).getMetadataObject();
AbstractMetadataRecord table = element.getParent();
if (table.getSourceName().equals(sObjectName)) {
XmlObject child = sObject.getChild(element.getSourceName());
Object cell = getCellDatum(element.getSourceName(), element.getJavaType(), child);
setElementValueInColumn(j, cell, row);
}
}
result.add(row);
return result;
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class QueryExecutionImpl method getObjectData.
private List<Object[]> getObjectData(SObject sObject) throws TranslatorException {
Iterator<XmlObject> topFields = sObject.getChildren();
ArrayList<XmlObject> children = new ArrayList<XmlObject>();
while (topFields.hasNext()) {
children.add(topFields.next());
}
logAndMapFields(sObject.getType(), children);
List<Object[]> result = new ArrayList<Object[]>();
if (visitor instanceof JoinQueryVisitor) {
for (int i = 0; i < children.size(); i++) {
XmlObject element = children.get(i);
extactJoinResults(element, result);
}
}
return extractDataFromFields(sObject, children, result);
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class TestQueryExecutionImpl method testJoin.
@Test
public void testJoin() throws Exception {
// $NON-NLS-1$
Select command = (Select) translationUtility.parseCommand("select Account.Name, Contact.Id from Account inner join Contact on Account.Id = Contact.AccountId");
SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);
QueryResult qr = new QueryResult();
SObject so = new SObject();
so.setType("Account");
so.addField("Name", "account name");
SObject so1 = new SObject();
so1.setType("Contact");
so1.addField("Id", "contact id");
so.addField("Contacts", so1);
qr.setRecords(new SObject[] { so });
qr.setDone(true);
Mockito.stub(sfc.query("SELECT Account.Name, Contact.Id FROM Contact WHERE Contact.AccountId != NULL", 0, false)).toReturn(qr);
QueryExecutionImpl qei = new QueryExecutionImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class), new SalesForceExecutionFactory());
qei.execute();
assertEquals(Arrays.asList("account name", "contact id"), qei.next());
assertNull(qei.next());
}
use of com.sforce.soap.partner.sobject.SObject in project teiid by teiid.
the class TestQueryExecutionImpl method testBatching.
@Test
public void testBatching() throws Exception {
// $NON-NLS-1$
Select command = (Select) translationUtility.parseCommand("select Name from Account");
SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);
QueryResult qr = new QueryResult();
SObject so = new SObject();
so.setType("Account");
so.addField("Name", null);
qr.setRecords(new SObject[] { so });
qr.setDone(false);
QueryResult finalQr = new QueryResult();
finalQr.setRecords(new SObject[] { so });
finalQr.setDone(true);
Mockito.stub(sfc.query("SELECT Account.Name FROM Account", 0, false)).toReturn(qr);
Mockito.stub(sfc.queryMore(null, 0)).toReturn(finalQr);
QueryExecutionImpl qei = new QueryExecutionImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class), new SalesForceExecutionFactory());
qei.execute();
assertNotNull(qei.next());
assertNotNull(qei.next());
assertNull(qei.next());
}
Aggregations