Java Code Examples for com.mysql.cj.conf.url.ReplicationConnectionUrl

The following examples show how to use com.mysql.cj.conf.url.ReplicationConnectionUrl. These examples are extracted from open source projects. 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 Project: quarkus   Source File: MySQLJDBCReflections.java    License: Apache License 2.0 5 votes vote down vote up
@BuildStep
void registerDriverForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {

    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, Driver.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, FailoverDnsSrvConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, FailoverConnectionUrl.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, SingleConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, LoadBalanceConnectionUrl.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
            LoadBalanceDnsSrvConnectionUrl.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
            ReplicationDnsSrvConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, ReplicationConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, XDevApiConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, XDevApiDnsSrvConnectionUrl.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
            com.mysql.cj.jdbc.ha.LoadBalancedAutoCommitInterceptor.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StandardLogger.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, Wrapper.class.getName()));
}
 
Example 2
Source Project: lams   Source File: NonRegisteringDriver.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Try to make a database connection to the given URL. The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given
 * URL. This will be common, as when the JDBC driverManager is asked to connect to a given URL, it passes the URL to each loaded driver in turn.
 * 
 * <p>
 * The driver should raise an SQLException if the URL is null or if it is the right driver to connect to the given URL, but has trouble connecting to the
 * database.
 * </p>
 * 
 * <p>
 * The java.util.Properties argument can be used to pass arbitrary string tag/value pairs as connection arguments. These properties take precedence over any
 * properties sent in the URL.
 * </p>
 * 
 * <p>
 * MySQL protocol takes the form:
 * 
 * <PRE>
 * jdbc:mysql://host:port/database
 * </PRE>
 * 
 * </p>
 * 
 * @param url
 *            the URL of the database to connect to
 * @param info
 *            a list of arbitrary tag/value pairs as connection arguments
 * 
 * @return a connection to the URL or null if it isn't us
 * 
 * @exception SQLException
 *                if a database access error occurs or the url is {@code null}
 * 
 * @see java.sql.Driver#connect
 */
public java.sql.Connection connect(String url, Properties info) throws SQLException {

    try {
        ConnectionUrl conStr = ConnectionUrl.getConnectionUrlInstance(url, info);
        if (conStr.getType() == null) {
            /*
             * According to JDBC spec:
             * The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. This will be common, as when the
             * JDBC driver manager is asked to connect to a given URL it passes the URL to each loaded driver in turn.
             */
            return null;
        }

        switch (conStr.getType()) {
            case LOADBALANCE_CONNECTION:
                return LoadBalancedConnectionProxy.createProxyInstance((LoadbalanceConnectionUrl) conStr);

            case FAILOVER_CONNECTION:
                return FailoverConnectionProxy.createProxyInstance(conStr);

            case REPLICATION_CONNECTION:
                return ReplicationConnectionProxy.createProxyInstance((ReplicationConnectionUrl) conStr);

            case XDEVAPI_SESSION:
                // TODO test it
                //return new XJdbcConnection(conStr.getProperties());

            default:
                return com.mysql.cj.jdbc.ConnectionImpl.getInstance(conStr.getMainHost());

        }

    } catch (CJException ex) {
        throw ExceptionFactory.createException(UnableToConnectException.class,
                Messages.getString("NonRegisteringDriver.17", new Object[] { ex.toString() }), ex);
    }
}
 
Example 3
private ReplicationConnectionUrl getConnectionUrl() {
    return (ReplicationConnectionUrl) this.connectionUrl;
}
 
Example 4
private ReplicationConnectionUrl getConnectionUrl() {
    return (ReplicationConnectionUrl) this.connectionUrl;
}
 
Example 5
/**
 * Try to make a database connection to the given URL. The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given
 * URL. This will be common, as when the JDBC driverManager is asked to connect to a given URL, it passes the URL to each loaded driver in turn.
 * 
 * <p>
 * The driver should raise an SQLException if the URL is null or if it is the right driver to connect to the given URL, but has trouble connecting to the
 * database.
 * </p>
 * 
 * <p>
 * The java.util.Properties argument can be used to pass arbitrary string tag/value pairs as connection arguments. These properties take precedence over any
 * properties sent in the URL.
 * </p>
 * 
 * <p>
 * MySQL protocol takes the form: jdbc:mysql://host:port/database
 * </p>
 * 
 * @param url
 *            the URL of the database to connect to
 * @param info
 *            a list of arbitrary tag/value pairs as connection arguments
 * 
 * @return a connection to the URL or null if it isn't us
 * 
 * @exception SQLException
 *                if a database access error occurs or the url is {@code null}
 */
@Override
public java.sql.Connection connect(String url, Properties info) throws SQLException {

    try {
        if (!ConnectionUrl.acceptsUrl(url)) {
            /*
             * According to JDBC spec:
             * The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. This will be common, as when the
             * JDBC driver manager is asked to connect to a given URL it passes the URL to each loaded driver in turn.
             */
            return null;
        }

        ConnectionUrl conStr = ConnectionUrl.getConnectionUrlInstance(url, info);
        switch (conStr.getType()) {
            case SINGLE_CONNECTION:
                return com.mysql.cj.jdbc.ConnectionImpl.getInstance(conStr.getMainHost());

            case LOADBALANCE_CONNECTION:
                return LoadBalancedConnectionProxy.createProxyInstance((LoadbalanceConnectionUrl) conStr);

            case FAILOVER_CONNECTION:
                return FailoverConnectionProxy.createProxyInstance(conStr);

            case REPLICATION_CONNECTION:
                return ReplicationConnectionProxy.createProxyInstance((ReplicationConnectionUrl) conStr);

            default:
                return null;
        }

    } catch (UnsupportedConnectionStringException e) {
        // when Connector/J can't handle this connection string the Driver must return null
        return null;

    } catch (CJException ex) {
        throw ExceptionFactory.createException(UnableToConnectException.class,
                Messages.getString("NonRegisteringDriver.17", new Object[] { ex.toString() }), ex);
    }
}
 
Example 6
/**
 * Static factory to create {@link ReplicationConnection} instances.
 * 
 * @param connectionUrl
 *            The connection URL containing the hosts in a replication setup.
 * @return A {@link ReplicationConnection} proxy.
 */
public static ReplicationConnection createProxyInstance(ReplicationConnectionUrl connectionUrl) throws SQLException {
    ReplicationConnectionProxy connProxy = new ReplicationConnectionProxy(connectionUrl);
    return (ReplicationConnection) java.lang.reflect.Proxy.newProxyInstance(ReplicationConnection.class.getClassLoader(),
            new Class<?>[] { ReplicationConnection.class, JdbcConnection.class }, connProxy);
}
 
Example 7
/**
 * Static factory to create {@link ReplicationConnection} instances.
 * 
 * @param connectionUrl
 *            The connection URL containing the hosts in a replication setup.
 * @return A {@link ReplicationConnection} proxy.
 * @throws SQLException
 *             if an error occurs
 */
public static ReplicationConnection createProxyInstance(ReplicationConnectionUrl connectionUrl) throws SQLException {
    ReplicationConnectionProxy connProxy = new ReplicationConnectionProxy(connectionUrl);
    return (ReplicationConnection) java.lang.reflect.Proxy.newProxyInstance(ReplicationConnection.class.getClassLoader(),
            new Class<?>[] { ReplicationConnection.class, JdbcConnection.class }, connProxy);
}