Skip to content
Browse files

[CONJ-622] The option connectTimeout takes in account DriverManager g…

…etLoginTimeout() va

(cherry picked from commit 803825e)
  • Loading branch information...
rusher committed Jun 27, 2018
1 parent 1043417 commit b4c4c4d17656b1656971f4b6b01f27a657c2b724
@@ -106,7 +106,7 @@ The following options are currently supported.
|=user|Database user name. \\//since 1.0.0//|
|=password|Password of database user.\\//since 1.0.0//|
|=rewriteBatchedStatements| For insert queries, rewrite batchedStatement to execute in a single executeQuery.\\example:\\{{{insert into ab (i) values (?)}}} with first batch values = 1, second = 2 will be rewritten\\{{{insert into ab (i) values (1), (2)}}}. \\\\If query cannot be rewriten in "multi-values", rewrite will use multi-queries : {{{INSERT INTO TABLE(col1) VALUES (?) ON DUPLICATE KEY UPDATE col2=?}}} with values [1,2] and [2,3]" will be rewritten\\{{{INSERT INTO TABLE(col1) VALUES (1) ON DUPLICATE KEY UPDATE col2=2;INSERT INTO TABLE(col1) VALUES (3) ON DUPLICATE KEY UPDATE col2=4}}}\\\\when active, the useServerPrepStmts option is set to false\\//Default: false. Since 1.1.8//|
|=connectTimeout| The connect timeout value, in milliseconds, or zero for no timeout.\\//Default: 0. Since 1.1.8//|
|=connectTimeout| The connect timeout value, in milliseconds.\\//Default: DriverManager.getLoginTimeout() value if set or 30s. Since 1.1.8//|
|=useServerPrepStmts|Queries are prepared on the server side before executing, permitting faster execution next time. \\if rewriteBatchedStatements is set to true, this option will be set to false.\\//Default: true. Since 1.3.0//|
|=useBatchMultiSend|*Not compatible with aurora* Driver will can send queries by batch. \\If disable, queries are send one by one, waiting for result before sending next one. \\If enable, queries will be send by batch corresponding to option useBatchMultiSendNumber value (default 100) or according to server variable @@max_allowed_packet if packet size cannot permit to send as many queries. Results will be read afterwhile, avoiding a lot of network latency when client and server aren't on same host. \\\\ There is 2 differents use case : JDBC executeBatch() and when option useServerPrepStmts is enable and MariaDB server >= 10.2.1, PREPARE commands will be delayed, to send PREPARE + EXECUTE in the same packet. This option if mainly effective when client is distant from server. [[./use-batch-multi-send-description.creole|more information]]\\//Default: true (false if using aurora failover). Since 1.5.0//|
@@ -53,6 +53,7 @@
package org.mariadb.jdbc.internal.util;

import java.lang.reflect.Field;
import java.sql.DriverManager;

public class Options implements Cloneable {
@@ -75,7 +76,7 @@
public boolean useFractionalSeconds = true;
public boolean pinGlobalTxToPhysicalConnection;
public String socketFactory;
public int connectTimeout = 30000;
public int connectTimeout = DriverManager.getLoginTimeout() > 0 ? DriverManager.getLoginTimeout() * 1000 : 30000;
public String pipe;
public String localSocket;
public String sharedMemory;
@@ -1,9 +1,11 @@
package org.mariadb.jdbc.internal.util;

import org.junit.Test;
import org.mariadb.jdbc.UrlParser;
import org.mariadb.jdbc.internal.util.constant.HaMode;

import java.lang.reflect.Field;
import java.sql.DriverManager;
import java.util.Properties;

import static org.junit.Assert.*;
@@ -26,6 +28,18 @@ public void parseDefault() throws Exception {

public void parseDefaultDriverManagerTimeout() throws Exception {
UrlParser parser = UrlParser.parse("jdbc:mariadb://localhost/");
assertEquals(parser.getOptions().connectTimeout, 2_000);


parser = UrlParser.parse("jdbc:mariadb://localhost/");
assertEquals(parser.getOptions().connectTimeout, 30_000);

* Ensure that default value of new Options() correspond to DefaultOption Enumeration.
* @throws Exception if any value differ.

0 comments on commit b4c4c4d

Please sign in to comment.
You can’t perform that action at this time.