use of org.teiid.core.TeiidException in project teiid by teiid.
the class TestSQLException method testCodeAsVendorCode.
@Test
public void testCodeAsVendorCode() {
// $NON-NLS-1$
TeiidException sqlexception = new TeiidException(Event.TEIID21, "foo");
// $NON-NLS-1$
String message = "top level message";
TeiidSQLException exception = TeiidSQLException.create(sqlexception, message);
assertEquals(sqlexception.getCode(), exception.getTeiidCode());
assertEquals(21, exception.getErrorCode());
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class TestSQLException method testCreateThrowable_01.
/*
* Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
*
* Tests various simple exceptions to see if the expected SQLState is
* returend.
*/
@Test
public void testCreateThrowable_01() {
testCreateThrowable(new CommunicationException(// $NON-NLS-1$
"A test MM Communication Exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
testCreateThrowable(// $NON-NLS-1$
new ConnectException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
testCreateThrowable(// $NON-NLS-1$
new ConnectionException("A test MM Connection Exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
testCreateThrowable(new IOException(// $NON-NLS-1$
"A test Generic java.io.IOException"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
testCreateThrowable(new MalformedURLException(// $NON-NLS-1$
"A test java.net.MalformedURLException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
testCreateThrowable(new TeiidException("A test Generic MM Core Exception"), // $NON-NLS-1$
SQLStates.DEFAULT);
testCreateThrowable(// $NON-NLS-1$
new TeiidException("A test MM Exception"), SQLStates.DEFAULT);
testCreateThrowable(new TeiidProcessingException(// $NON-NLS-1$
"A test Generic MM Query Processing Exception"), SQLStates.USAGE_ERROR);
testCreateThrowable(new TeiidRuntimeException("A test MM Runtime Exception"), // $NON-NLS-1$
SQLStates.DEFAULT);
testCreateThrowable(new TeiidSQLException("A test Generic MM SQL Exception"), // $NON-NLS-1$
SQLStates.DEFAULT);
testCreateThrowable(new NoRouteToHostException(// $NON-NLS-1$
"A test java.net.NoRouteToHostException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
testCreateThrowable(// $NON-NLS-1$
new NullPointerException("A test NPE"), SQLStates.DEFAULT);
testCreateThrowable(new ProcedureErrorInstructionException(// $NON-NLS-1$
"A test SQL Procedure Error exception"), SQLStates.VIRTUAL_PROCEDURE_ERROR);
testCreateThrowable(new SocketTimeoutException(// $NON-NLS-1$
"A test socket timeout exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
testCreateThrowable(// $NON-NLS-1$
new UnknownHostException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class SocketServerConnection method connect.
private ILogon connect(HostInfo hostInfo) throws CommunicationException, IOException {
hostInfo.setSsl(secure);
this.serverInstance = connectionFactory.getServerInstance(hostInfo);
this.logonResult = logonResults.get(hostInfo);
ILogon newLogon = this.serverInstance.getService(ILogon.class);
if (this.logonResult != null) {
try {
newLogon.assertIdentity(logonResult.getSessionToken());
} catch (TeiidException e) {
// session is no longer valid
disconnect();
}
}
return newLogon;
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class SocketServerConnectionFactory method getConnection.
/**
* @param connectionProperties will be updated with additional information before logon
*/
public SocketServerConnection getConnection(Properties connectionProperties) throws CommunicationException, ConnectionException {
TeiidURL url;
try {
url = new TeiidURL(connectionProperties.getProperty(TeiidURL.CONNECTION.SERVER_URL));
} catch (MalformedURLException e1) {
throw new ConnectionException(JDBCPlugin.Event.TEIID20014, e1, e1.getMessage());
}
String discoveryStrategyName = connectionProperties.getProperty(TeiidURL.CONNECTION.DISCOVERY_STRATEGY, URL);
ServerDiscovery discovery;
if (URL.equalsIgnoreCase(discoveryStrategyName)) {
discovery = new UrlServerDiscovery();
} else {
try {
discovery = (ServerDiscovery) ReflectionHelper.create(discoveryStrategyName, null, this.getClass().getClassLoader());
} catch (TeiidException e) {
throw new ConnectionException(e);
}
}
discovery.init(url, connectionProperties);
return new SocketServerConnection(this, url.isUsingSSL(), discovery, connectionProperties);
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class TestExceptionHolder method testSourceWarning.
@Test
public void testSourceWarning() 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(new SourceWarning("x", "y", obj, true)));
oos.flush();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
ExceptionHolder holder = (ExceptionHolder) ois.readObject();
SourceWarning sw = (SourceWarning) holder.getException();
assertEquals(sw.getConnectorBindingName(), "y");
assertEquals(sw.getModelName(), "x");
assertTrue(sw.isPartialResultsError());
try {
ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("old-exceptionholder.ser")));
holder = (ExceptionHolder) ois.readObject();
assertTrue(holder.getException() instanceof TeiidException);
} finally {
ois.close();
}
}
Aggregations