Search in sources :

Example 66 with ResourceException

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);
    }
}
Also used : ResourceException(javax.resource.ResourceException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException)

Example 67 with ResourceException

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);
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ResourceException(javax.resource.ResourceException)

Example 68 with ResourceException

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);
    }
}
Also used : ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 69 with ResourceException

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;
}
Also used : XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 70 with ResourceException

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);
    }
}
Also used : Argument(org.teiid.language.Argument) ArrayList(java.util.ArrayList) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Aggregations

ResourceException (javax.resource.ResourceException)163 TranslatorException (org.teiid.translator.TranslatorException)26 SQLException (java.sql.SQLException)18 IOException (java.io.IOException)17 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)14 ManagedConnection (javax.resource.spi.ManagedConnection)13 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)13 NamingException (javax.naming.NamingException)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 SObject (com.sforce.soap.partner.sobject.SObject)9 ConnectionException (com.sforce.ws.ConnectionException)9 UnexpectedErrorFault (com.sforce.soap.partner.fault.UnexpectedErrorFault)8 ArrayList (java.util.ArrayList)8 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)7 InvalidSObjectFault (com.sforce.soap.partner.fault.InvalidSObjectFault)6 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)6 Set (java.util.Set)6 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)6 XAResource (javax.transaction.xa.XAResource)6 InvalidFieldFault (com.sforce.soap.partner.fault.InvalidFieldFault)5