Java Code Examples for com.mysql.cj.protocol.SocketConnection#connect()

The following examples show how to use com.mysql.cj.protocol.SocketConnection#connect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XProtocol.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
public XProtocol(String host, int port, String defaultSchema, PropertySet propertySet) {

        this.defaultSchemaName = defaultSchema;

        // Override common connectTimeout with xdevapi.connect-timeout to provide unified logic in StandardSocketFactory
        RuntimeProperty<Integer> connectTimeout = propertySet.getIntegerProperty(PropertyKey.connectTimeout);
        RuntimeProperty<Integer> xdevapiConnectTimeout = propertySet.getIntegerProperty(PropertyKey.xdevapiConnectTimeout);
        if (xdevapiConnectTimeout.isExplicitlySet() || !connectTimeout.isExplicitlySet()) {
            connectTimeout.setValue(xdevapiConnectTimeout.getValue());
        }

        SocketConnection socketConn = propertySet.getBooleanProperty(PropertyKey.xdevapiUseAsyncProtocol).getValue() ? new XAsyncSocketConnection()
                : new NativeSocketConnection();
        socketConn.connect(host, port, propertySet, null, null, 0);
        init(null, socketConn, propertySet, null);
    }
 
Example 2
Source File: XProtocol.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
public XProtocol(HostInfo hostInfo, PropertySet propertySet) {
    String host = hostInfo.getHost();
    if (host == null || StringUtils.isEmptyOrWhitespaceOnly(host)) {
        host = "localhost";
    }
    int port = hostInfo.getPort();
    if (port < 0) {
        port = 33060;
    }
    this.defaultSchemaName = hostInfo.getDatabase();

    // Override common connectTimeout with xdevapi.connect-timeout to provide unified logic in StandardSocketFactory
    RuntimeProperty<Integer> connectTimeout = propertySet.getIntegerProperty(PropertyKey.connectTimeout);
    RuntimeProperty<Integer> xdevapiConnectTimeout = propertySet.getIntegerProperty(PropertyKey.xdevapiConnectTimeout);
    if (xdevapiConnectTimeout.isExplicitlySet() || !connectTimeout.isExplicitlySet()) {
        connectTimeout.setValue(xdevapiConnectTimeout.getValue());
    }

    SocketConnection socketConn = propertySet.getBooleanProperty(PropertyKey.xdevapiUseAsyncProtocol).getValue() ? new XAsyncSocketConnection()
            : new NativeSocketConnection();
    socketConn.connect(host, port, propertySet, null, null, 0);
    init(null, socketConn, propertySet, null);
}
 
Example 3
Source File: XProtocol.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static XProtocol getInstance(String host, int port, PropertySet propertySet) {

        SocketConnection socketConnection = propertySet.getBooleanReadableProperty(PropertyDefinitions.PNAME_useAsyncProtocol).getValue()
                ? new XAsyncSocketConnection() :
                // TODO: we should share SocketConnection unless there comes a time where they need to diverge
                new NativeSocketConnection();

        socketConnection.connect(host, port, propertySet, null, null, 0);

        XProtocol protocol = new XProtocol();
        protocol.init(null, socketConnection, propertySet, null);
        return protocol;
    }
 
Example 4
Source File: NativeSession.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void connect(HostInfo hi, String user, String password, String database, int loginTimeout, TransactionEventHandler transactionManager)
        throws IOException {

    this.hostInfo = hi;

    // reset max-rows to default value
    this.setSessionMaxRows(-1);

    // TODO do we need different types of physical connections?
    SocketConnection socketConnection = new NativeSocketConnection();
    socketConnection.connect(this.hostInfo.getHost(), this.hostInfo.getPort(), this.propertySet, getExceptionInterceptor(), this.log, loginTimeout);

    // we use physical connection to create a -> protocol
    // this configuration places no knowledge of protocol or session on physical connection.
    // physical connection is responsible *only* for I/O streams
    if (this.protocol == null) {
        this.protocol = NativeProtocol.getInstance(this, socketConnection, this.propertySet, this.log, transactionManager);
    } else {
        this.protocol.init(this, socketConnection, this.propertySet, transactionManager);
    }

    // use protocol to create a -> session
    // protocol is responsible for building a session and authenticating (using AuthenticationProvider) internally
    this.protocol.connect(user, password, database);

    // error messages are returned according to character_set_results which, at this point, is set from the response packet
    this.protocol.getServerSession().setErrorMessageEncoding(this.protocol.getAuthenticationProvider().getEncodingForHandshake());

    this.isClosed = false;
}
 
Example 5
Source File: NativeSession.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
public void connect(HostInfo hi, String user, String password, String database, int loginTimeout, TransactionEventHandler transactionManager)
        throws IOException {

    this.hostInfo = hi;

    // reset max-rows to default value
    this.setSessionMaxRows(-1);

    // TODO do we need different types of physical connections?
    SocketConnection socketConnection = new NativeSocketConnection();
    socketConnection.connect(this.hostInfo.getHost(), this.hostInfo.getPort(), this.propertySet, getExceptionInterceptor(), this.log, loginTimeout);

    // we use physical connection to create a -> protocol
    // this configuration places no knowledge of protocol or session on physical connection.
    // physical connection is responsible *only* for I/O streams
    if (this.protocol == null) {
        this.protocol = NativeProtocol.getInstance(this, socketConnection, this.propertySet, this.log, transactionManager);
    } else {
        this.protocol.init(this, socketConnection, this.propertySet, transactionManager);
    }

    // use protocol to create a -> session
    // protocol is responsible for building a session and authenticating (using AuthenticationProvider) internally
    this.protocol.connect(user, password, database);

    // error messages are returned according to character_set_results which, at this point, is set from the response packet
    this.protocol.getServerSession().setErrorMessageEncoding(this.protocol.getAuthenticationProvider().getEncodingForHandshake());

    this.isClosed = false;
}