Search in sources :

Example 11 with DQP

use of org.teiid.client.DQP 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)

Example 12 with DQP

use of org.teiid.client.DQP in project teiid by teiid.

the class TransportService method start.

@Override
public void start(StartContext context) throws StartException {
    this.setVDBRepository(this.getVdbRepository());
    SessionService ss = sessionServiceInjector.getValue();
    this.setSecurityHelper(ss.getSecurityHelper());
    // create the necessary services
    // $NON-NLS-1$
    this.logon = new LogonImpl(ss, "teiid-cluster");
    DQP dqpProxy = proxyService(DQP.class, getDQP(), LogConstants.CTX_DQP);
    this.registerClientService(ILogon.class, logon, LogConstants.CTX_SECURITY);
    this.registerClientService(DQP.class, dqpProxy, LogConstants.CTX_DQP);
    this.setAuthenticationType(ss.getDefaultAuthenticationType());
    if (this.socketConfig != null) {
        /*
    		try {
				// this is to show the bound socket port in the JMX console
				SocketBinding socketBinding = getSocketBindingInjector().getValue();
				ManagedServerSocketBinding ss = (ManagedServerSocketBinding)socketBinding.getSocketBindings().getServerSocketFactory().createServerSocket(socketBinding.getName());
				socketBinding.getSocketBindings().getNamedRegistry().registerBinding(ss);
			}  catch (IOException e) {
				throw new StartException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50013));
			}
    		*/
        this.address = getSocketBindingInjector().getValue().getSocketAddress();
        this.socketConfig.setBindAddress(this.address.getHostName());
        this.socketConfig.setPortNumber(this.address.getPort());
        boolean sslEnabled = false;
        if (this.socketConfig.getSSLConfiguration() != null) {
            sslEnabled = this.socketConfig.getSSLConfiguration().isSslEnabled();
        }
        if (socketConfig.getProtocol() == WireProtocol.teiid) {
            this.socketListener = new SocketListener(address, this.socketConfig, this, getBufferManagerInjector().getValue());
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50012, this.transportName, address.getHostName(), String.valueOf(address.getPort()), (sslEnabled ? "ON" : "OFF")));
        } else if (socketConfig.getProtocol() == WireProtocol.pg) {
            TeiidDriver driver = new TeiidDriver();
            driver.setLocalProfile(new ConnectionProfile() {

                @Override
                public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
                    try {
                        LocalServerConnection sc = new LocalServerConnection(info, true) {

                            @Override
                            protected ClientServiceRegistry getClientServiceRegistry(String name) {
                                return TransportService.this;
                            }
                        };
                        return new ConnectionImpl(sc, info, url);
                    } catch (CommunicationException e) {
                        throw TeiidSQLException.create(e);
                    } catch (ConnectionException e) {
                        throw TeiidSQLException.create(e);
                    }
                }
            });
            ODBCSocketListener odbc = new ODBCSocketListener(address, this.socketConfig, this, getBufferManagerInjector().getValue(), getMaxODBCLobSizeAllowed(), this.logon, driver);
            this.socketListener = odbc;
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50037, this.transportName, address.getHostName(), String.valueOf(address.getPort()), (sslEnabled ? "ON" : "OFF")));
        } else {
            throw new StartException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50013));
        }
    } else {
        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50038, LocalServerConnection.jndiNameForRuntime(transportName)));
    }
}
Also used : DQP(org.teiid.client.DQP) CommunicationException(org.teiid.net.CommunicationException) ConnectionProfile(org.teiid.jdbc.ConnectionProfile) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) Properties(java.util.Properties) SessionService(org.teiid.dqp.service.SessionService) LogonImpl(org.teiid.transport.LogonImpl) SocketListener(org.teiid.transport.SocketListener) ODBCSocketListener(org.teiid.transport.ODBCSocketListener) TeiidDriver(org.teiid.jdbc.TeiidDriver) StartException(org.jboss.msc.service.StartException) LocalServerConnection(org.teiid.transport.LocalServerConnection) ODBCSocketListener(org.teiid.transport.ODBCSocketListener) ConnectionException(org.teiid.net.ConnectionException)

Aggregations

DQP (org.teiid.client.DQP)12 Properties (java.util.Properties)9 Test (org.junit.Test)7 ResultsFuture (org.teiid.client.util.ResultsFuture)7 ResultsMessage (org.teiid.client.ResultsMessage)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 SQLException (java.sql.SQLException)3 LogonResult (org.teiid.client.security.LogonResult)3 ConnectionException (org.teiid.net.ConnectionException)3 ServerConnection (org.teiid.net.ServerConnection)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 InvalidSessionException (org.teiid.client.security.InvalidSessionException)2 SessionToken (org.teiid.client.security.SessionToken)2 TeiidException (org.teiid.core.TeiidException)2 CommunicationException (org.teiid.net.CommunicationException)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 BatchUpdateException (java.sql.BatchUpdateException)1