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());
}
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());
}
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);
}
}
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);
}
}
};
}
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;
}
Aggregations