Skip to content

Commit

Permalink
[misc] acceptsURL with mariadb_<version> to permit performance test w…
Browse files Browse the repository at this point in the history
…ith multiple instance of driver in classpath.
  • Loading branch information
rusher committed Mar 11, 2016
1 parent 5ac170f commit b3e5557
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/main/java/org/mariadb/jdbc/UrlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.util.Options;
import org.mariadb.jdbc.internal.util.constant.ParameterConstant;
import org.mariadb.jdbc.internal.util.constant.HaMode;
import org.mariadb.jdbc.internal.util.constant.Version;

import java.sql.SQLException;
import java.util.List;
Expand Down Expand Up @@ -114,9 +115,16 @@ protected UrlParser(String database, List<HostAddress> addresses, Options option
}
}


/**
* Tell if mariadb driver accept url string.
* (Correspond to interface java.jdbc.Driver.acceptsURL() method)
* @param url url String
* @return true if url string correspond.
*/
public static boolean acceptsUrl(String url) {
return (url != null) && (url.startsWith("jdbc:mariadb:") || url.startsWith("jdbc:mysql:"));
return (url != null) && (url.startsWith("jdbc:mariadb:")
|| url.startsWith("jdbc:mysql:")
|| url.startsWith("jdbc:mariadb_" + Version.version + ":"));

}

Expand Down Expand Up @@ -146,6 +154,13 @@ public static UrlParser parse(final String url, Properties prop) throws SQLExcep
parseInternal(urlParser, "jdbc:mysql:" + url.substring(13), prop);
return urlParser;
}

//to permit having multiple maria db version in classpath and permit performance test
if (url.startsWith("jdbc:mariadb_" + Version.version + ":")) {
UrlParser urlParser = new UrlParser();
parseInternal(urlParser, "jdbc:mysql:" + url.substring(("jdbc:mariadb_" + Version.version + ":").length()), prop);
return urlParser;
}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void finishPacket() throws IOException {
if (buffer.capacity() > BUFFER_DEFAULT_SIZE) {
saveTemporaryBigBuffer = buffer;
buffer = firstBuffer;
} else if (saveTemporaryBigBuffer != null){
} else if (saveTemporaryBigBuffer != null) {
saveTemporaryBigBuffer = null;
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/mariadb/jdbc/JdbcParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.mariadb.jdbc.internal.util.constant.HaMode;
import org.mariadb.jdbc.internal.util.constant.Version;

import java.sql.SQLException;
import java.util.Properties;
Expand All @@ -13,7 +14,18 @@ public class JdbcParserTest {
public void testMariaAlias() throws Throwable {
UrlParser jdbc = UrlParser.parse("jdbc:mariadb://localhost/test");
UrlParser jdbc2 = UrlParser.parse("jdbc:mysql://localhost/test");
UrlParser jdbc3 = UrlParser.parse("jdbc:mariadb_" + Version.version + "://localhost/test");
Assert.assertEquals(jdbc, jdbc2);
Assert.assertEquals(jdbc, jdbc3);
}

@Test
public void testAcceptsUrl() throws Throwable {
Driver driver = new Driver();
Assert.assertTrue(driver.acceptsURL("jdbc:mariadb://localhost/test"));
Assert.assertTrue(driver.acceptsURL("jdbc:mysql://localhost/test"));
Assert.assertTrue(driver.acceptsURL("jdbc:mariadb_" + Version.version + "://localhost/test"));
Assert.assertFalse(driver.acceptsURL("jdbc:mariadb_1.3.6://localhost/test"));
}

@Test
Expand Down

0 comments on commit b3e5557

Please sign in to comment.