Skip to content

Commit

Permalink
Connections exception now contain SQLState and errorCode [CONJ-166]
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 16, 2015
1 parent 7b6277d commit 5c8f4fe
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>mariadb-java-client</artifactId>
<packaging>jar</packaging>
<name>mariadb-java-client</name>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.0</version>
<description>JDBC driver for MariaDB and MySQL</description>
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>
<properties>
Expand Down Expand Up @@ -88,7 +88,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<version>1.4.0</version>
<configuration>
<executable>git</executable>
<arguments>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/mariadb/jdbc/Version.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.mariadb.jdbc;

public final class Version {
public static final String version = "1.2.0-SNAPSHOT";
public static final String version = "1.2.0";
public static final int majorVersion = 1;
public static final int minorVersion = 2;
public static final int patchVersion = 0;
public static final String qualifier = "SNAPSHOT";
public static final String qualifier = "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ private static Options parse(UrlHAMode haMode, String urlParameters, Properties
if (pos == -1) {
throw new IllegalArgumentException("Invalid connection URL, expected key=value pairs, found " + parameter);
}
properties.setProperty(parameter.substring(0, pos), parameter.substring(pos + 1));
if (!properties.containsKey(parameter.substring(0, pos)))
properties.setProperty(parameter.substring(0, pos), parameter.substring(pos + 1));
}
}
return parse(haMode, properties, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void checkErrorPacket(RawPacket rp) throws QueryException{
if (rp.getByteBuffer().get(0) == -1) {
ErrorPacket ep = new ErrorPacket(rp);
String message = ep.getMessage();
throw new QueryException("Could not connect: " + message);
throw new QueryException("Could not connect: " + message, ep.getErrorNumber(), ep.getSqlState());
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/mariadb/jdbc/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Properties;
import java.util.concurrent.Executor;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.mariadb.jdbc.internal.common.query.MySQLQuery;
Expand All @@ -21,6 +22,23 @@

public class ConnectionTest extends BaseTest {


/**
* CONJ-166
* Connection error code must be thrown
* @throws SQLException
*/
@Test
public void testAccessDeniedErrorCode() throws SQLException {
try {
DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database+"?user=foo");
Assert.fail();
} catch (SQLException e) {
Assert.assertTrue("28000".equals(e.getSQLState()));
Assert.assertTrue(1045 == e.getErrorCode());
}
}

/**
* CONJ-89
*
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/org/mariadb/jdbc/failover/AuroraFailoverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,23 @@ public void socketTimeoutTest() throws SQLException {
// the connection should not be closed
assertTrue(!connection.isClosed());
}

/**
* CONJ-166
* Connection error code must be thrown
* @throws SQLException
*/
@Test
public void testAccessDeniedErrorCode() throws SQLException {
try {
DriverManager.getConnection(initialUrl+"&retriesAllDown=1", "foouser", "foopwd");
Assert.fail();
} catch (SQLException e) {
Assert.assertTrue("28000".equals(e.getSQLState()));
Assert.assertTrue(1045 == e.getErrorCode());
}
}

// @Test
// public void testFailoverMaster() throws Throwable {
// connection = getNewConnection("&validConnectionTimeout=1&secondsBeforeRetryMaster=1&autoReconnect=true", false);
Expand Down

0 comments on commit 5c8f4fe

Please sign in to comment.