use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceInsert method writeToSalesForce.
@VisibleForTesting
void writeToSalesForce(Object[] rowData) throws KettleException {
try {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceInsert.WriteToSalesforce", data.iBufferPos, meta.getBatchSizeInt()));
}
// if there is room in the buffer
if (data.iBufferPos < meta.getBatchSizeInt()) {
ArrayList<XmlObject> insertfields = new ArrayList<>();
// Reserve for empty fields
ArrayList<String> fieldsToNull = new ArrayList<String>();
// Add fields to insert
for (int i = 0; i < data.nrfields; i++) {
ValueMetaInterface valueMeta = data.inputRowMeta.getValueMeta(data.fieldnrs[i]);
Object value = rowData[data.fieldnrs[i]];
if (valueMeta.isNull(value)) {
// The value is null
// We need to keep track of this field
fieldsToNull.add(SalesforceUtils.getFieldToNullName(log, meta.getUpdateLookup()[i], meta.getUseExternalId()[i]));
} else {
Object normalObject = normalizeValue(valueMeta, value);
insertfields.add(SalesforceConnection.createMessageElement(meta.getUpdateLookup()[i], normalObject, meta.getUseExternalId()[i]));
}
}
// build the SObject
SObject sobjPass = new SObject();
sobjPass.setType(data.connection.getModule());
if (insertfields.size() > 0) {
for (XmlObject element : insertfields) {
sobjPass.setSObjectField(element.getName().getLocalPart(), element.getValue());
}
}
if (fieldsToNull.size() > 0) {
// Set Null to fields
sobjPass.setFieldsToNull(fieldsToNull.toArray(new String[fieldsToNull.size()]));
}
// Load the buffer array
data.sfBuffer[data.iBufferPos] = sobjPass;
data.outputBuffer[data.iBufferPos] = rowData;
data.iBufferPos++;
}
if (data.iBufferPos >= meta.getBatchSizeInt()) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "SalesforceInsert.CallingFlushBuffer"));
}
flushBuffers();
}
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInsert.Error", e.getMessage()));
}
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceUpdate method writeToSalesForce.
@VisibleForTesting
void writeToSalesForce(Object[] rowData) throws KettleException {
try {
if (log.isDetailed()) {
logDetailed("Called writeToSalesForce with " + data.iBufferPos + " out of " + meta.getBatchSizeInt());
}
// if there is room in the buffer
if (data.iBufferPos < meta.getBatchSizeInt()) {
// Reserve for empty fields
ArrayList<String> fieldsToNull = new ArrayList<String>();
ArrayList<XmlObject> updatefields = new ArrayList<>();
// Add fields to update
for (int i = 0; i < data.nrfields; i++) {
boolean valueIsNull = data.inputRowMeta.isNull(rowData, data.fieldnrs[i]);
if (valueIsNull) {
// The value is null
// We need to keep track of this field
fieldsToNull.add(SalesforceUtils.getFieldToNullName(log, meta.getUpdateLookup()[i], meta.getUseExternalId()[i]));
} else {
ValueMetaInterface valueMeta = data.inputRowMeta.getValueMeta(data.fieldnrs[i]);
Object value = rowData[data.fieldnrs[i]];
Object normalObject = normalizeValue(valueMeta, value);
updatefields.add(SalesforceConnection.createMessageElement(meta.getUpdateLookup()[i], normalObject, meta.getUseExternalId()[i]));
}
}
// build the SObject
SObject sobjPass = new SObject();
sobjPass.setType(data.connection.getModule());
if (updatefields.size() > 0) {
for (XmlObject element : updatefields) {
sobjPass.setSObjectField(element.getName().getLocalPart(), element.getValue());
}
}
if (fieldsToNull.size() > 0) {
// Set Null to fields
sobjPass.setFieldsToNull(fieldsToNull.toArray(new String[fieldsToNull.size()]));
}
// Load the buffer array
data.sfBuffer[data.iBufferPos] = sobjPass;
data.outputBuffer[data.iBufferPos] = rowData;
data.iBufferPos++;
}
if (data.iBufferPos >= meta.getBatchSizeInt()) {
if (log.isDetailed()) {
logDetailed("Calling flush buffer from writeToSalesForce");
}
flushBuffers();
}
} catch (Exception e) {
throw new KettleException("\nFailed in writeToSalesForce: " + e.getMessage());
}
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceUpsert method setFieldInSObject.
void setFieldInSObject(SObject sobjPass, XmlObject element) {
Iterator<XmlObject> children = element.getChildren();
String name = element.getName().getLocalPart();
if (!children.hasNext()) {
sobjPass.setSObjectField(name, element.getValue());
} else {
SObject child = new SObject();
child.setName(new QName(name));
while (children.hasNext()) {
setFieldInSObject(child, children.next());
}
sobjPass.setSObjectField(name, child);
}
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceUpsertTest method testSetFieldInSObjectForeignKey.
@Test
public void testSetFieldInSObjectForeignKey() throws Exception {
SalesforceUpsert salesforceUpsert = new SalesforceUpsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
SObject sobjPass = new SObject();
XmlObject parentObject = new XmlObject();
String parentParam = "parentParam";
String parentValue = "parentValue";
parentObject.setName(new QName(parentParam));
parentObject.setValue(parentValue);
String child = "child";
String childParam = "childParam";
String childValue = "childValue";
XmlObject childObject = new XmlObject();
childObject.setName(new QName(child));
childObject.setField(childParam, childValue);
salesforceUpsert.setFieldInSObject(sobjPass, parentObject);
salesforceUpsert.setFieldInSObject(sobjPass, childObject);
Assert.assertEquals(parentValue, sobjPass.getField(parentParam));
Assert.assertEquals(childValue, ((SObject) sobjPass.getField(child)).getField(childParam));
}
use of com.sforce.ws.bind.XmlObject 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;
}
Aggregations