Search in sources :

Example 81 with TeiidRuntimeException

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);
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 82 with TeiidRuntimeException

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 }));
                }
            }
        }
    }
}
Also used : BigInteger(java.math.BigInteger) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 83 with TeiidRuntimeException

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);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 84 with TeiidRuntimeException

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;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException) XATransactionException(org.teiid.client.xa.XATransactionException) TeiidException(org.teiid.core.TeiidException)

Example 85 with TeiidRuntimeException

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;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4