Search in sources :

Example 1 with StatementImpl

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

the class ODBCServerRemoteImpl method logon.

@Override
public void logon(String databaseName, String user, NullTerminatedStringDataInputStream data, SocketAddress remoteAddress) {
    try {
        java.util.Properties info = new java.util.Properties();
        info.put(TeiidURL.CONNECTION.USER_NAME, user);
        AuthenticationType authType = getAuthenticationType(user, databaseName);
        String password = null;
        if (authType.equals(AuthenticationType.USERPASSWORD)) {
            password = data.readString();
        } else if (authType.equals(AuthenticationType.GSS)) {
            byte[] serviceToken = data.readServiceToken();
            GSSResult result = this.logon.neogitiateGssLogin(serviceToken, databaseName, null, user);
            serviceToken = result.getServiceToken();
            if (result.isAuthenticated()) {
                info.put(ILogon.KRB5TOKEN, serviceToken);
                if (!result.isNullContinuationToken()) {
                    this.client.authenticationGSSContinue(serviceToken);
                }
                // if delegation is in progress, participate in it.
                if (result.getDelegationCredential() != null) {
                    info.put(GSSCredential.class.getName(), result.getDelegationCredential());
                }
            } else {
                this.client.authenticationGSSContinue(serviceToken);
                return;
            }
        } else {
            // $NON-NLS-1$
            throw new AssertionError("Unsupported Authentication Type");
        }
        // this is local connection
        // $NON-NLS-1$
        String url = "jdbc:teiid:" + databaseName;
        if (password != null) {
            info.put(TeiidURL.CONNECTION.PASSWORD, password);
        }
        String applicationName = this.props.getProperty(PgBackendProtocol.APPLICATION_NAME);
        if (applicationName == null) {
            applicationName = PgBackendProtocol.DEFAULT_APPLICATION_NAME;
            this.props.put(PgBackendProtocol.APPLICATION_NAME, applicationName);
        }
        info.put(TeiidURL.CONNECTION.APP_NAME, applicationName);
        if (remoteAddress instanceof InetSocketAddress) {
            SocketServerConnection.updateConnectionProperties(info, ((InetSocketAddress) remoteAddress).getAddress(), false);
        }
        this.connection = driver.connect(url, info);
        // Propagate so that we can use in pg methods
        SessionMetadata sm = ((LocalServerConnection) this.connection.getServerConnection()).getWorkContext().getSession();
        sm.addAttchment(ODBCServerRemoteImpl.class, this);
        setConnectionProperties(this.connection);
        int hash = this.connection.getConnectionId().hashCode();
        Enumeration<?> keys = this.props.propertyNames();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            this.connection.setExecutionProperty(key, this.props.getProperty(key));
        }
        StatementImpl s = this.connection.createStatement();
        try {
            // $NON-NLS-1$
            s.execute("select teiid_session_set('resolve_groupby_positional', true)");
        } finally {
            s.close();
        }
        this.client.authenticationSucess(hash, hash);
        ready();
    } catch (SQLException e) {
        errorOccurred(e);
        terminate();
    } catch (LogonException e) {
        errorOccurred(e);
        terminate();
    } catch (IOException e) {
        errorOccurred(e);
        terminate();
    }
}
Also used : Properties(java.util.Properties) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) SQLException(java.sql.SQLException) InetSocketAddress(java.net.InetSocketAddress) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) IOException(java.io.IOException) Properties(java.util.Properties) GSSResult(org.teiid.security.GSSResult) PreparedStatementImpl(org.teiid.jdbc.PreparedStatementImpl) StatementImpl(org.teiid.jdbc.StatementImpl) LogonException(org.teiid.client.security.LogonException) AuthenticationType(org.teiid.net.socket.AuthenticationType)

Example 2 with StatementImpl

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

the class ODBCServerRemoteImpl method sqlExecute.

private void sqlExecute(final String sql, final ResultsFuture<Integer> completion) throws SQLException {
    String modfiedSQL = fixSQL(sql);
    final StatementImpl stmt = connection.createStatement();
    executionFuture = stmt.submitExecute(modfiedSQL, null);
    completion.addCompletionListener(new ResultsFuture.CompletionListener<Integer>() {

        public void onCompletion(ResultsFuture<Integer> future) {
            try {
                stmt.close();
            } catch (SQLException e) {
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_ODBC, e, "Error closing statement");
            }
        }
    });
    executionFuture.addCompletionListener(new ResultsFuture.CompletionListener<Boolean>() {

        @Override
        public void onCompletion(ResultsFuture<Boolean> future) {
            executionFuture = null;
            try {
                if (future.get()) {
                    List<PgColInfo> cols = getPgColInfo(stmt.getResultSet().getMetaData());
                    String tag = PgBackendProtocol.getCompletionTag(sql, null);
                    // $NON-NLS-1$ //$NON-NLS-2$
                    client.sendResults(sql, stmt.getResultSet(), cols, completion, CursorDirection.FORWARD, -1, tag.equals("SELECT") || tag.equals("SHOW"), null);
                } else {
                    client.sendUpdateCount(sql, stmt.getUpdateCount());
                    updateSessionProperties();
                    completion.getResultsReceiver().receiveResults(1);
                }
            } catch (Throwable e) {
                if (!completion.isDone()) {
                    completion.getResultsReceiver().exceptionOccurred(e);
                }
            }
        }
    });
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) SQLException(java.sql.SQLException) ResultsFuture(org.teiid.client.util.ResultsFuture) PreparedStatementImpl(org.teiid.jdbc.PreparedStatementImpl) StatementImpl(org.teiid.jdbc.StatementImpl) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

SQLException (java.sql.SQLException)2 PreparedStatementImpl (org.teiid.jdbc.PreparedStatementImpl)2 StatementImpl (org.teiid.jdbc.StatementImpl)2 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)1 LogonException (org.teiid.client.security.LogonException)1 ResultsFuture (org.teiid.client.util.ResultsFuture)1 AuthenticationType (org.teiid.net.socket.AuthenticationType)1 GSSResult (org.teiid.security.GSSResult)1