Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-227] url alias mariadb correction when using failover parameter
  • Loading branch information
rusher committed Nov 30, 2015
1 parent 528fa17 commit 4a5b824
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/main/java/org/mariadb/jdbc/UrlParser.java
Expand Up @@ -143,7 +143,7 @@ public static UrlParser parse(final String url, Properties prop) throws SQLExcep
} else {
if (url.startsWith("jdbc:mariadb:")) {
UrlParser urlParser = new UrlParser();
parseInternal(urlParser, "jdbc:mysql:" + url.substring(12), prop);
parseInternal(urlParser, "jdbc:mysql:" + url.substring(13), prop);
return urlParser;
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ public void parseUrl(String url) throws SQLException {
String[] arr = new String[]{"jdbc:mysql:thin:", "jdbc:mariadb:"};
for (String prefix : arr) {
if (url.startsWith(prefix)) {
parseInternal(this, url, new Properties());
parseInternal(this, "jdbc:mysql:" + url.substring(prefix.length()), new Properties());
break;
}
}
Expand Down Expand Up @@ -299,4 +299,28 @@ public HaMode getHaMode() {
return haMode;
}

@Override
public boolean equals(Object parser) {
if (this == parser) {
return true;
}
if (!(parser instanceof UrlParser)) {
return false;
}

UrlParser urlParser = (UrlParser) parser;

if (getDatabase() != null ? !getDatabase().equals(urlParser.getDatabase()) : urlParser.getDatabase() != null) {
return false;
}
if (getOptions() != null ? !getOptions().equals(urlParser.getOptions()) : urlParser.getOptions() != null) {
return false;
}
if (addresses != null ? !addresses.equals(urlParser.addresses) : urlParser.addresses != null) {
return false;
}
return getHaMode() == urlParser.getHaMode();

}

}
159 changes: 159 additions & 0 deletions src/main/java/org/mariadb/jdbc/internal/util/Options.java
Expand Up @@ -156,4 +156,163 @@ public String toString() {
+ ", maximizeMysqlCompatibility=" + maximizeMysqlCompatibility
+ "}";
}


@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}

Options options = (Options) obj;

if (trustServerCertificate != options.trustServerCertificate) {
return false;
}
if (useFractionalSeconds != options.useFractionalSeconds) {
return false;
}
if (pinGlobalTxToPhysicalConnection != options.pinGlobalTxToPhysicalConnection) {
return false;
}
if (tcpNoDelay != options.tcpNoDelay) {
return false;
}
if (tcpKeepAlive != options.tcpKeepAlive) {
return false;
}
if (tcpAbortiveClose != options.tcpAbortiveClose) {
return false;
}
if (allowMultiQueries != options.allowMultiQueries) {
return false;
}
if (rewriteBatchedStatements != options.rewriteBatchedStatements) {
return false;
}
if (useCompression != options.useCompression) {
return false;
}
if (interactiveClient != options.interactiveClient) {
return false;
}
if (useSsl != options.useSsl) {
return false;
}
if (tinyInt1isBit != options.tinyInt1isBit) {
return false;
}
if (yearIsDateType != options.yearIsDateType) {
return false;
}
if (createDatabaseIfNotExist != options.createDatabaseIfNotExist) {
return false;
}
if (nullCatalogMeansCurrent != options.nullCatalogMeansCurrent) {
return false;
}
if (dumpQueriesOnException != options.dumpQueriesOnException) {
return false;
}
if (useOldAliasMetadataBehavior != options.useOldAliasMetadataBehavior) {
return false;
}
if (allowLocalInfile != options.allowLocalInfile) {
return false;
}
if (cachePrepStmts != options.cachePrepStmts) {
return false;
}
if (useLegacyDatetimeCode != options.useLegacyDatetimeCode) {
return false;
}
if (maximizeMysqlCompatibility != options.maximizeMysqlCompatibility) {
return false;
}
if (alwaysAutoGeneratedKeys != options.alwaysAutoGeneratedKeys) {
return false;
}
if (useServerPrepStmts != options.useServerPrepStmts) {
return false;
}
if (assureReadOnly != options.assureReadOnly) {
return false;
}
if (autoReconnect != options.autoReconnect) {
return false;
}
if (failOnReadOnly != options.failOnReadOnly) {
return false;
}
if (secondsBeforeRetryMaster != options.secondsBeforeRetryMaster) {
return false;
}
if (queriesBeforeRetryMaster != options.queriesBeforeRetryMaster) {
return false;
}
if (retriesAllDown != options.retriesAllDown) {
return false;
}
if (validConnectionTimeout != options.validConnectionTimeout) {
return false;
}
if (loadBalanceBlacklistTimeout != options.loadBalanceBlacklistTimeout) {
return false;
}
if (failoverLoopRetries != options.failoverLoopRetries) {
return false;
}
if (user != null ? !user.equals(options.user) : options.user != null) {
return false;
}
if (password != null ? !password.equals(options.password) : options.password != null) {
return false;
}
if (serverSslCert != null ? !serverSslCert.equals(options.serverSslCert) : options.serverSslCert != null) {
return false;
}
if (socketFactory != null ? !socketFactory.equals(options.socketFactory) : options.socketFactory != null) {
return false;
}
if (connectTimeout != null ? !connectTimeout.equals(options.connectTimeout) : options.connectTimeout != null) {
return false;
}
if (pipe != null ? !pipe.equals(options.pipe) : options.pipe != null) {
return false;
}
if (localSocket != null ? !localSocket.equals(options.localSocket) : options.localSocket != null) {
return false;
}
if (sharedMemory != null ? !sharedMemory.equals(options.sharedMemory) : options.sharedMemory != null) {
return false;
}
if (tcpRcvBuf != null ? !tcpRcvBuf.equals(options.tcpRcvBuf) : options.tcpRcvBuf != null) {
return false;
}
if (tcpSndBuf != null ? !tcpSndBuf.equals(options.tcpSndBuf) : options.tcpSndBuf != null) {
return false;
}
if (localSocketAddress != null ? !localSocketAddress.equals(options.localSocketAddress) : options.localSocketAddress != null) {
return false;
}
if (socketTimeout != null ? !socketTimeout.equals(options.socketTimeout) : options.socketTimeout != null) {
return false;
}
if (sessionVariables != null ? !sessionVariables.equals(options.sessionVariables) : options.sessionVariables != null) {
return false;
}
if (serverTimezone != null ? !serverTimezone.equals(options.serverTimezone) : options.serverTimezone != null) {
return false;
}
if (prepStmtCacheSize != null ? !prepStmtCacheSize.equals(options.prepStmtCacheSize) : options.prepStmtCacheSize != null) {
return false;
}
return !(prepStmtCacheSqlLimit != null ? !prepStmtCacheSqlLimit.equals(options.prepStmtCacheSqlLimit)
: options.prepStmtCacheSqlLimit != null);

}

}
25 changes: 25 additions & 0 deletions src/test/java/org/mariadb/jdbc/DriverTest.java
Expand Up @@ -4,11 +4,14 @@
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mariadb.jdbc.internal.util.DefaultOptions;
import org.mariadb.jdbc.internal.util.constant.HaMode;

import java.io.*;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
Expand Down Expand Up @@ -342,6 +345,28 @@ public void testConnectorJurl() throws SQLException {

}



@Test
public void testAliasReplication() throws SQLException {
UrlParser url = UrlParser.parse("jdbc:mysql:replication://localhost/test");
UrlParser url2 = UrlParser.parse("jdbc:mariadb:replication://localhost/test");
assertEquals(url, url2);
}

@Test
public void testAliasDataSource() throws SQLException {
ArrayList<HostAddress> hostAddresses = new ArrayList<>();
hostAddresses.add(new HostAddress(hostname, port));
UrlParser urlParser = new UrlParser(database, hostAddresses, DefaultOptions.defaultValues(HaMode.NONE), HaMode.NONE);
UrlParser urlParser2 = new UrlParser(database, hostAddresses, DefaultOptions.defaultValues(HaMode.NONE), HaMode.NONE);

urlParser.parseUrl("jdbc:mysql:replication://localhost/test");
urlParser2.parseUrl("jdbc:mariadb:replication://localhost/test");
assertEquals(urlParser, urlParser2);
}


@Test
public void testEscapes() throws SQLException {
String query = "select ?";
Expand Down

0 comments on commit 4a5b824

Please sign in to comment.