use of org.teiid.client.SourceWarning in project teiid by teiid.
the class TestDataTierManager method testPartialResults.
@Test
public void testPartialResults() throws Exception {
DataTierTupleSource info = helpSetup(1);
connectorManager.throwExceptionOnExecute = true;
for (int i = 0; i < 10; i++) {
try {
assertNull(info.nextTuple());
SourceWarning warning = (SourceWarning) context.getAndClearWarnings().get(0);
assertTrue(warning.isPartialResultsError());
return;
} catch (BlockedException e) {
Thread.sleep(50);
}
}
fail();
}
use of org.teiid.client.SourceWarning in project teiid by teiid.
the class TestExceptionHolder method testSourceWarning.
@Test
public void testSourceWarning() throws Exception {
// $NON-NLS-1$
ClassLoader cl = new URLClassLoader(new URL[] { UnitTestUtil.getTestDataFile("test.jar").toURI().toURL() });
ArrayList<String> args = new ArrayList<String>();
// $NON-NLS-1$
args.add("Unknown Exception");
// $NON-NLS-1$
Exception obj = (Exception) ReflectionHelper.create("test.UnknownException", args, cl);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(new ExceptionHolder(new SourceWarning("x", "y", obj, true)));
oos.flush();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
ExceptionHolder holder = (ExceptionHolder) ois.readObject();
SourceWarning sw = (SourceWarning) holder.getException();
assertEquals(sw.getConnectorBindingName(), "y");
assertEquals(sw.getModelName(), "x");
assertTrue(sw.isPartialResultsError());
try {
ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("old-exceptionholder.ser")));
holder = (ExceptionHolder) ois.readObject();
assertTrue(holder.getException() instanceof TeiidException);
} finally {
ois.close();
}
}
use of org.teiid.client.SourceWarning in project teiid by teiid.
the class DataTierTupleSource method receiveResults.
void receiveResults(AtomicResultsMessage response, boolean partial) {
this.arm = response;
this.scope = response.getScope();
if (this.scope != null) {
this.aqr.getCommandContext().setDeterminismLevel(CachingTupleSource.getDeterminismLevel(this.scope));
}
explicitClose |= !arm.supportsImplicitClose();
rowsProcessed += response.getResults().length;
index = 0;
if (response.getWarnings() != null) {
for (Exception warning : response.getWarnings()) {
SourceWarning sourceFailure = new SourceWarning(this.aqr.getModelName(), aqr.getConnectorName(), warning, partial);
this.aqr.getCommandContext().addWarning(sourceFailure);
}
}
if (response.getFinalRow() >= 0) {
done = true;
}
}
use of org.teiid.client.SourceWarning in project teiid by teiid.
the class ExceptionHolder method writeExternal.
@Override
public void writeExternal(ObjectOutput out) throws IOException {
List<String> classNames = new ArrayList<String>();
Class<?> clazz = exception.getClass();
while (clazz != null) {
if (clazz == Throwable.class || clazz == Exception.class) {
break;
}
classNames.add(clazz.getName());
clazz = clazz.getSuperclass();
}
ExternalizeUtil.writeList(out, classNames);
out.writeObject(exception.getMessage());
out.writeObject(exception.getStackTrace());
if (exception instanceof TeiidException) {
out.writeObject(((TeiidException) exception).getCode());
} else {
out.writeObject(null);
}
// specify that this cause is nested exception; not top level
if (this.exception.getCause() != null && this.exception.getCause() != this.exception) {
out.writeObject(new ExceptionHolder(this.exception.getCause(), true));
} else {
out.writeObject(null);
}
// only for the top level exception write the serialized block for the object
if (!nested) {
out.writeObject(writeAsByteArray(this.exception));
} else {
out.writeObject(null);
}
// handle SQLException chains
if (exception instanceof SQLException) {
if (nested) {
out.writeInt(0);
} else {
SQLException se = (SQLException) exception;
SQLException next = se.getNextException();
int count = 0;
while (next != null) {
count++;
next = next.getNextException();
}
out.writeInt(count);
next = se.getNextException();
while (next != null) {
out.writeObject(new ExceptionHolder(next, true));
next = next.getNextException();
}
}
} else if (exception instanceof SourceWarning) {
SourceWarning sw = (SourceWarning) exception;
out.writeUTF(sw.getConnectorBindingName());
out.writeUTF(sw.getModelName());
out.writeBoolean(sw.isPartialResultsError());
}
}
use of org.teiid.client.SourceWarning in project teiid by teiid.
the class WarningUtil method createWarning.
/**
* Used to wrap warnings/exceptions into SQLWarning.
* The chain of warnings is translated into a chain of SQLWarnings.
* @param reason String object which is the description of the warning.
* @param ex Throwable object which needs to be wrapped.
*/
static SQLWarning createWarning(Throwable ex) {
String sourceName = null;
String modelName = null;
if (ex instanceof SourceWarning) {
SourceWarning exception = (SourceWarning) ex;
if (exception.isPartialResultsError()) {
// $NON-NLS-1$
PartialResultsWarning warning = new PartialResultsWarning(JDBCPlugin.Util.getString("WarningUtil.Failures_occurred"));
warning.addConnectorFailure(exception.getConnectorBindingName(), TeiidSQLException.create(exception));
return warning;
}
ex = exception.getCause();
sourceName = exception.getConnectorBindingName();
modelName = exception.getModelName();
}
String code = null;
if (ex instanceof TeiidException) {
code = ((TeiidException) ex).getCode();
}
return new TeiidSQLWarning(ex.getMessage(), code, ex, sourceName, modelName);
}
Aggregations