Search in sources :

Example 1 with ConnectionImpl

use of org.teiid.jdbc.ConnectionImpl in project teiid by teiid.

the class ODataFilter method registerVDBListener.

protected void registerVDBListener(Client client, Connection conn) {
    if (!this.listenerRegistered) {
        synchronized (this) {
            if (!this.listenerRegistered) {
                if (client instanceof LocalClient) {
                    try {
                        ConnectionImpl connection = (ConnectionImpl) conn;
                        LocalServerConnection lsc = (LocalServerConnection) connection.getServerConnection();
                        lsc.addListener(this);
                        this.listenerRegistered = true;
                    } catch (SQLException e) {
                        LogManager.logWarning(LogConstants.CTX_ODATA, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16014));
                    }
                }
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) LocalClient(org.teiid.olingo.service.LocalClient) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) LocalServerConnection(org.teiid.transport.LocalServerConnection)

Example 2 with ConnectionImpl

use of org.teiid.jdbc.ConnectionImpl 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 3 with ConnectionImpl

use of org.teiid.jdbc.ConnectionImpl 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)

Example 4 with ConnectionImpl

use of org.teiid.jdbc.ConnectionImpl in project teiid by teiid.

the class LocalClient method buildConnection.

public static ConnectionImpl buildConnection(TeiidDriver driver, String vdbName, String version, Properties props) throws SQLException {
    StringBuilder sb = new StringBuilder();
    // $NON-NLS-1$
    sb.append("jdbc:teiid:").append(vdbName);
    if (version != null) {
        // $NON-NLS-1$
        sb.append(".").append(version);
    }
    // $NON-NLS-1$
    sb.append(";");
    if (props.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION) == null) {
        // $NON-NLS-1$
        props.setProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, "true");
    }
    if (props.getProperty(LocalProfile.TRANSPORT_NAME) == null) {
        props.setProperty(LocalProfile.TRANSPORT_NAME, "odata");
    }
    if (props.getProperty(LocalProfile.WAIT_FOR_LOAD) == null) {
        // $NON-NLS-1$
        props.setProperty(LocalProfile.WAIT_FOR_LOAD, "0");
    }
    ConnectionImpl connection = driver.connect(sb.toString(), props);
    return connection;
}
Also used : ConnectionImpl(org.teiid.jdbc.ConnectionImpl)

Example 5 with ConnectionImpl

use of org.teiid.jdbc.ConnectionImpl in project teiid by teiid.

the class TestJDBCSocketTransport method testSyncTimeout.

/**
 * Tests to ensure that a SynchronousTtl/synchTimeout does
 * not cause a cancel.
 * TODO: had to increase the values since the test would fail on slow machine runs
 * @throws Exception
 */
@Test
public void testSyncTimeout() throws Exception {
    TeiidDriver td = new TeiidDriver();
    td.setSocketProfile(new ConnectionProfile() {

        @Override
        public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
            SocketServerConnectionFactory sscf = new SocketServerConnectionFactory();
            sscf.initialize(info);
            try {
                return new ConnectionImpl(sscf.getConnection(info), info, url);
            } catch (CommunicationException e) {
                throw TeiidSQLException.create(e);
            } catch (ConnectionException e) {
                throw TeiidSQLException.create(e);
            }
        }
    });
    Properties p = new Properties();
    p.setProperty("user", "testuser");
    p.setProperty("password", "testpassword");
    ConnectorManagerRepository cmr = server.getConnectorManagerRepository();
    AutoGenDataService agds = new AutoGenDataService() {

        @Override
        public Object getConnectionFactory() throws TranslatorException {
            return null;
        }
    };
    // wait longer than the synch ttl/soTimeout, we should still succeed
    agds.setSleep(2000);
    cmr.addConnectorManager("source", agds);
    try {
        conn = td.connect("jdbc:teiid:parts@mm://" + addr.getHostName() + ":" + jdbcTransport.getPort(), p);
        Statement s = conn.createStatement();
        assertTrue(s.execute("select * from parts"));
    } finally {
        server.setConnectorManagerRepository(cmr);
    }
}
Also used : SocketServerConnectionFactory(org.teiid.net.socket.SocketServerConnectionFactory) CommunicationException(org.teiid.net.CommunicationException) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ConnectionProfile(org.teiid.jdbc.ConnectionProfile) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) Properties(java.util.Properties) TeiidDriver(org.teiid.jdbc.TeiidDriver) AutoGenDataService(org.teiid.dqp.service.AutoGenDataService) ConnectionException(org.teiid.net.ConnectionException) Test(org.junit.Test)

Aggregations

ConnectionImpl (org.teiid.jdbc.ConnectionImpl)5 Properties (java.util.Properties)2 ConnectionProfile (org.teiid.jdbc.ConnectionProfile)2 TeiidDriver (org.teiid.jdbc.TeiidDriver)2 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)2 CommunicationException (org.teiid.net.CommunicationException)2 ConnectionException (org.teiid.net.ConnectionException)2 LocalServerConnection (org.teiid.transport.LocalServerConnection)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 StartException (org.jboss.msc.service.StartException)1 Test (org.junit.Test)1 DQP (org.teiid.client.DQP)1 TeiidException (org.teiid.core.TeiidException)1 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)1 AutoGenDataService (org.teiid.dqp.service.AutoGenDataService)1 SessionService (org.teiid.dqp.service.SessionService)1 LocalProfile (org.teiid.jdbc.LocalProfile)1 ServerConnection (org.teiid.net.ServerConnection)1