use of org.teiid.net.ConnectionException 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.net.ConnectionException in project teiid by teiid.
the class SocketServerConnection method getService.
public <T> T getService(Class<T> iface) {
return iface.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { iface }, new SocketServerInstanceImpl.RemoteInvocationHandler(iface, PropertiesUtils.getBooleanProperty(connProps, TeiidURL.CONNECTION.ENCRYPT_REQUESTS, false)) {
@Override
protected SocketServerInstance getInstance() throws CommunicationException {
if (failOver && System.currentTimeMillis() - lastPing > pingFailOverInterval) {
try {
ResultsFuture<?> future = selectServerInstance(false).getService(ILogon.class).ping();
future.get();
} catch (SingleInstanceCommunicationException e) {
closeServerInstance();
} catch (CommunicationException e) {
throw e;
} catch (InvalidSessionException e) {
disconnect();
closeServerInstance();
} catch (Exception e) {
closeServerInstance();
}
}
lastPing = System.currentTimeMillis();
try {
return selectServerInstance(false);
} catch (ConnectionException e) {
throw new CommunicationException(e);
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
return super.invoke(proxy, method, args);
} catch (Exception e) {
if (ExceptionUtil.getExceptionOfType(e, InvalidSessionException.class) != null) {
disconnect();
}
throw e;
}
}
}));
}
use of org.teiid.net.ConnectionException 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.net.ConnectionException in project teiid by teiid.
the class ModuleHelper method createFromModule.
static ServerConnection createFromModule(Properties info) throws ConnectionException, TeiidException {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
ModuleLoader callerModuleLoader = Module.getCallerModuleLoader();
if (callerModuleLoader == null) {
logger.fine(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20033));
// $NON-NLS-1$
return (ServerConnection) ReflectionHelper.create("org.teiid.transport.LocalServerConnection", Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, LocalProfile.USE_CALLING_THREAD, true)), Thread.currentThread().getContextClassLoader());
}
// $NON-NLS-1$
final Module module = callerModuleLoader.loadModule(ModuleIdentifier.create("org.jboss.teiid"));
Thread.currentThread().setContextClassLoader(module.getClassLoader());
// $NON-NLS-1$
return (ServerConnection) ReflectionHelper.create("org.teiid.transport.LocalServerConnection", Arrays.asList(info, PropertiesUtils.getBooleanProperty(info, LocalProfile.USE_CALLING_THREAD, true)), Thread.currentThread().getContextClassLoader());
} catch (ModuleLoadException e) {
throw new ConnectionException(JDBCPlugin.Event.TEIID20008, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20008));
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
use of org.teiid.net.ConnectionException in project teiid by teiid.
the class VDBRepository method waitForFinished.
public void waitForFinished(VDBKey key, int timeOutMillis) throws ConnectionException {
CompositeVDB cvdb = null;
if (timeOutMillis < 0) {
timeOutMillis = DEFAULT_TIMEOUT_MILLIS;
}
long timeOutNanos = TimeUnit.MILLISECONDS.toNanos(timeOutMillis);
lock.lock();
try {
while ((cvdb = this.vdbRepo.get(key)) == null) {
if (timeOutNanos <= 0) {
throw new ConnectionException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40096, timeOutMillis, key.getName(), key.getVersion()));
}
timeOutNanos = this.vdbAdded.awaitNanos(timeOutNanos);
}
} catch (InterruptedException e) {
return;
} finally {
lock.unlock();
}
VDBMetaData vdb = cvdb.getVDB();
long finishNanos = System.nanoTime() + timeOutNanos;
synchronized (vdb) {
while (vdb.getStatus() != Status.ACTIVE) {
long millis = timeOutNanos / 1000000;
if (millis <= 0) {
throw new ConnectionException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40097, timeOutMillis, key.getName(), key.getVersion(), vdb.getValidityErrors()));
}
try {
vdb.wait(millis);
} catch (InterruptedException e) {
return;
}
timeOutNanos = finishNanos - System.nanoTime();
}
}
}
Aggregations