use of com.salesforce.soap.partner.DeleteResponse in project tdi-studio-se by Talend.
the class SforceManagementImpl method logout.
/**
* logout
*/
@Override
public void logout() throws Exception {
Object returnObject = null;
// if there are still records to be commited:
try {
if (insertItems.size() > 0) {
SObject[] accs = insertItems.toArray(new SObject[insertItems.size()]);
String[] changedItemKeys = new String[accs.length];
Create create = new Create();
create.setSObjects(accs);
SaveResult[] sr = sforceConn.create(create).getResult();
insertItems.clear();
accs = null;
if (sr != null && sr.length != 0) {
int batch_idx = -1;
for (SaveResult result : sr) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? "" + (batch_idx + 1) : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
returnObject = sr;
}
if (deleteItems.size() > 0) {
ID[] delIDs = deleteItems.toArray(new ID[deleteItems.size()]);
String[] changedItemKeys = new String[delIDs.length];
for (int ix = 0; ix < delIDs.length; ++ix) {
changedItemKeys[ix] = delIDs[ix].getID();
}
Delete dels = new Delete();
dels.setIds(delIDs);
DeleteResponse dresp = sforceConn.delete(dels);
DeleteResult[] dr = dresp.getResult();
deleteItems.clear();
delIDs = null;
if (dr != null && dr.length != 0) {
int batch_idx = -1;
for (DeleteResult result : dr) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
returnObject = dr;
}
if (updateItems.size() > 0) {
SObject[] upds = updateItems.toArray(new SObject[updateItems.size()]);
String[] changedItemKeys = new String[upds.length];
for (int ix = 0; ix < upds.length; ++ix) {
changedItemKeys[ix] = upds[ix].getId().getID();
}
Update update = new Update();
update.setSObjects(upds);
SaveResult[] saveResults = sforceConn.update(update).getResult();
updateItems.clear();
upds = null;
if (saveResults != null && saveResults.length != 0) {
int batch_idx = -1;
for (SaveResult result : saveResults) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
returnObject = saveResults;
}
if (upsertItems.size() > 0) {
SObject[] upds = upsertItems.toArray(new SObject[upsertItems.size()]);
String[] changedItemKeys = new String[upds.length];
for (int ix = 0; ix < upds.length; ++ix) {
changedItemKeys[ix] = "No value for " + upsertKeyColumn + " ";
OMElement[] oms = upds[ix].getExtraElement();
for (OMElement om : oms) {
if (upsertKeyColumn != null && om != null && upsertKeyColumn.equals(om.getLocalName())) {
changedItemKeys[ix] = om.getText();
break;
}
}
}
Upsert upsert = new Upsert();
upsert.setSObjects(upds);
upsert.setExternalIDFieldName(upsertKeyColumn);
UpsertResult[] upsertResults = sforceConn.upsert(upsert).getResult();
upsertItems.clear();
upds = null;
if (upsertResults != null && upsertResults.length != 0) {
int batch_idx = -1;
for (UpsertResult result : upsertResults) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
returnObject = upsertResults;
}
} catch (Exception e) {
throw new Exception(e.toString());
}
if (logWriter != null) {
logWriter.close();
}
}
use of com.salesforce.soap.partner.DeleteResponse in project tdi-studio-se by Talend.
the class SforceManagementImpl method delete.
/**
* delete, one time one record.
*/
@Override
public DeleteResult[] delete(String id) throws Exception {
if (id == null) {
return null;
}
// String[] ids = new String[] { id };
ID dID = new ID();
dID.setID(id);
deleteItems.add(dID);
if (deleteItems.size() >= commitLevel) {
ID[] delIDs = deleteItems.toArray(new ID[deleteItems.size()]);
String[] changedItemKeys = new String[delIDs.length];
for (int ix = 0; ix < delIDs.length; ++ix) {
changedItemKeys[ix] = delIDs[ix].getID();
}
Delete dels = new Delete();
dels.setIds(delIDs);
DeleteResponse dresp = sforceConn.delete(dels);
DeleteResult[] dr = dresp.getResult();
deleteItems.clear();
delIDs = null;
if (dr != null && dr.length != 0) {
int batch_idx = -1;
for (DeleteResult result : dr) {
++batch_idx;
StringBuilder errors = new StringBuilder("");
if (result.getSuccess()) {
// TODO: send back the ID
} else {
errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
}
if (exceptionForErrors && errors.toString().length() > 0) {
if (logWriter != null) {
logWriter.close();
}
throw new Exception(errors.toString());
}
}
}
return dr;
}
return null;
}
Aggregations