Search in sources :

Example 61 with TeiidException

use of org.teiid.core.TeiidException 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 62 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class ReflectionHelper method create.

/**
 * Helper method to create an instance of the class using the appropriate
 * constructor based on the ctorObjs passed.
 * @param className is the class to instantiate
 * @param ctorObjs are the objects to pass to the constructor; optional, nullable
 * @param classLoader the class loader to use; may be null if the current
 * class loader is to be used
 * @return Object is the instance of the class
 * @throws TeiidException if an error occurs instantiating the class
 */
public static final Object create(String className, Collection<?> ctorObjs, final ClassLoader classLoader) throws TeiidException {
    try {
        int size = (ctorObjs == null ? 0 : ctorObjs.size());
        Class[] names = new Class[size];
        Object[] objArray = new Object[size];
        int i = 0;
        if (size > 0) {
            for (Iterator<?> it = ctorObjs.iterator(); it.hasNext(); ) {
                Object obj = it.next();
                if (obj != null) {
                    names[i] = obj.getClass();
                    objArray[i] = obj;
                }
                i++;
            }
        }
        return create(className, objArray, names, classLoader);
    } catch (Exception e) {
        throw new TeiidException(CorePlugin.Event.TEIID10033, e);
    }
}
Also used : TeiidException(org.teiid.core.TeiidException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeiidException(org.teiid.core.TeiidException)

Example 63 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class TestFileUtils method testDirectoryPermissions.

/**
 * Test whether it's possible to read and write files in the specified directory.
 * @param dirPath Name of the directory to test
 * @throws TeiidException
 * @since 4.3
 */
public static void testDirectoryPermissions(String dirPath) throws TeiidException {
    // try to create a file
    File tmpFile = new File(dirPath + File.separatorChar + TestFileUtils.TEMP_FILE);
    boolean success = false;
    try {
        success = tmpFile.createNewFile();
    } catch (IOException e) {
    }
    if (!success) {
        // $NON-NLS-1$
        throw new TeiidException("cannot create file in " + dirPath);
    }
    // test if file can be written to
    if (!tmpFile.canWrite()) {
        // $NON-NLS-1$
        throw new TeiidException("cannot write " + dirPath);
    }
    // test if file can be read
    if (!tmpFile.canRead()) {
        // $NON-NLS-1$
        throw new TeiidException("cannot read " + dirPath);
    }
    // test if file can be renamed
    File newFile = new File(dirPath + File.separatorChar + TestFileUtils.TEMP_FILE_RENAMED);
    success = false;
    try {
        success = tmpFile.renameTo(newFile);
    } catch (Exception e) {
    }
    if (!success) {
        // $NON-NLS-1$
        throw new TeiidException("failed to rename " + dirPath);
    }
    // test if file can be deleted
    success = false;
    try {
        success = newFile.delete();
    } catch (Exception e) {
    }
    if (!success) {
        // $NON-NLS-1$
        final String msg = CorePlugin.Util.getString("FileUtils.Unable_to_delete_file_in", dirPath);
        throw new TeiidException(msg);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) TeiidException(org.teiid.core.TeiidException)

Example 64 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class TestSQLException method testCreateThrowable3.

@Test
public void testCreateThrowable3() {
    TeiidSQLException e = testCreateThrowable(new TeiidException(new SocketTimeoutException(// $NON-NLS-1$
    "A test MM Invalid Session Exception"), // $NON-NLS-1$
    "Test MetaMatrixRuntimeException with a InvalidSessionException in it"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    // test to ensure that wrapping mmsqlexceptions works
    // $NON-NLS-1$
    TeiidSQLException e1 = TeiidSQLException.create(e, "new message");
    // $NON-NLS-1$
    assertEquals("new message", e1.getMessage());
    testCreateThrowable(((TeiidSQLException) e1.getCause()).getCause(), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) TeiidException(org.teiid.core.TeiidException) Test(org.junit.Test)

Example 65 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class TestExceptionHolder method testDeserializationNotSerializable.

@Test
public void testDeserializationNotSerializable() throws Exception {
    Exception ex = new TeiidException() {

        NotSerializable ns = new NotSerializable();
    };
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(new ExceptionHolder(ex));
    oos.flush();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    ExceptionHolder holder = (ExceptionHolder) ois.readObject();
    Throwable e = holder.getException();
    assertTrue(e instanceof TeiidException);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) SQLException(java.sql.SQLException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

TeiidException (org.teiid.core.TeiidException)85 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)26 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)13 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 SQLException (java.sql.SQLException)9 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)8 BigInteger (java.math.BigInteger)6 Column (org.teiid.metadata.Column)6 Command (org.teiid.query.sql.lang.Command)6 TranslatorException (org.teiid.translator.TranslatorException)6 IOException (java.io.IOException)5 TeiidProcessingException (org.teiid.core.TeiidProcessingException)5 List (java.util.List)4 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)4 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 UpdateResponse (org.teiid.odata.api.UpdateResponse)4 Update (org.teiid.query.sql.lang.Update)4 SocketTimeoutException (java.net.SocketTimeoutException)3