Search in sources :

Example 1 with DataNotAvailableException

use of org.teiid.translator.DataNotAvailableException in project teiid by teiid.

the class AutoGenDataService method registerRequest.

@Override
public ConnectorWork registerRequest(AtomicRequestMessage message) throws TeiidComponentException {
    List projectedSymbols = (message.getCommand()).getProjectedSymbols();
    List[] results = createResults(projectedSymbols, rows, useIntCounter);
    if (RelationalNodeUtil.isUpdate(message.getCommand())) {
        results = new List[] { Arrays.asList(1) };
    }
    final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results);
    msg.setFinalRow(rows);
    return new ConnectorWork() {

        boolean returnedInitial;

        @Override
        public boolean isDataAvailable() {
            return dataAvailable;
        }

        @Override
        public AtomicResultsMessage more() throws TranslatorException {
            if (dataNotAvailable != null) {
                int delay = dataNotAvailable;
                dataNotAvailable = null;
                DataNotAvailableException dnae = new DataNotAvailableException(delay);
                dnae.setStrict(strict);
                throw dnae;
            }
            if (addWarning) {
                msg.setWarnings(Arrays.asList(new Exception()));
            }
            if (!returnedInitial) {
                returnedInitial = true;
                return msg;
            }
            // $NON-NLS-1$
            throw new RuntimeException("Should not be called");
        }

        @Override
        public void execute() throws TranslatorException {
            executeCount.incrementAndGet();
            if (sleep > 0) {
                try {
                    Thread.sleep(sleep);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            if (latch != null) {
                try {
                    latch.countDown();
                    latch.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            if (throwExceptionOnExecute) {
                // $NON-NLS-1$
                throw new TranslatorException("Connector Exception");
            }
        }

        @Override
        public void close() {
            closeCount.incrementAndGet();
        }

        @Override
        public void cancel(boolean abnormal) {
        }

        @Override
        public CacheDirective getCacheDirective() {
            return cacheDirective;
        }

        @Override
        public boolean isForkable() {
            return true;
        }

        @Override
        public boolean isThreadBound() {
            return threadBound;
        }

        @Override
        public AtomicRequestID getId() {
            return null;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TranslatorException(org.teiid.translator.TranslatorException) ConnectorWork(org.teiid.dqp.internal.datamgr.ConnectorWork) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) TeiidComponentException(org.teiid.core.TeiidComponentException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) IOException(java.io.IOException)

Example 2 with DataNotAvailableException

use of org.teiid.translator.DataNotAvailableException in project teiid by teiid.

the class ConnectorHost method readResultsFromExecution.

private List<List> readResultsFromExecution(Execution execution) throws TranslatorException {
    List<List> results = new ArrayList<List>();
    while (true) {
        try {
            if (execution instanceof ResultSetExecution) {
                ResultSetExecution rs = (ResultSetExecution) execution;
                List result = null;
                while ((result = rs.next()) != null) {
                    results.add(result);
                }
                break;
            }
            UpdateExecution rs = (UpdateExecution) execution;
            int[] result = rs.getUpdateCounts();
            for (int i = 0; i < result.length; i++) {
                results.add(Arrays.asList(result[i]));
            }
            break;
        } catch (DataNotAvailableException e) {
            if (e.getRetryDelay() > 0) {
                try {
                    Thread.sleep(e.getRetryDelay());
                } catch (InterruptedException e1) {
                    throw new TranslatorException(e1);
                }
            }
        }
    }
    return results;
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) ArrayList(java.util.ArrayList) UpdateExecution(org.teiid.translator.UpdateExecution) ArrayList(java.util.ArrayList) List(java.util.List) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException)

Example 3 with DataNotAvailableException

use of org.teiid.translator.DataNotAvailableException 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 4 with DataNotAvailableException

use of org.teiid.translator.DataNotAvailableException in project teiid by teiid.

the class FileExecutionFactory method createProcedureExecution.

// @Override
public ProcedureExecution createProcedureExecution(final Call command, final ExecutionContext executionContext, final RuntimeMetadata metadata, final Connection conn) throws TranslatorException {
    if (conn instanceof VirtualFileConnection) {
        return new VirtualFileProcedureExecution(command, (VirtualFileConnection) conn);
    }
    final FileConnection fc = (FileConnection) conn;
    if (command.getProcedureName().equalsIgnoreCase(SAVEFILE)) {
        return new ProcedureExecution() {

            @Override
            public void execute() throws TranslatorException {
                String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
                Object file = command.getArguments().get(1).getArgumentValue().getValue();
                if (file == null || filePath == null) {
                    // $NON-NLS-1$
                    throw new TranslatorException(UTIL.getString("non_null"));
                }
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Saving", filePath);
                InputStream is = null;
                try {
                    if (file instanceof SQLXML) {
                        is = ((SQLXML) file).getBinaryStream();
                    } else if (file instanceof Clob) {
                        is = new ReaderInputStream(((Clob) file).getCharacterStream(), encoding);
                    } else if (file instanceof Blob) {
                        is = ((Blob) file).getBinaryStream();
                    } else {
                        // $NON-NLS-1$
                        throw new TranslatorException(UTIL.getString("unknown_type"));
                    }
                    ObjectConverterUtil.write(is, fc.getFile(filePath));
                } catch (IOException e) {
                    // $NON-NLS-1$
                    throw new TranslatorException(e, UTIL.getString("error_writing"));
                } catch (SQLException e) {
                    // $NON-NLS-1$
                    throw new TranslatorException(e, UTIL.getString("error_writing"));
                } catch (ResourceException e) {
                    // $NON-NLS-1$
                    throw new TranslatorException(e, UTIL.getString("error_writing"));
                }
            }

            @Override
            public void close() {
            }

            @Override
            public void cancel() throws TranslatorException {
            }

            @Override
            public List<?> next() throws TranslatorException, DataNotAvailableException {
                return null;
            }

            @Override
            public List<?> getOutputParameterValues() throws TranslatorException {
                return Collections.emptyList();
            }
        };
    } else if (command.getProcedureName().equalsIgnoreCase(DELETEFILE)) {
        return new ProcedureExecution() {

            @Override
            public void execute() throws TranslatorException {
                String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
                if (filePath == null) {
                    // $NON-NLS-1$
                    throw new TranslatorException(UTIL.getString("non_null"));
                }
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Deleting", filePath);
                try {
                    File f = fc.getFile(filePath);
                    if (!f.exists()) {
                        if (exceptionIfFileNotFound) {
                            // $NON-NLS-1$
                            throw new TranslatorException(DataPlugin.Util.gs("file_not_found", filePath));
                        }
                    } else if (!f.delete()) {
                        // $NON-NLS-1$
                        throw new TranslatorException(UTIL.getString("error_deleting"));
                    }
                } catch (ResourceException e) {
                    // $NON-NLS-1$
                    throw new TranslatorException(e, UTIL.getString("error_deleting"));
                }
            }

            @Override
            public void close() {
            }

            @Override
            public void cancel() throws TranslatorException {
            }

            @Override
            public List<?> next() throws TranslatorException, DataNotAvailableException {
                return null;
            }

            @Override
            public List<?> getOutputParameterValues() throws TranslatorException {
                return Collections.emptyList();
            }
        };
    }
    return new FileProcedureExecution(command, fc);
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) ReaderInputStream(org.teiid.core.util.ReaderInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) SQLXML(java.sql.SQLXML) ReaderInputStream(org.teiid.core.util.ReaderInputStream) ProcedureExecution(org.teiid.translator.ProcedureExecution) TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) List(java.util.List) ArrayList(java.util.ArrayList) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) Clob(java.sql.Clob) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) VirtualFileConnection(org.teiid.file.VirtualFileConnection) VirtualFileConnection(org.teiid.file.VirtualFileConnection) FileConnection(org.teiid.translator.FileConnection)

Example 5 with DataNotAvailableException

use of org.teiid.translator.DataNotAvailableException in project teiid by teiid.

the class LoopbackExecution method next.

@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
    // Wait on first batch if necessary
    if (this.config.getWaitTime() > 0 && !waited) {
        // Wait a random amount of time up to waitTime milliseconds
        int randomTimeToWait = randomNumber.nextInt(this.config.getWaitTime());
        // then just say we don't have results instead
        if (this.config.getPollIntervalInMilli() >= 0 && randomTimeToWait > this.config.getPollIntervalInMilli()) {
            waited = true;
            DataNotAvailableException dnae = new DataNotAvailableException(randomTimeToWait);
            dnae.setStrict(true);
            throw dnae;
        }
        try {
            Thread.sleep(randomTimeToWait);
        } catch (InterruptedException e) {
        }
        waited = true;
    }
    List<Object> resultRow = row;
    if (rowsReturned < this.rowsNeeded && resultRow.size() > 0) {
        rowsReturned++;
        if (config.getIncrementRows()) {
            rowNumber = rowNumber.add(BigInteger.ONE);
            generateRow();
        }
        return resultRow;
    }
    return null;
}
Also used : DataNotAvailableException(org.teiid.translator.DataNotAvailableException)

Aggregations

DataNotAvailableException (org.teiid.translator.DataNotAvailableException)16 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)10 ExecutionContext (org.teiid.translator.ExecutionContext)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Test (org.junit.Test)9 TranslatorException (org.teiid.translator.TranslatorException)9 ResultSetExecution (org.teiid.translator.ResultSetExecution)5 SalesForceExecutionFactory (org.teiid.translator.salesforce.SalesForceExecutionFactory)5 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)5 IOException (java.io.IOException)4 Table (org.teiid.metadata.Table)4 JobInfo (com.sforce.async.JobInfo)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 ColumnReference (org.teiid.language.ColumnReference)3 Command (org.teiid.language.Command)3 Expression (org.teiid.language.Expression)3 ExpressionValueSource (org.teiid.language.ExpressionValueSource)3 Insert (org.teiid.language.Insert)3