diff --git a/README.md b/README.md
index b9f500ac3..788dce744 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ or maven :
org.mariadb.jdbc
mariadb-java-client
- 1.2.2
+ 1.2.3
```
diff --git a/pom.xml b/pom.xml
index fef4de211..6c2465a5e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,39 +1,46 @@
+
4.0.0
org.mariadb.jdbc
mariadb-java-client
jar
mariadb-java-client
- 1.3.0-SNAPSHOT
+ 1.2.3
JDBC driver for MariaDB and MySQL
https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/
+
UTF-8
3.3.0
src/main/resources/Version.java.template
src/main/java/org/mariadb/jdbc/Version.java
+
LGPL-2.1
+
scm:git:git://github.com/MariaDB/mariadb-connector-j.git
https://github.com/MariaDB/mariadb-connector-j
scm:git:git@github.com:MariaDB/mariadb-connector-j.git
+
JIRA
https://mariadb.atlassian.net/browse/CONJ
+
ossrh
https://oss.sonatype.org/content/repositories/snapshots
+
wlad
@@ -56,6 +63,7 @@
diego.dupin@mariadb.com
+
test
@@ -67,7 +75,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 2.12.4
+ 2.18.1
-Xmx1g
@@ -134,13 +142,6 @@
-
org.apache.maven.plugins
maven-gpg-plugin
@@ -209,6 +210,31 @@
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.4
+
+
+
+ jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
org.codehaus.mojo
build-helper-maven-plugin
@@ -224,8 +250,8 @@
com.google.code.maven-replacer-plugin
- maven-replacer-plugin
- 1.4.1
+ replacer
+ 1.5.3
process-sources
@@ -285,6 +311,7 @@
org.slf4j
slf4j-api
1.7.12
+ test
net.java.dev.jna
@@ -317,6 +344,6 @@
org.sonatype.oss
oss-parent
- 6
+ 9
diff --git a/src/main/java/org/mariadb/jdbc/Driver.java b/src/main/java/org/mariadb/jdbc/Driver.java
index 9ec6b3547..c065e7824 100644
--- a/src/main/java/org/mariadb/jdbc/Driver.java
+++ b/src/main/java/org/mariadb/jdbc/Driver.java
@@ -53,10 +53,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.QueryException;
import org.mariadb.jdbc.internal.common.Utils;
import org.mariadb.jdbc.internal.mysql.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
@@ -68,7 +64,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
public final class Driver implements java.sql.Driver {
- private final static Logger log = LoggerFactory.getLogger(Driver.class);
static {
try {
@@ -89,13 +84,11 @@ public final class Driver implements java.sql.Driver {
*/
public Connection connect(final String url, final Properties props) throws SQLException {
- log.debug("Connecting to: " + url);
try {
JDBCUrl jdbcUrl = JDBCUrl.parse(url, props);
//
if (jdbcUrl == null) return null;
if (jdbcUrl.getHostAddresses() == null) {
- log.info("MariaDB connector : missing Host address");
return null;
} else {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
diff --git a/src/main/java/org/mariadb/jdbc/MySQLDataSource.java b/src/main/java/org/mariadb/jdbc/MySQLDataSource.java
index b264a5d57..a4b1c6773 100644
--- a/src/main/java/org/mariadb/jdbc/MySQLDataSource.java
+++ b/src/main/java/org/mariadb/jdbc/MySQLDataSource.java
@@ -56,7 +56,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.UrlHAMode;
import org.mariadb.jdbc.internal.common.Utils;
import org.mariadb.jdbc.internal.mysql.*;
-import org.slf4j.LoggerFactory;
import javax.sql.*;
@@ -72,7 +71,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
public class MySQLDataSource implements DataSource, ConnectionPoolDataSource, XADataSource {
- private final static org.slf4j.Logger log = LoggerFactory.getLogger(MySQLDataSource.class);
private final JDBCUrl jdbcUrl;
@@ -281,7 +279,6 @@ public Connection getConnection() throws SQLException {
public Connection getConnection(final String username, final String password) throws SQLException {
jdbcUrl.setUsername(username);
jdbcUrl.setPassword(password);
- if (log.isDebugEnabled()) log.debug("connection : " +jdbcUrl.toString());
return getConnection();
}
diff --git a/src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java b/src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java
index eefac0c17..481c69c38 100644
--- a/src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java
+++ b/src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java
@@ -52,8 +52,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.Utils;
import org.mariadb.jdbc.internal.common.query.*;
import org.mariadb.jdbc.internal.common.query.parameters.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -69,7 +67,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
public class MySQLPreparedStatement extends MySQLStatement implements PreparedStatement {
- private final static Logger log = LoggerFactory.getLogger(MySQLPreparedStatement.class);
private MySQLParameterizedQuery dQuery;
private String sql;
private boolean useFractionalSeconds;
@@ -82,9 +79,6 @@ public MySQLPreparedStatement(MySQLConnection connection,
this.sql = sql;
useFractionalSeconds =
connection.getProtocol().getOptions().useFractionalSeconds;
- if(log.isDebugEnabled()) {
- log.debug("Creating prepared statement for " + sql);
- }
isInsertRewriteable(sql);
dQuery = new MySQLParameterizedQuery(Utils.nativeSQL(sql, connection.noBackslashEscapes),
connection.noBackslashEscapes, isRewriteable?firstRewrite.length():-1);
diff --git a/src/main/java/org/mariadb/jdbc/Version.java b/src/main/java/org/mariadb/jdbc/Version.java
index d941c6df1..ff6066c53 100644
--- a/src/main/java/org/mariadb/jdbc/Version.java
+++ b/src/main/java/org/mariadb/jdbc/Version.java
@@ -1,10 +1,10 @@
package org.mariadb.jdbc;
public final class Version {
- public static final String version = "1.3.0-SNAPSHOT";
+ public static final String version = "1.2.3";
public static final int majorVersion = 1;
- public static final int minorVersion = 3;
- public static final int patchVersion = 0;
- public static final String qualifier = "SNAPSHOT";
+ public static final int minorVersion = 2;
+ public static final int patchVersion = 3;
+ public static final String qualifier = "";
}
\ No newline at end of file
diff --git a/src/main/java/org/mariadb/jdbc/internal/common/packet/PacketOutputStream.java b/src/main/java/org/mariadb/jdbc/internal/common/packet/PacketOutputStream.java
index da2128180..5030a34af 100644
--- a/src/main/java/org/mariadb/jdbc/internal/common/packet/PacketOutputStream.java
+++ b/src/main/java/org/mariadb/jdbc/internal/common/packet/PacketOutputStream.java
@@ -1,15 +1,11 @@
package org.mariadb.jdbc.internal.common.packet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class PacketOutputStream extends OutputStream {
- private final static Logger log = LoggerFactory.getLogger(PacketOutputStream.class);
private static final int MAX_PACKET_LENGTH = 0x00ffffff;
private static final int SEQNO_OFFSET = 3;
@@ -132,12 +128,6 @@ private void internalFlush() throws IOException {
throw new MaxAllowedPacketException("max_allowed_packet exceeded. wrote " + bytesWritten + ", max_allowed_packet = " +maxAllowedPacket, this.seqNo != 0);
}
baseStream.write(byteBuffer, 0, position);
- if (log.isTraceEnabled()) {
- byte[] tmp = new byte[Math.min(1000, position)];
- System.arraycopy(byteBuffer, 0, tmp, 0, Math.min(1000, position));
- log.trace(new String(tmp));
- }
-
position = HEADER_LENGTH;
this.seqNo++;
}
diff --git a/src/main/java/org/mariadb/jdbc/internal/common/packet/commands/StreamedQueryPacket.java b/src/main/java/org/mariadb/jdbc/internal/common/packet/commands/StreamedQueryPacket.java
index fbafb01e3..afecd7bbf 100644
--- a/src/main/java/org/mariadb/jdbc/internal/common/packet/commands/StreamedQueryPacket.java
+++ b/src/main/java/org/mariadb/jdbc/internal/common/packet/commands/StreamedQueryPacket.java
@@ -73,31 +73,29 @@ public StreamedQueryPacket(final List queries, boolean isRewritable, int
}
public int send(final OutputStream ostream) throws IOException, QueryException {
+ PacketOutputStream pos = (PacketOutputStream) ostream;
+ pos.startPacket(0);
+ pos.write(0x03);
+
if (queries.size() == 1) {
- PacketOutputStream pos = (PacketOutputStream)ostream;
- pos.startPacket(0);
- pos.write(0x03);
queries.get(0).writeTo(ostream);
- pos.finishPacket();
} else {
- PacketOutputStream pos = (PacketOutputStream)ostream;
- pos.startPacket(0);
- pos.write(0x03);
if (!isRewritable) {
queries.get(0).writeTo(ostream);
- for (int i=1;i queryParts = createQueryParts(query, noBackslashEscapes);
- if (rewriteOffset != -1) {
- try {
+ try {
+ this.query = query;
+ List queryParts = createQueryParts(query, noBackslashEscapes);
+ if (rewriteOffset != -1) {
rewriteFirstPart = queryParts.get(0).substring(rewriteOffset + 1).getBytes("UTF-8");
- String lastPart = queryParts.get(queryParts.size() - 1 );
- rewriteRepeatLastPart = lastPart.substring(0, lastPart.indexOf(")")).getBytes("UTF-8");
- rewriteNotRepeatLastPart = lastPart.substring(lastPart.indexOf(")") + 1 ).getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException("UTF-8 not supported", e);
+ String lastPart = queryParts.get(queryParts.size() - 1);
+ if (lastPart.indexOf(")") != -1) {
+ rewriteRepeatLastPart = lastPart.substring(0, lastPart.indexOf(")")).getBytes("UTF-8");
+ rewriteNotRepeatLastPart = lastPart.substring(lastPart.indexOf(")") + 1).getBytes("UTF-8");
+ } else {
+ rewriteRepeatLastPart = lastPart.getBytes("UTF-8");
+ rewriteNotRepeatLastPart = new byte[0];
+ }
}
- }
- queryPartsArray = new byte[queryParts.size()][];
- for(int i=0;i < queryParts.size(); i++) {
- try {
+ queryPartsArray = new byte[queryParts.size()][];
+ for (int i = 0; i < queryParts.size(); i++) {
queryPartsArray[i] = queryParts.get(i).getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException("UTF-8 not supported", e);
}
- }
- paramCount = queryParts.size() - 1;
- parameters = new ParameterHolder[paramCount];
+ paramCount = queryParts.size() - 1;
+ parameters = new ParameterHolder[paramCount];
+ } catch (UnsupportedEncodingException u) {}
}
- private MySQLParameterizedQuery() {
+ private MySQLParameterizedQuery() {
}
+
public MySQLParameterizedQuery cloneQuery() {
- MySQLParameterizedQuery q = new MySQLParameterizedQuery();
+ MySQLParameterizedQuery q = new MySQLParameterizedQuery();
q.parameters = new ParameterHolder[parameters.length];
- for (int i = 0; i < parameters.length;i++) {
+ for (int i = 0; i < parameters.length; i++) {
q.parameters[i] = parameters[i];
}
q.paramCount = paramCount;
@@ -132,31 +131,31 @@ public void clearParameters() {
this.parameters = new ParameterHolder[paramCount];
}
- public void validate() throws QueryException{
- if(containsNull(parameters)) {
+ public void validate() throws QueryException {
+ if (containsNull(parameters)) {
throw new QueryException("You need to set exactly " + paramCount + " parameters on the prepared statement");
}
}
public void writeTo(final OutputStream os) throws IOException, QueryException {
- if(queryPartsArray.length == 0) {
+ if (queryPartsArray.length == 0) {
throw new AssertionError("Invalid query, queryParts was empty");
}
os.write(queryPartsArray[0]);
- for(int i = 1; i 0) {
sb.append(", parameters : [");
- for(int i = 0; i < parameters.length; i++) {
- if (parameters[i] == null) {
+ for (int i = 0; i < parameters.length; i++) {
+ if (parameters[i] == null) {
sb.append("null");
- } else {
+ } else {
sb.append(parameters[i].toString());
}
- if (i != parameters.length -1) {
+ if (i != parameters.length - 1) {
sb.append(",");
}
}
@@ -231,7 +230,4 @@ public String toString() {
}
-
-
-
}
\ No newline at end of file
diff --git a/src/main/java/org/mariadb/jdbc/internal/common/query/MySQLQuery.java b/src/main/java/org/mariadb/jdbc/internal/common/query/MySQLQuery.java
index 11e399638..b5e45e9d9 100644
--- a/src/main/java/org/mariadb/jdbc/internal/common/query/MySQLQuery.java
+++ b/src/main/java/org/mariadb/jdbc/internal/common/query/MySQLQuery.java
@@ -48,11 +48,13 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
*/
package org.mariadb.jdbc.internal.common.query;
-import org.mariadb.jdbc.internal.common.QueryException;
+
+import org.mariadb.jdbc.internal.common.QueryException;
+
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
-
+import java.nio.charset.StandardCharsets;
public class MySQLQuery implements Query {
@@ -65,7 +67,7 @@ public MySQLQuery(final String query) {
public void writeTo(final OutputStream os) throws IOException {
try {
- byte[] queryToSend = query.getBytes("UTF-8");
+ byte[] queryToSend = query.getBytes("UTF-8");
os.write(queryToSend, 0, queryToSend.length);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unsupported encoding: " + e.getMessage(), e);
@@ -76,7 +78,8 @@ public void writeFirstRewritePart(final OutputStream os) throws IOException, Que
writeTo(os);
}
- public void writeLastRewritePart(final OutputStream os) throws IOException, QueryException { }
+ public void writeLastRewritePart(final OutputStream os) throws IOException, QueryException {
+ }
public void writeToRewritablePart(final OutputStream os, int rewriteOffset) throws IOException, QueryException {
@@ -104,7 +107,7 @@ public boolean equals(final Object otherObj) {
public void writeTo(OutputStream ostream, int offset, int packLength) throws IOException {
try {
- byte[] queryToSend = query.getBytes("UTF-8");
+ byte[] queryToSend = query.getBytes("UTF-8");
ostream.write(queryToSend, offset, packLength);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unsupported encoding: " + e.getMessage(), e);
@@ -112,7 +115,7 @@ public void writeTo(OutputStream ostream, int offset, int packLength) throws IOE
}
- public void validate() throws QueryException{
+ public void validate() throws QueryException {
}
diff --git a/src/main/java/org/mariadb/jdbc/internal/mysql/AuroraProtocol.java b/src/main/java/org/mariadb/jdbc/internal/mysql/AuroraProtocol.java
index 193c97d79..de6c4eaf3 100644
--- a/src/main/java/org/mariadb/jdbc/internal/mysql/AuroraProtocol.java
+++ b/src/main/java/org/mariadb/jdbc/internal/mysql/AuroraProtocol.java
@@ -57,16 +57,12 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.queryresults.SelectQueryResult;
import org.mariadb.jdbc.internal.mysql.listener.impl.AuroraListener;
import org.mariadb.jdbc.internal.mysql.listener.tools.SearchFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class AuroraProtocol extends MastersSlavesProtocol {
- private final static Logger log = LoggerFactory.getLogger(AuroraProtocol.class);
-
public AuroraProtocol(final JDBCUrl url, final ReentrantReadWriteLock lock) {
super(url, lock);
}
@@ -97,7 +93,6 @@ public boolean checkIfMaster() throws QueryException {
return this.masterConnection;
} catch (IOException ioe) {
- log.trace("exception during checking if master", ioe);
throw new QueryException("could not check the 'innodb_read_only' variable status on " + this.getHostAddress() +
" : " + ioe.getMessage(), -1, SQLExceptionMapper.SQLStates.CONNECTION_EXCEPTION.getSqlState(), ioe);
} finally {
@@ -107,16 +102,11 @@ public boolean checkIfMaster() throws QueryException {
public static void searchProbableMaster(AuroraListener listener, HostAddress probableMaster, Map blacklist, SearchFilter searchFilter) throws QueryException {
- if (log.isDebugEnabled()) {
- log.debug("searching for master:" + searchFilter.isSearchForMaster() + " replica:" + searchFilter.isSearchForSlave() + " address:" + probableMaster + " blacklist:" + blacklist.keySet());
- }
AuroraProtocol protocol = getNewProtocol(listener.getProxy(), listener.getJdbcUrl());
try {
protocol.setHostAddress(probableMaster);
- if (log.isTraceEnabled()) log.trace("trying to connect to " + protocol.getHostAddress());
protocol.connect();
- if (log.isTraceEnabled()) log.trace("connected to " + protocol.getHostAddress());
if (searchFilter.isSearchForMaster() && protocol.isMasterConnection()) {
searchFilter.setSearchForMaster(false);
@@ -127,16 +117,12 @@ public static void searchProbableMaster(AuroraListener listener, HostAddress pro
protocol.setMustBeMasterConnection(false);
listener.foundActiveSecondary(protocol);
} else {
- if (log.isDebugEnabled())
- log.debug("close connection because unused : " + protocol.getHostAddress());
protocol.close();
protocol = getNewProtocol(listener.getProxy(), listener.getJdbcUrl());
}
} catch (QueryException e) {
blacklist.put(protocol.getHostAddress(), System.currentTimeMillis());
- if (log.isDebugEnabled())
- log.debug("Could not connect to " + protocol.currentHost + " searching for master : " + searchFilter.isSearchForMaster() + " for replica :" + searchFilter.isSearchForSlave() + " error:" + e.getMessage());
}
}
@@ -150,10 +136,6 @@ public static void searchProbableMaster(AuroraListener listener, HostAddress pro
* @throws QueryException if not found
*/
public static void loop(AuroraListener listener, final List addresses, Map blacklist, SearchFilter searchFilter) throws QueryException {
- if (log.isDebugEnabled()) {
- log.debug("searching for master:" + searchFilter.isSearchForMaster() + " replica:" + searchFilter.isSearchForSlave() + " addresses:" + addresses);
- }
-
AuroraProtocol protocol;
List loopAddresses = new LinkedList<>(addresses);
int maxConnectionTry = listener.getRetriesAllDown();
@@ -169,10 +151,8 @@ public static void loop(AuroraListener listener, final List address
protocol.setHostAddress(loopAddresses.get(0));
loopAddresses.remove(0);
- if (log.isDebugEnabled()) log.debug("trying to connect to " + protocol.getHostAddress());
protocol.connect();
blacklist.remove(protocol.getHostAddress());
- if (log.isDebugEnabled()) log.debug("connected to " + (protocol.isMasterConnection()?"primary ":"replica ") + protocol.getHostAddress());
if (searchFilter.isSearchForMaster() && protocol.isMasterConnection()) {
if (foundMaster(listener, protocol, searchFilter)) return;
@@ -191,7 +171,6 @@ public static void loop(AuroraListener listener, final List address
} catch (QueryException e) {
lastQueryException = e;
blacklist.put(protocol.getHostAddress(), System.currentTimeMillis());
- if (log.isDebugEnabled()) log.debug("Could not connect to " + protocol.getHostAddress() + " searching: " + searchFilter + " error: " + e.getMessage());
}
if (!searchFilter.isSearchForMaster() && !searchFilter.isSearchForSlave()) return;
diff --git a/src/main/java/org/mariadb/jdbc/internal/mysql/FailoverProxy.java b/src/main/java/org/mariadb/jdbc/internal/mysql/FailoverProxy.java
index 3db13ee0c..948269253 100644
--- a/src/main/java/org/mariadb/jdbc/internal/mysql/FailoverProxy.java
+++ b/src/main/java/org/mariadb/jdbc/internal/mysql/FailoverProxy.java
@@ -52,8 +52,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.SQLExceptionMapper;
import org.mariadb.jdbc.internal.common.QueryException;
import org.mariadb.jdbc.internal.mysql.listener.Listener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
@@ -63,7 +61,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
public class FailoverProxy implements InvocationHandler {
- private final static Logger log = LoggerFactory.getLogger(FailoverProxy.class);
public final static String METHOD_IS_EXPLICIT_CLOSED = "isExplicitClosed";
public final static String METHOD_GET_OPTIONS = "getOptions";
diff --git a/src/main/java/org/mariadb/jdbc/internal/mysql/MastersSlavesProtocol.java b/src/main/java/org/mariadb/jdbc/internal/mysql/MastersSlavesProtocol.java
index 11aa1925a..eb43acffd 100644
--- a/src/main/java/org/mariadb/jdbc/internal/mysql/MastersSlavesProtocol.java
+++ b/src/main/java/org/mariadb/jdbc/internal/mysql/MastersSlavesProtocol.java
@@ -54,15 +54,11 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.QueryException;
import org.mariadb.jdbc.internal.mysql.listener.impl.MastersSlavesListener;
import org.mariadb.jdbc.internal.mysql.listener.tools.SearchFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class MastersSlavesProtocol extends MySQLProtocol {
-
- private final static Logger log = LoggerFactory.getLogger(MastersSlavesProtocol.class);
boolean masterConnection = false;
boolean mustBeMasterConnection = false;
@@ -81,9 +77,6 @@ public MastersSlavesProtocol(final JDBCUrl url, final ReentrantReadWriteLock loc
* @throws QueryException if not found
*/
public static void loop(MastersSlavesListener listener, final List addresses, Map blacklist, SearchFilter searchFilter) throws QueryException {
- if (log.isDebugEnabled()) {
- log.debug("searching for master:" + searchFilter.isSearchForMaster() + " replica:" + searchFilter.isSearchForSlave() + " addresses:" + addresses);
- }
MastersSlavesProtocol protocol;
List loopAddresses = new LinkedList<>(addresses);
@@ -100,11 +93,8 @@ public static void loop(MastersSlavesListener listener, final List
protocol.setHostAddress(loopAddresses.get(0));
loopAddresses.remove(0);
- if (log.isDebugEnabled()) log.debug("trying to connect to " + protocol.getHostAddress());
-
protocol.connect();
blacklist.remove(protocol.getHostAddress());
- if (log.isDebugEnabled()) log.debug("connected to " + (protocol.isMasterConnection()?"primary ":"replica ") + protocol.getHostAddress());
if (searchFilter.isSearchForMaster() && protocol.isMasterConnection()) {
if (foundMaster(listener, protocol, searchFilter)) return;
@@ -117,7 +107,6 @@ public static void loop(MastersSlavesListener listener, final List
} catch (QueryException e) {
lastQueryException = e;
blacklist.put(protocol.getHostAddress(), System.currentTimeMillis());
- if (log.isDebugEnabled()) log.debug("Could not connect to " + protocol.getHostAddress() + " searching: " + searchFilter + " error: " + e.getMessage());
}
if (!searchFilter.isSearchForMaster() && !searchFilter.isSearchForSlave()) return;
diff --git a/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java b/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java
index faa93aa13..5f48636fc 100644
--- a/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java
+++ b/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java
@@ -68,8 +68,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.mysql.listener.tools.SearchFilter;
import org.mariadb.jdbc.internal.mysql.packet.MySQLGreetingReadPacket;
import org.mariadb.jdbc.internal.mysql.packet.commands.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import javax.net.SocketFactory;
import javax.net.ssl.*;
@@ -155,7 +153,6 @@ public X509Certificate[] getAcceptedIssuers() {
public class MySQLProtocol implements Protocol {
- private final static Logger log = LoggerFactory.getLogger(MySQLProtocol.class);
protected final ReentrantReadWriteLock lock;
private boolean connected = false;
private boolean explicitClosed = false;
@@ -236,7 +233,6 @@ private void connect(String host, int port) throws QueryException, IOException{
try {
socketFactory = (SocketFactory) (Class.forName(socketFactoryName).newInstance());
} catch (Exception sfex){
- log.debug("Failed to create socket factory " + socketFactoryName);
socketFactory = SocketFactory.getDefault();
}
} else {
@@ -271,7 +267,6 @@ private void connect(String host, int port) throws QueryException, IOException{
if (jdbcUrl.getOptions().tcpSndBuf != null) socket.setSendBufferSize(jdbcUrl.getOptions().tcpSndBuf);
if (jdbcUrl.getOptions().tcpAbortiveClose) socket.setSoLinger(true, 0);
} catch (Exception e) {
- if (log.isDebugEnabled())log.debug("Failed to set socket option: " + e.getLocalizedMessage());
}
// Bind the socket to a particular interface if the connection property
@@ -647,10 +642,6 @@ public boolean shouldReconnectWithoutProxy() {
* @throws QueryException if not found
*/
public static void loop(Listener listener, final List addresses, Map blacklist, SearchFilter searchFilter) throws QueryException {
- if (log.isDebugEnabled()) {
- log.debug("searching for master:" + searchFilter.isSearchForMaster() + " replica:" + searchFilter.isSearchForSlave() + " addresses:" + addresses);
- }
-
MySQLProtocol protocol;
List loopAddresses = new LinkedList<>(addresses);
int maxConnectionTry = listener.getRetriesAllDown();
@@ -665,16 +656,13 @@ public static void loop(Listener listener, final List addresses, Ma
protocol.setHostAddress(loopAddresses.get(0));
loopAddresses.remove(0);
- if (log.isDebugEnabled()) log.debug("trying to connect to " + protocol.getHostAddress());
protocol.connect();
blacklist.remove(protocol.getHostAddress());
- if (log.isDebugEnabled()) log.debug("connected to primary " + protocol.getHostAddress());
listener.foundActiveMaster(protocol);
return;
} catch (QueryException e) {
blacklist.put(protocol.getHostAddress(), System.currentTimeMillis());
- if (log.isDebugEnabled()) log.debug("Could not connect to " + protocol.getHostAddress() + " searching: " + searchFilter + " error: " + e.getMessage());
lastQueryException = e;
}
@@ -749,7 +737,6 @@ protected static void close(PacketFetcher fetcher, PacketOutputStream packetOutp
try {
socket.close();
} catch (IOException e) {
- log.warn("Could not close socket");
}
}
}
@@ -773,11 +760,9 @@ public void close() {
/* eat exception */
}
try {
- if (log.isTraceEnabled()) log.trace("Closing connection " + currentHost);
close(packetFetcher, writer, socket);
} catch (Exception e) {
// socket is closed, so it is ok to ignore exception
- log.debug("got exception " + e + " while closing connection");
} finally {
this.connected = false;
@@ -823,7 +808,6 @@ private SelectQueryResult createQueryResult(final ResultSetPacket packet, boolea
@Override
public void setCatalog(final String database) throws QueryException {
lock.writeLock().lock();
- if (log.isTraceEnabled()) log.trace("Selecting db " + database);
final SelectDBPacket packet = new SelectDBPacket(database);
try {
packet.send(writer);
@@ -905,7 +889,6 @@ public boolean ping() throws QueryException {
final MySQLPingPacket pingPacket = new MySQLPingPacket();
try {
pingPacket.send(writer);
- if (log.isTraceEnabled())log.trace("Sent ping packet");
final RawPacket rawPacket = packetFetcher.getRawPacket();
return ResultPacketFactory.createResultPacket(rawPacket).getResultType() == ResultPacket.ResultType.OK;
} catch (IOException e) {
@@ -947,7 +930,6 @@ public QueryResult getResult(List dQueries, boolean streaming) throws Que
SQLExceptionMapper.SQLStates.FEATURE_NOT_SUPPORTED.getSqlState());
}
LocalInfilePacket localInfilePacket = (LocalInfilePacket) resultPacket;
- if (log.isTraceEnabled()) log.trace("sending local file " + localInfilePacket.getFileName());
String localInfile = localInfilePacket.getFileName();
try {
@@ -984,11 +966,6 @@ public QueryResult getResult(List dQueries, boolean streaming) throws Que
this.moreResults = false;
this.hasWarnings = false;
ErrorPacket ep = (ErrorPacket) resultPacket;
- if (dQueries != null && dQueries.size() == 1) {
- log.warn("Could not execute query " + dQueries.get(0) + ": " + ((ErrorPacket) resultPacket).getMessage());
- } else {
- log.warn("Got error from server: " + ((ErrorPacket) resultPacket).getMessage());
- }
throw new QueryException(ep.getMessage(), ep.getErrorNumber(), ep.getSqlState());
case OK:
@@ -1000,7 +977,6 @@ public QueryResult getResult(List dQueries, boolean streaming) throws Que
okpacket.getWarnings(),
okpacket.getMessage(),
okpacket.getInsertId());
- if (log.isTraceEnabled()) log.trace("OK, " + okpacket.getAffectedRows());
return updateResult;
case RESULTSET:
this.hasWarnings = false;
@@ -1015,7 +991,6 @@ public QueryResult getResult(List dQueries, boolean streaming) throws Que
e);
}
default:
- log.error("Could not parse result..." + resultPacket.getResultType());
throw new QueryException("Could not parse result", (short) -1, SQLExceptionMapper.SQLStates.INTERRUPTED_EXCEPTION.getSqlState());
}
diff --git a/src/main/java/org/mariadb/jdbc/internal/mysql/listener/AbstractMastersListener.java b/src/main/java/org/mariadb/jdbc/internal/mysql/listener/AbstractMastersListener.java
index 56ace7b5d..64bd1054f 100644
--- a/src/main/java/org/mariadb/jdbc/internal/mysql/listener/AbstractMastersListener.java
+++ b/src/main/java/org/mariadb/jdbc/internal/mysql/listener/AbstractMastersListener.java
@@ -59,8 +59,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.mysql.HandleErrorResult;
import org.mariadb.jdbc.internal.mysql.Protocol;
import org.mariadb.jdbc.internal.mysql.listener.tools.SearchFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -76,7 +74,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
public abstract class AbstractMastersListener implements Listener {
- private final static Logger log = LoggerFactory.getLogger(AbstractMastersListener.class);
/* =========================== Failover variables ========================================= */
public final JDBCUrl jdbcUrl;
@@ -119,7 +116,6 @@ public Map getBlacklist() {
public HandleErrorResult handleFailover(Method method, Object[] args) throws Throwable {
if (explicitClosed) throw new QueryException("Connection has been closed !");
if (setMasterHostFail()) {
- log.warn("SQL Primary node [" + this.currentProtocol.getHostAddress().toString() + "] connection fail ");
addToBlacklist(currentProtocol.getHostAddress());
}
return primaryFail(method, args);
@@ -131,7 +127,6 @@ public HandleErrorResult handleFailover(Method method, Object[] args) throws Thr
*/
public void addToBlacklist(HostAddress hostAddress) {
if (hostAddress != null) {
- if (log.isTraceEnabled())log.trace("host " + hostAddress+" added to blacklist");
blacklist.put(hostAddress, System.currentTimeMillis());
}
}
@@ -144,7 +139,6 @@ public void resetOldsBlackListHosts() {
Set currentBlackListkeys = new HashSet(blacklist.keySet());
for (HostAddress blackListHost : currentBlackListkeys) {
if (blacklist.get(blackListHost) < currentTime - jdbcUrl.getOptions().loadBalanceBlacklistTimeout * 1000) {
- if (log.isTraceEnabled()) log.trace("host " + blackListHost+" remove of blacklist");
blacklist.remove(blackListHost);
}
}
@@ -160,13 +154,11 @@ protected void resetMasterFailoverData() {
protected class FailLoop implements Runnable {
Listener listener;
public FailLoop(Listener listener) {
- log.trace("launched FailLoop");
this.listener = listener;
}
public void run() {
if (hasHostFail()) {
- if (log.isTraceEnabled()) log.trace("failLoop , listener.shouldReconnect() : "+listener.shouldReconnect());
if (listener.shouldReconnect()) {
try {
if (currentConnectionAttempts.get() >= jdbcUrl.getOptions().failoverLoopRetries)
@@ -177,18 +169,15 @@ public void run() {
//reconnection done !
stopFailover();
} catch (Exception e) {
- log.trace("FailLoop search connection failed", e);
}
} else {
if (currentConnectionAttempts.get() > jdbcUrl.getOptions().retriesAllDown) {
- if (log.isDebugEnabled()) log.debug("stopping failover after too many attemps ("+currentConnectionAttempts+")");
stopFailover();
}
}
} else {
stopFailover();
}
- log.trace("end launched FailLoop");
}
}
@@ -200,7 +189,6 @@ protected void setSessionReadOnly(boolean readOnly) throws QueryException {
protected void stopFailover() {
if (isLooping.compareAndSet(true, false)) {
- log.trace("stopping failover");
if (scheduledFailover!=null)scheduledFailover.cancel(false);
}
}
diff --git a/src/main/java/org/mariadb/jdbc/internal/mysql/listener/AbstractMastersSlavesListener.java b/src/main/java/org/mariadb/jdbc/internal/mysql/listener/AbstractMastersSlavesListener.java
index ca1588cfe..b16215285 100644
--- a/src/main/java/org/mariadb/jdbc/internal/mysql/listener/AbstractMastersSlavesListener.java
+++ b/src/main/java/org/mariadb/jdbc/internal/mysql/listener/AbstractMastersSlavesListener.java
@@ -55,8 +55,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.mysql.HandleErrorResult;
import org.mariadb.jdbc.internal.mysql.Protocol;
import org.mariadb.jdbc.internal.mysql.listener.tools.SearchFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -65,7 +63,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
public abstract class AbstractMastersSlavesListener extends AbstractMastersListener {
- private final static Logger log = LoggerFactory.getLogger(AbstractMastersSlavesListener.class);
/* =========================== Failover variables ========================================= */
private AtomicLong secondaryHostFailTimestamp = new AtomicLong();
@@ -81,14 +78,12 @@ public HandleErrorResult handleFailover(Method method, Object[] args) throws Thr
if (explicitClosed) throw new QueryException("Connection has been closed !");
if (currentProtocol.mustBeMasterConnection()) {
if (setMasterHostFail()) {
- log.warn("SQL Primary node [" + this.currentProtocol.getHostAddress().toString() + "] connection fail ");
addToBlacklist(currentProtocol.getHostAddress());
if (FailoverProxy.METHOD_EXECUTE_QUERY.equals(method.getName())) queriesSinceFailover.incrementAndGet();
}
return primaryFail(method, args);
} else {
if (setSecondaryHostFail()) {
- log.warn("SQL Secondary node [" + this.currentProtocol.getHostAddress().toString() + "] connection fail ");
addToBlacklist(currentProtocol.getHostAddress());
if (FailoverProxy.METHOD_EXECUTE_QUERY.equals(method.getName())) queriesSinceFailover.incrementAndGet();
}
diff --git a/src/main/java/org/mariadb/jdbc/internal/mysql/listener/impl/AuroraListener.java b/src/main/java/org/mariadb/jdbc/internal/mysql/listener/impl/AuroraListener.java
index 157846bb0..68a87e167 100644
--- a/src/main/java/org/mariadb/jdbc/internal/mysql/listener/impl/AuroraListener.java
+++ b/src/main/java/org/mariadb/jdbc/internal/mysql/listener/impl/AuroraListener.java
@@ -56,8 +56,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.queryresults.SelectQueryResult;
import org.mariadb.jdbc.internal.mysql.*;
import org.mariadb.jdbc.internal.mysql.listener.tools.SearchFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Collections;
@@ -66,8 +64,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import java.util.concurrent.TimeUnit;
public class AuroraListener extends MastersSlavesListener {
- private final static Logger log = LoggerFactory.getLogger(AuroraListener.class);
-
public AuroraListener(JDBCUrl jdbcUrl) {
super(jdbcUrl);
@@ -83,7 +79,6 @@ public void initializeConnection() throws QueryException {
try {
reconnectFailedConnection(new SearchFilter(true, true, true));
} catch (QueryException e) {
- log.debug("initializeConnection failed", e);
checkInitialConnection();
throw e;
}
@@ -99,7 +94,6 @@ public void initializeConnection() throws QueryException {
*/
@Override
public void reconnectFailedConnection(SearchFilter searchFilter) throws QueryException {
- if (log.isTraceEnabled()) log.trace("search connection searchFilter=" + searchFilter);
currentConnectionAttempts.incrementAndGet();
resetOldsBlackListHosts();
@@ -126,13 +120,12 @@ public void reconnectFailedConnection(SearchFilter searchFilter) throws QueryExc
//loopAddress.add(secondaryProtocol.getHostAddress());
}
if (isMasterHostFail()) {
- log.debug("searching probableMaster");
HostAddress probableMaster = searchByStartName(secondaryProtocol, loopAddress);
if (probableMaster != null) {
loopAddress.remove(probableMaster);
loopAddress.add(0, probableMaster);
- } else if (log.isTraceEnabled()) log.trace("probableMaster not found");
+ }
}
}
@@ -163,17 +156,14 @@ public HostAddress searchByStartName(Protocol secondaryProtocol, List 0) {
- log.debug("new primary node [" + newMasterProtocol.getHostAddress().toString() + "] connection established after " + (System.currentTimeMillis() - getMasterHostFailTimestamp()));
- } else
- log.debug("new primary node [" + newMasterProtocol.getHostAddress().toString() + "] connection established");
- }
resetMasterFailoverData();
if (!isSecondaryHostFail()) stopFailover();
} finally {
@@ -281,26 +265,16 @@ public void foundActiveSecondary(Protocol newSecondaryProtocol) {
try {
if (secondaryProtocol != null && !secondaryProtocol.isClosed()) secondaryProtocol.close();
- log.trace("found active secondary connection");
this.secondaryProtocol = newSecondaryProtocol;
//if asked to be on read only connection, switching to this new connection
if (currentReadOnlyAsked.get() || (jdbcUrl.getOptions().failOnReadOnly && !currentReadOnlyAsked.get() && isMasterHostFail())) {
try {
syncConnection(currentProtocol, this.secondaryProtocol);
- } catch (Exception e) {
- log.debug("Some error append during connection parameter synchronisation : ", e);
- }
+ } catch (Exception e) { }
currentProtocol = this.secondaryProtocol;
}
- if (log.isDebugEnabled()) {
- if (getSecondaryHostFailTimestamp() > 0) {
- log.debug("new active secondary node [" + newSecondaryProtocol.getHostAddress().toString() + "] connection established after " + (System.currentTimeMillis() - getSecondaryHostFailTimestamp()));
- } else
- log.debug("new active secondary node [" + newSecondaryProtocol.getHostAddress().toString() + "] connection established");
-
- }
resetSecondaryFailoverData();
if (!isMasterHostFail()) stopFailover();
} finally {
@@ -316,7 +290,6 @@ public void foundActiveSecondary(Protocol newSecondaryProtocol) {
*/
@Override
public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryException {
- if (log.isTraceEnabled()) log.trace("switching to mustBeReadOnly = " + mustBeReadOnly + " mode");
if (mustBeReadOnly != currentReadOnlyAsked.get() && currentProtocol.inTransaction()) {
throw new QueryException("Trying to set to read-only mode during a transaction");
@@ -328,16 +301,10 @@ public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryExcepti
if (!isSecondaryHostFail()) {
proxy.lock.writeLock().lock();
try {
-
- log.trace("switching to secondary connection");
syncConnection(this.masterProtocol, this.secondaryProtocol);
-
currentProtocol = this.secondaryProtocol;
-
- log.trace("current connection is now secondary");
return;
} catch (QueryException e) {
- log.trace("switching to secondary connection failed", e);
if (setSecondaryHostFail()) {
addToBlacklist(secondaryProtocol.getHostAddress());
}
@@ -355,15 +322,10 @@ public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryExcepti
proxy.lock.writeLock().lock();
try {
- log.trace("switching to master connection");
-
syncConnection(this.secondaryProtocol, this.masterProtocol);
currentProtocol = this.masterProtocol;
-
- log.debug("current connection is now master");
return;
} catch (QueryException e) {
- log.debug("switching to master connection failed", e);
if (setMasterHostFail()) {
addToBlacklist(masterProtocol.getHostAddress());
}
@@ -374,7 +336,6 @@ public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryExcepti
if (jdbcUrl.getOptions().autoReconnect) {
reconnectFailedConnection(new SearchFilter(false, true, false, true));
//connection established, no need to send Exception !
- log.trace("switching to master connection");
proxy.lock.writeLock().lock();
try {
syncConnection(this.secondaryProtocol, this.masterProtocol);
@@ -382,7 +343,6 @@ public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryExcepti
} finally {
proxy.lock.writeLock().unlock();
}
- log.debug("current connection is now master");
return;
}
launchFailLoopIfNotlaunched(false);
@@ -406,8 +366,6 @@ public HandleErrorResult primaryFail(Method method, Object[] args) throws Throwa
//try to reconnect automatically only time before looping
try {
if (masterProtocol != null && masterProtocol.isConnected() && masterProtocol.ping()) {
- if (log.isDebugEnabled())
- log.debug("Primary node [" + masterProtocol.getHostAddress().toString() + "] connection re-established");
// if in transaction cannot be sure that the last query has been received by server of not, so rollback.
if (masterProtocol.inTransaction()) {
@@ -432,7 +390,6 @@ public HandleErrorResult primaryFail(Method method, Object[] args) throws Throwa
if (!isSecondaryHostFail()) {
try {
if (this.secondaryProtocol != null && this.secondaryProtocol.ping()) {
- log.trace("switching to secondary connection");
syncConnection(masterProtocol, this.secondaryProtocol);
proxy.lock.writeLock().lock();
try {
@@ -443,11 +400,9 @@ public HandleErrorResult primaryFail(Method method, Object[] args) throws Throwa
launchFailLoopIfNotlaunched(false);
try {
return relaunchOperation(method, args);
- } catch (Exception e) {
- log.trace("relaunchOperation failed", e);
- }
+ } catch (Exception e) { }
return new HandleErrorResult();
- } else log.trace("ping failed on secondary");
+ }
} catch (Exception e) {
if (setSecondaryHostFail()) addToBlacklist(this.secondaryProtocol.getHostAddress());
if (secondaryProtocol.isConnected()) {
@@ -458,7 +413,6 @@ public HandleErrorResult primaryFail(Method method, Object[] args) throws Throwa
proxy.lock.writeLock().unlock();
}
}
- log.trace("ping on secondary failed");
}
}
}
@@ -497,12 +451,9 @@ public void reconnect() throws QueryException {
public HandleErrorResult secondaryFail(Method method, Object[] args) throws Throwable {
try {
if (this.secondaryProtocol != null && secondaryProtocol.isConnected() && this.secondaryProtocol.ping()) {
- if (log.isDebugEnabled())
- log.debug("Secondary node [" + this.secondaryProtocol.getHostAddress().toString() + "] connection re-established");
return relaunchOperation(method, args);
}
} catch (Exception e) {
- log.trace("ping fail on secondary");
proxy.lock.writeLock().lock();
try {
secondaryProtocol.close();
@@ -517,7 +468,6 @@ public HandleErrorResult secondaryFail(Method method, Object[] args) throws Thro
try {
if (masterProtocol != null) {
this.masterProtocol.ping(); //check that master is on before switching to him
- log.trace("switching to master connection");
syncConnection(secondaryProtocol, masterProtocol);
proxy.lock.writeLock().lock();
try {
@@ -529,7 +479,6 @@ public HandleErrorResult secondaryFail(Method method, Object[] args) throws Thro
return relaunchOperation(method, args); //now that we are on master, relaunched result if the result was not crashing the master
}
} catch (Exception e) {
- log.trace("ping fail on master");
if (setMasterHostFail()) {
addToBlacklist(masterProtocol.getHostAddress());
if (masterProtocol.isConnected()) {
@@ -547,10 +496,7 @@ public HandleErrorResult secondaryFail(Method method, Object[] args) throws Thro
try {
reconnectFailedConnection(new SearchFilter(true, true, true, true));
if (!isSecondaryHostFail()) {
- if (log.isDebugEnabled())
- log.debug("SQL Secondary node [" + this.masterProtocol.getHostAddress().toString() + "] connection re-established");
} else {
- log.debug("switching to master connection");
syncConnection(this.secondaryProtocol, this.masterProtocol);
proxy.lock.writeLock().lock();
try {
@@ -579,9 +525,7 @@ public PingLoop(MastersSlavesListener listener) {
public void run() {
if (lastQueryTime + jdbcUrl.getOptions().validConnectionTimeout * 1000 < System.currentTimeMillis()) {
- log.trace("PingLoop run ");
if (!isMasterHostFail()) {
- log.trace("PingLoop run, master not seen failed");
boolean masterFail = false;
try {
@@ -591,12 +535,10 @@ public void run() {
masterFail = true;
}
} catch (QueryException e) {
- log.trace("PingLoop ping to master error", e);
masterFail = true;
}
if (masterFail) {
- log.trace("PingLoop master failed -> will loop to found it");
if (setMasterHostFail()) {
try {
listener.primaryFail(null, null);
@@ -611,9 +553,7 @@ public void run() {
}
public void checkIfTypeHaveChanged(SearchFilter searchFilter) throws QueryException {
- if (masterProtocol != null && masterProtocol.ping()) {
- log.trace("PingLoop master ping ok");
- }
+ if (masterProtocol != null && masterProtocol.ping()) { }
}
diff --git a/src/test/java/org/mariadb/jdbc/DateTest.java b/src/test/java/org/mariadb/jdbc/DateTest.java
index d962884b8..f28d59bf5 100644
--- a/src/test/java/org/mariadb/jdbc/DateTest.java
+++ b/src/test/java/org/mariadb/jdbc/DateTest.java
@@ -3,14 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.sql.Date;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.sql.Types;
+import java.sql.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
@@ -245,32 +238,34 @@ public void javaUtilDateInPreparedStatementAsTime() throws Exception {
Assert.assertTrue(Math.abs(d.getSeconds() - rs.getTime(1).getSeconds())<=1);
}
}
+ public void setSessionTimeZone(Connection connection, String timeZone) throws SQLException {
+ Statement statement = connection.createStatement();
+ statement.execute("set @@session.time_zone = '" + timeZone + "'");
+ statement.close();
+ }
@Test
- public void serverTimezone() throws Exception {
+ public void serverTimezone() throws Exception {
TimeZone tz = TimeZone.getDefault();
- //TimeZone gmt = TimeZone.getTimeZone("GMT");
- long offset = tz.getRawOffset();
- setConnection("&serverTimezone=GMT") ;
+
+ setConnection("&serverTimezone=GMT-5:00");
+ setSessionTimeZone(connection, "-5:00");
+
java.util.Date now = new java.util.Date();
- offset = tz.getOffset(now.getTime());
+ TimeZone canadaTimeZone = TimeZone.getTimeZone("GMT-5:00");
+
+ long clientOffset = tz.getOffset(now.getTime());
+ long serverOffset = canadaTimeZone.getOffset(now.getTime());
+ long totalOffset = clientOffset - serverOffset;
PreparedStatement ps = connection.prepareStatement("select now()");
ResultSet rs = ps.executeQuery();
rs.next();
- java.sql.Timestamp ts = rs.getTimestamp(1);
- long differenceToGMT = ts.getTime() - now.getTime();
- long diff = Math.abs(differenceToGMT - offset);
- log.trace("diff : "+diff);
- assertTrue(diff < 5000); /* query take less than a second but taking in accout server and client time second diff ... */
+ java.sql.Timestamp ts = rs.getTimestamp(1);
+ long differenceToServer = ts.getTime() - now.getTime();
+ long diff = Math.abs(differenceToServer - totalOffset);
+ //System.out.println("diff : " + diff);
+ assertTrue(differenceToServer < 5000); /* query take less than a second but taking in account server and client time second diff ... */
- ps = connection.prepareStatement("select utc_timestamp(), ?");
- ps.setObject(1,now);
- rs = ps.executeQuery();
- rs.next();
- ts = rs.getTimestamp(1);
- java.sql.Timestamp ts2 = rs.getTimestamp(2);
- long diff2 = Math.abs(ts.getTime() - ts2.getTime());
- assertTrue(diff2 < 5000); /* query take less than a second */
}
/**
diff --git a/src/test/java/org/mariadb/jdbc/MultiTest.java b/src/test/java/org/mariadb/jdbc/MultiTest.java
index 8c397cb2a..5fd66596b 100644
--- a/src/test/java/org/mariadb/jdbc/MultiTest.java
+++ b/src/test/java/org/mariadb/jdbc/MultiTest.java
@@ -569,4 +569,38 @@ public void testInsertWithoutFirstContent() throws Exception {
if (tmpConnection != null) tmpConnection.close();
}
}
+
+ @Test
+ public void rewriteSelectQuery() throws Throwable {
+ Statement st = connection.createStatement();
+ st.execute("drop table if exists tselect1");
+ st.execute("drop table if exists tselect2");
+ st.execute("create table tselect1 (LAST_UPDATE_DATETIME TIMESTAMP , nn int)");
+ st.execute("create table tselect2 (nn int)");
+ st.execute("INSERT INTO tselect2 VALUES (1)");
+ PreparedStatement ps = connection.prepareStatement("/*CLIENT*/ insert into tselect1 (LAST_UPDATE_DATETIME, nn) select ?, nn from tselect2");
+ ps.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
+ ps.executeUpdate();
+
+ ResultSet rs = st.executeQuery("SELECT * FROM tselect1");
+ rs.next();
+ Assert.assertEquals(rs.getInt(2), 1);
+ }
+
+ @Test
+ public void rewriteSelectQueryServerPrepared() throws Throwable {
+ Statement st = connection.createStatement();
+ st.execute("drop table if exists tselect1");
+ st.execute("drop table if exists tselect2");
+ st.execute("create table tselect1 (LAST_UPDATE_DATETIME TIMESTAMP , nn int)");
+ st.execute("create table tselect2 (nn int)");
+ st.execute("INSERT INTO tselect2 VALUES (1)");
+ PreparedStatement ps = connection.prepareStatement("insert into tselect1 (LAST_UPDATE_DATETIME, nn) select ?, nn from tselect2");
+ ps.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
+ ps.executeUpdate();
+
+ ResultSet rs = st.executeQuery("SELECT * FROM tselect1");
+ rs.next();
+ Assert.assertEquals(rs.getInt(2), 1);
+ }
}
diff --git a/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java b/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
index 6828ee976..aaff3ba48 100644
--- a/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
+++ b/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
@@ -108,4 +108,28 @@ public void testPreparedStatementsWithQuotes() throws SQLException {
connection.createStatement().execute("DROP TABLE IF EXISTS backTicksPreparedStatements");
}
+
+ @Test
+ public void testduplicate() throws Exception {
+ connection.createStatement().execute("DROP TABLE IF EXISTS SOME_TABLE");
+ connection.createStatement().execute("CREATE TABLE SOME_TABLE (ID INT(11) not null, FOO INT(11), PRIMARY KEY (ID), UNIQUE INDEX `FOO` (`FOO`))");
+ String sql = "insert into `SOME_TABLE` (`ID`, `FOO`) values (?, ?) on duplicate key update `SOME_TABLE`.`FOO` = ?";
+ PreparedStatement pst = connection.prepareStatement(sql);
+ pst.setInt(1, 1);
+ pst.setInt(2, 1);
+ pst.setInt(3, 1);
+ pst.addBatch();
+
+ pst.setInt(1, 2);
+ pst.setInt(2, 1);
+ pst.setInt(3, 2);
+ pst.addBatch();
+ pst.executeBatch();
+
+ Statement st = connection.createStatement();
+ ResultSet rs = st.executeQuery("SELECT * FROM `SOME_TABLE`");
+ rs.next();
+ assertEquals(rs.getInt(1), 1);
+ assertEquals(rs.getInt(2), 2);
+ }
}