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;
}
};
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations