use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class CorrelatedReferenceCollectorVisitor method visit.
// ############### Visitor methods for language objects ##################
/**
* Visit a language object and collect symbols. This method should <b>NOT</b> be
* called directly.
* @param obj Language object
*/
public void visit(Reference obj) {
ElementSymbol e = obj.getExpression();
if (e == null || !e.isExternalReference()) {
return;
}
GroupSymbol g = e.getGroupSymbol();
for (int i = this.outerGroups.size() - (queryRoot ? 2 : 1); i >= 0; i--) {
GroupSymbol outer = this.outerGroups.get(i).get(g);
if (outer == null) {
continue;
}
try {
if (ResolverUtil.resolveElementsInGroup(outer, metadata).contains(e)) {
// add if correlated to the root groups
if (i == 0) {
this.references.add(obj);
}
return;
}
} catch (TeiidComponentException e1) {
throw new TeiidRuntimeException(e1);
}
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class BatchSerializer method writeBatch.
public static void writeBatch(ObjectOutput out, String[] types, List<? extends List<?>> batch, byte version) throws IOException {
if (batch == null) {
out.writeInt(-1);
} else {
if (version > 0 && batch.size() > 0) {
out.writeInt(-batch.size() - 1);
out.writeByte(version);
} else {
out.writeInt(batch.size());
}
if (batch.size() > 0) {
int columns = types.length;
out.writeInt(columns);
Map<Object, Integer> cache = null;
for (int i = 0; i < columns; i++) {
ColumnSerializer serializer = getSerializer(types[i], version);
if (cache == null && serializer.usesCache(version)) {
cache = new HashMap<Object, Integer>();
}
try {
serializer.writeColumn(out, i, batch, cache, version);
} catch (ClassCastException e) {
Object obj = null;
String objectClass = null;
objectSearch: for (int row = 0; row < batch.size(); row++) {
obj = batch.get(row).get(i);
if (obj != null) {
objectClass = obj.getClass().getName();
break objectSearch;
}
}
throw new TeiidRuntimeException(JDBCPlugin.Event.TEIID20001, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20001, new Object[] { types[i], new Integer(i), objectClass }));
}
}
}
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class PlanNode method toXml.
/**
* Converts this PlanNode to XML. See the JAXB bindings for the
* document form.
* @return an XML document of this PlanNode
*/
public String toXml() {
try {
XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
StringWriter stringWriter = new StringWriter();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter);
// $NON-NLS-1$ //$NON-NLS-2$
writer.writeStartDocument("UTF-8", "1.0");
writePlanNode(this, writer);
writer.writeEndDocument();
return stringWriter.toString();
} catch (FactoryConfigurationError e) {
throw new TeiidRuntimeException(JDBCPlugin.Event.TEIID20002, e);
} catch (XMLStreamException e) {
throw new TeiidRuntimeException(JDBCPlugin.Event.TEIID20003, e);
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class ExceptionUtil method sanitize.
/**
* Strip out the message and optionally the stacktrace
* @param t
* @return
*/
public static Throwable sanitize(Throwable t, boolean perserveStack) {
String code = null;
if (t instanceof TeiidException) {
code = ((TeiidException) t).getCode();
} else if (t instanceof TeiidRuntimeException) {
code = ((TeiidRuntimeException) t).getCode();
} else {
code = t.getClass().getName();
}
Throwable child = null;
if (t.getCause() != null && t.getCause() != t) {
child = sanitize(t.getCause(), perserveStack);
}
Class<?> clazz = t.getClass();
Throwable result = null;
while (clazz != null) {
if (clazz == Throwable.class || clazz == Exception.class) {
break;
}
Constructor<?> ctor = null;
try {
ctor = clazz.getDeclaredConstructor(new Class<?>[] { String.class });
result = (Throwable) ctor.newInstance(code);
break;
} catch (Exception e) {
}
clazz = clazz.getSuperclass();
}
if (result == null) {
result = new TeiidException(code);
}
if (result instanceof TeiidException) {
((TeiidException) result).setCode(code);
} else if (result instanceof TeiidRuntimeException) {
((TeiidException) result).setCode(code);
}
if (child != null) {
result.initCause(child);
}
if (perserveStack) {
result.setStackTrace(t.getStackTrace());
} else {
result.setStackTrace(new StackTraceElement[0]);
}
return result;
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class FileUtils method convertByteArrayToFile.
public static File convertByteArrayToFile(final byte[] contents, final String parentDirectoryPath, final String fileName) {
if (contents != null) {
FileOutputStream os = null;
try {
final File temp = new File(parentDirectoryPath, fileName);
os = new FileOutputStream(temp);
os.write(contents);
return temp;
} catch (Exception e) {
throw new TeiidRuntimeException(CorePlugin.Event.TEIID10024, e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e1) {
// do nothing
}
}
}
}
return null;
}
Aggregations