use of org.teiid.net.ServerConnection in project teiid by teiid.
the class TestCommSockets method helpTestNewInstance.
private void helpTestNewInstance(Properties p) throws CommunicationException, ConnectionException, SessionServiceException {
SSLConfiguration config = new SSLConfiguration();
SocketServerConnection conn = helpEstablishConnection(false, config, p);
SocketListenerStats stats = listener.getStats();
// handshake response, logon,
assertEquals(2, stats.objectsRead);
assertEquals(1, stats.sockets);
conn.cleanUp();
assertEquals(1, this.service.getActiveSessionsCount());
ServerConnection conn2 = helpEstablishConnection(false, config, p);
assertEquals(2, this.service.getActiveSessionsCount());
conn.selectServerInstance(false);
assertEquals(2, this.service.getActiveSessionsCount());
assertTrue(conn.isOpen(10000));
stats = listener.getStats();
// (ping (pool test), assert identityx2, ping (isOpen))x2
assertEquals(8, stats.objectsRead);
assertEquals(2, stats.sockets);
conn.close();
conn2.close();
}
use of org.teiid.net.ServerConnection in project teiid by teiid.
the class CommandContext method getConnection.
@Override
public TeiidConnection getConnection() throws TeiidSQLException {
LocalProfile ep = getDQPWorkContext().getConnectionProfile();
// TODO: this is problematic as the client properties are not conveyed
Properties info = new Properties();
info.put(LocalProfile.DQP_WORK_CONTEXT, getDQPWorkContext());
// $NON-NLS-1$ //$NON-NLS-2$
String url = "jdbc:teiid:" + getVdbName() + "." + getVdbVersion();
ServerConnection sc;
try {
sc = ep.createServerConnection(info);
} catch (TeiidException e) {
throw TeiidSQLException.create(e);
}
return new ConnectionImpl(sc, info, url) {
@Override
public void close() throws SQLException {
// just ignore
}
@Override
public void rollback() throws SQLException {
// just ignore
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
// TODO: detect if attempted set conflicts with current txn state
throw new TeiidSQLException();
}
@Override
public void commit() throws SQLException {
throw new TeiidSQLException();
}
@Override
public void changeUser(String userName, String newPassword) throws SQLException {
throw new TeiidSQLException();
}
@Override
protected synchronized long nextRequestID() {
// need to choose ids that won't conflict with the user connection
return -(long) (Math.random() * Long.MAX_VALUE);
}
};
}
use of org.teiid.net.ServerConnection 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.ServerConnection in project teiid by teiid.
the class TestStatement method testDisableLocalTransations.
@Test
public void testDisableLocalTransations() throws Exception {
ServerConnection mock = Mockito.mock(ServerConnection.class);
DQP dqp = Mockito.mock(DQP.class);
Mockito.stub(mock.getService(DQP.class)).toReturn(dqp);
ConnectionImpl conn = new ConnectionImpl(mock, new Properties(), "x");
StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
assertTrue(conn.getAutoCommit());
statement.execute("set disablelocaltxn true");
// $NON-NLS-1$
assertFalse(statement.execute("start transaction"));
conn.beginLocalTxnIfNeeded();
assertFalse(conn.isInLocalTxn());
statement.execute("set disablelocaltxn false");
// $NON-NLS-1$
assertFalse(statement.execute("start transaction"));
conn.beginLocalTxnIfNeeded();
assertTrue(conn.isInLocalTxn());
}
use of org.teiid.net.ServerConnection in project teiid by teiid.
the class TestConnection method getMMConnection.
public static ConnectionImpl getMMConnection(String url) {
ServerConnection mock = mock(ServerConnection.class);
DQP dqp = mock(DQP.class);
try {
stub(dqp.start((XidImpl) Mockito.anyObject(), Mockito.anyInt(), Mockito.anyInt())).toAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return ResultsFuture.NULL_FUTURE;
}
});
stub(dqp.rollback((XidImpl) Mockito.anyObject())).toAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return ResultsFuture.NULL_FUTURE;
}
});
stub(dqp.rollback()).toAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return ResultsFuture.NULL_FUTURE;
}
});
} catch (XATransactionException e) {
throw new RuntimeException(e);
}
Properties props = new Properties();
try {
new InnerDriver(url).parseUrl(props);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
stub(mock.getService(DQP.class)).toReturn(dqp);
// $NON-NLS-1$
stub(mock.getLogonResult()).toReturn(new LogonResult(new SessionToken(1, "admin"), STD_DATABASE_NAME, "fake"));
return new ConnectionImpl(mock, props, url);
}
Aggregations