Search in sources :

Example 11 with TeiidRuntimeException

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

the class TestExceptionHolder method testDeserializationUnknownChildException2.

@Test
public void testDeserializationUnknownChildException2() 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(obj));
    oos.flush();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    ExceptionHolder holder = (ExceptionHolder) ois.readObject();
    Throwable e = holder.getException();
    assertTrue(e instanceof TeiidRuntimeException);
    // $NON-NLS-1$
    assertEquals("Remote test.UnknownException: Unknown Exception", e.getMessage());
}
Also used : ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) 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) ByteArrayInputStream(java.io.ByteArrayInputStream) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 12 with TeiidRuntimeException

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

the class TestExceptionHolder method testDeserializationUnknownChildException.

@Test
public void testDeserializationUnknownChildException() throws Exception {
    // $NON-NLS-1$
    ClassLoader cl = new URLClassLoader(new URL[] { UnitTestUtil.getTestDataFile("test.jar").toURI().toURL() });
    // $NON-NLS-1$
    Exception obj = (Exception) ReflectionHelper.create("test.UnknownException", null, cl);
    // $NON-NLS-1$
    obj.initCause(new SQLException("something bad happended"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    // $NON-NLS-1$
    oos.writeObject(new ExceptionHolder(new BadException2(obj, "I have foreign exception embedded in me")));
    oos.flush();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    ExceptionHolder holder = (ExceptionHolder) ois.readObject();
    Throwable e = holder.getException();
    assertTrue(e instanceof BadException2);
    // $NON-NLS-1$
    assertEquals("Remote org.teiid.client.util.TestExceptionHolder$BadException2: I have foreign exception embedded in me", e.getMessage());
    e = e.getCause();
    assertTrue(e instanceof TeiidRuntimeException);
    e = e.getCause();
    assertTrue(e instanceof SQLException);
    // $NON-NLS-1$
    assertEquals("Remote java.sql.SQLException: something bad happended", e.getMessage());
}
Also used : SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) 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) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 13 with TeiidRuntimeException

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

the class ClobType method compareTo.

@Override
public int compareTo(ClobType o) {
    try {
        Reader cs1 = this.getCharacterStream();
        Reader cs2 = o.getCharacterStream();
        long len1 = this.length();
        long len2 = o.length();
        long n = Math.min(len1, len2);
        for (long i = 0; i < n; i++) {
            int c1 = cs1.read();
            int c2 = cs2.read();
            if (c1 != c2) {
                return c1 - c2;
            }
        }
        return Long.signum(len1 - len2);
    } catch (SQLException e) {
        throw new TeiidRuntimeException(CorePlugin.Event.TEIID10056, e);
    } catch (IOException e) {
        throw new TeiidRuntimeException(CorePlugin.Event.TEIID10057, e);
    }
}
Also used : SQLException(java.sql.SQLException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 14 with TeiidRuntimeException

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

the class ClobType method getCharSequence.

public CharSequence getCharSequence() {
    return new CharSequence() {

        private char[] buffer = new char[CHAR_SEQUENCE_BUFFER_SIZE];

        private int bufLength;

        private Reader reader;

        private int beginPosition;

        public int length() {
            long result;
            try {
                result = ClobType.this.length();
            } catch (SQLException err) {
                throw new TeiidRuntimeException(CorePlugin.Event.TEIID10051, err);
            }
            if (((int) result) != result) {
                throw new TeiidRuntimeException(CorePlugin.Event.TEIID10052, CorePlugin.Util.gs(CorePlugin.Event.TEIID10052));
            }
            return (int) result;
        }

        public char charAt(int index) {
            try {
                if ((reader == null || index < beginPosition) && reader != null) {
                    reader.close();
                    reader = null;
                }
                if (buffer == null || index < beginPosition || index >= beginPosition + bufLength) {
                    if (reference instanceof ClobImpl) {
                        if (reader == null) {
                            reader = getCharacterStream();
                        }
                        bufLength = reader.read(buffer, 0, buffer.length);
                    } else {
                        String stringBuffer = ClobType.this.getSubString(index + 1, CHAR_SEQUENCE_BUFFER_SIZE);
                        bufLength = stringBuffer.length();
                        buffer = stringBuffer.toCharArray();
                    }
                    beginPosition = index;
                }
                return buffer[index - beginPosition];
            } catch (IOException err) {
                throw new TeiidRuntimeException(CorePlugin.Event.TEIID10053, err);
            } catch (SQLException err) {
                throw new TeiidRuntimeException(CorePlugin.Event.TEIID10053, err);
            }
        }

        public CharSequence subSequence(int start, int end) {
            try {
                return ClobType.this.getSubString(start + 1, end - start);
            } catch (SQLException err) {
                throw new TeiidRuntimeException(CorePlugin.Event.TEIID10054, err);
            }
        }
    };
}
Also used : SQLException(java.sql.SQLException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 15 with TeiidRuntimeException

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

the class DhKeyGenerator method loadKeySpecification.

private static DHParameterSpec loadKeySpecification(String propsFile) {
    Properties props = new Properties();
    InputStream is = null;
    try {
        is = DhKeyGenerator.class.getResourceAsStream(propsFile);
        props.load(is);
    } catch (IOException e) {
        throw new TeiidRuntimeException(CorePlugin.Event.TEIID10000, e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException e) {
        }
    }
    // $NON-NLS-1$
    BigInteger p = new BigInteger(props.getProperty("p"));
    // $NON-NLS-1$
    BigInteger g = new BigInteger(props.getProperty("g"));
    DHParameterSpec result = new DHParameterSpec(p, g, Integer.parseInt(props.getProperty(// $NON-NLS-1$
    "l")));
    return result;
}
Also used : InputStream(java.io.InputStream) BigInteger(java.math.BigInteger) DHParameterSpec(javax.crypto.spec.DHParameterSpec) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Properties(java.util.Properties)

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