use of com.sforce.async.SObject in project teiid by teiid.
the class InsertExecutionImpl method execute.
@Override
public void execute() throws TranslatorException {
try {
Insert insert = (Insert) command;
if (insert.getParameterValues() == null) {
DataPayload data = new DataPayload();
data.setType(this.objectName);
buildSingleRowInsertPayload(insert, data);
if (insert.isUpsert()) {
result = getConnection().upsert(data);
} else {
result = getConnection().create(data);
}
} else {
if (this.activeJob == null) {
this.activeJob = getConnection().createBulkJob(this.objectName, insert.isUpsert() ? OperationEnum.upsert : OperationEnum.insert, false);
counts = new ArrayList<Integer>();
}
if (this.activeJob.getState() == JobStateEnum.Open) {
while (this.rowIter.hasNext()) {
List<SObject> rows = buildBulkRowPayload(insert, this.rowIter, this.executionFactory.getMaxBulkInsertBatchSize());
batches.add(getConnection().addBatch(rows, activeJob));
}
this.activeJob = getConnection().closeJob(this.activeJob.getId());
}
BatchResult[] batchResult = getConnection().getBulkResults(this.activeJob, batches);
for (BatchResult br : batchResult) {
for (Result r : br.getResult()) {
if (r.isSuccess() && r.isCreated()) {
counts.add(1);
} else if (r.getErrors().length > 0) {
counts.add(Statement.EXECUTE_FAILED);
this.context.addWarning(new SQLWarning(r.getErrors()[0].getMessage(), r.getErrors()[0].getStatusCode().name()));
} else {
counts.add(Statement.SUCCESS_NO_INFO);
}
}
}
// now process the next set of batch rows
this.activeJob = null;
}
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
Aggregations