use of javax.resource.ResourceException in project teiid by teiid.
the class SalesforceConnectionImpl method getBulkResults.
@Override
public BatchResult[] getBulkResults(JobInfo job, List<String> ids) throws ResourceException {
try {
JobInfo info = this.bulkConnection.getJobStatus(job.getId());
if (info.getNumberBatchesTotal() != info.getNumberBatchesFailed() + info.getNumberBatchesCompleted()) {
throw new DataNotAvailableException(pollingInterval);
}
BatchResult[] results = new BatchResult[ids.size()];
for (int i = 0; i < ids.size(); i++) {
results[i] = this.bulkConnection.getBatchResult(job.getId(), ids.get(i));
}
return results;
} catch (AsyncApiException e) {
throw new ResourceException(e);
}
}
use of javax.resource.ResourceException in project teiid by teiid.
the class SalesforceConnectionImpl method getBatchQueryResults.
@Override
public BulkBatchResult getBatchQueryResults(String jobId, BatchResultInfo info) throws ResourceException {
if (info.getResultList() == null && info.getPkBatches() == null) {
try {
BatchInfo batch = this.bulkConnection.getBatchInfo(jobId, info.getBatchId());
switch(batch.getState()) {
case NotProcessed:
// we need more checks to ensure that chunking is being used. since
// we don't know, then we'll explicitly check
JobInfo jobStatus = this.bulkConnection.getJobStatus(jobId);
if (jobStatus.getState() == JobStateEnum.Aborted) {
throw new ResourceException(JobStateEnum.Aborted.name());
}
BatchInfoList batchInfoList = this.bulkConnection.getBatchInfoList(jobId);
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Pk chunk batches", batchInfoList);
BatchInfo[] batchInfo = batchInfoList.getBatchInfo();
LinkedHashMap<String, BatchInfo> pkBactches = new LinkedHashMap<String, BatchInfo>();
boolean anyComplete = false;
for (int i = 0; i < batchInfo.length; i++) {
BatchInfo batchInfoItem = batchInfo[i];
if (batchInfoItem.getId().equals(info.getBatchId())) {
// disregard the initial batch
continue;
}
switch(batchInfoItem.getState()) {
case Failed:
case NotProcessed:
throw new ResourceException(batchInfoItem.getStateMessage());
case Completed:
anyComplete = true;
default:
pkBactches.put(batchInfoItem.getId(), batchInfoItem);
}
}
info.setPkBatches(pkBactches);
if (!anyComplete) {
throwDataNotAvailable(info);
}
break;
case Completed:
{
QueryResultList list = this.bulkConnection.getQueryResultList(jobId, info.getBatchId());
info.setResultList(list.getResult());
break;
}
case InProgress:
case Queued:
throwDataNotAvailable(info);
default:
throw new ResourceException(batch.getStateMessage());
}
} catch (AsyncApiException e) {
throw new ResourceException(e);
}
}
try {
BulkBatchResult result = null;
if (info.getResultList() != null) {
result = nextBulkBatch(jobId, info);
}
if (result == null && info.getPkBatches() != null) {
getNextPkChunkResultList(jobId, info);
result = nextBulkBatch(jobId, info);
}
info.resetWaitCount();
return result;
} catch (AsyncApiException e) {
throw new ResourceException(e);
}
}
use of javax.resource.ResourceException in project teiid by teiid.
the class DirectQueryExecution method doUpsert.
private void doUpsert(String upsert) throws TranslatorException {
DataPayload payload = buildDataPlayload(upsert);
try {
// $NON-NLS-1$
this.updateCount = this.connection.upsert(payload);
this.updateQuery = true;
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
use of javax.resource.ResourceException in project teiid by teiid.
the class DirectQueryExecution method getRow.
private List<?> getRow(QueryResult result) throws TranslatorException {
// for insert/update/delete clauses
if (this.updateQuery) {
if (this.updateCount != -1) {
List<?> updateResult = Arrays.asList(this.updateCount);
this.updateCount = -1;
return updateResult;
}
return null;
}
// select clauses
List<Object> row = null;
if (this.currentBatch == null) {
this.currentBatch = loadBatch(this.results);
}
if (!this.currentBatch.isEmpty()) {
row = this.currentBatch.remove(0);
} else {
if (!result.isDone()) {
// fetch more results
try {
this.results = this.connection.queryMore(results.getQueryLocator(), context.getBatchSize());
} catch (ResourceException e) {
throw new TranslatorException(e);
}
this.currentBatch = loadBatch(this.results);
// read next row
row = this.currentBatch.remove(0);
}
}
return row;
}
use of javax.resource.ResourceException in project teiid by teiid.
the class DirectQueryExecution method doDelete.
private void doDelete() throws TranslatorException {
List<String> ids = new ArrayList<String>();
for (Argument arg : arguments) {
Object val = arg.getArgumentValue().getValue();
if (val != null) {
ids.add(Util.stripQutes(val.toString()));
}
}
try {
this.updateCount = this.connection.delete(ids.toArray(new String[ids.size()]));
this.updateQuery = true;
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
Aggregations