Search in sources :

Example 6 with ServerConnection

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();
}
Also used : SocketServerConnection(org.teiid.net.socket.SocketServerConnection) ServerConnection(org.teiid.net.ServerConnection) SocketServerConnection(org.teiid.net.socket.SocketServerConnection)

Example 7 with ServerConnection

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);
        }
    };
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ServerConnection(org.teiid.net.ServerConnection) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) LocalProfile(org.teiid.jdbc.LocalProfile) TeiidException(org.teiid.core.TeiidException)

Example 8 with ServerConnection

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);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleLoader(org.jboss.modules.ModuleLoader) ServerConnection(org.teiid.net.ServerConnection) Module(org.jboss.modules.Module) ConnectionException(org.teiid.net.ConnectionException)

Example 9 with ServerConnection

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());
}
Also used : DQP(org.teiid.client.DQP) ServerConnection(org.teiid.net.ServerConnection) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with ServerConnection

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);
}
Also used : DQP(org.teiid.client.DQP) SQLException(java.sql.SQLException) SessionToken(org.teiid.client.security.SessionToken) LogonResult(org.teiid.client.security.LogonResult) ServerConnection(org.teiid.net.ServerConnection) XATransactionException(org.teiid.client.xa.XATransactionException) Properties(java.util.Properties) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Aggregations

ServerConnection (org.teiid.net.ServerConnection)11 Test (org.junit.Test)5 Properties (java.util.Properties)4 LogonResult (org.teiid.client.security.LogonResult)4 DQP (org.teiid.client.DQP)3 Connection (java.sql.Connection)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 TeiidException (org.teiid.core.TeiidException)2 BatchUpdateException (java.sql.BatchUpdateException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 XAResource (javax.transaction.xa.XAResource)1 Module (org.jboss.modules.Module)1 ModuleLoadException (org.jboss.modules.ModuleLoadException)1 ModuleLoader (org.jboss.modules.ModuleLoader)1 Answer (org.mockito.stubbing.Answer)1 RequestMessage (org.teiid.client.RequestMessage)1 ResultsMessage (org.teiid.client.ResultsMessage)1 SessionToken (org.teiid.client.security.SessionToken)1