Skip to content

Commit 523e6ed

Browse files
committed
Merge branch 'release/3.0.5'
2 parents cc0aa96 + c2f09c7 commit 523e6ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1658
-191
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ or maven :
2727
<dependency>
2828
<groupId>org.mariadb.jdbc</groupId>
2929
<artifactId>mariadb-java-client</artifactId>
30-
<version>3.0.4</version>
30+
<version>3.0.5</version>
3131
</dependency>
3232
```
3333

@@ -46,7 +46,7 @@ Development snapshot are available on sonatype nexus repository
4646
<dependency>
4747
<groupId>org.mariadb.jdbc</groupId>
4848
<artifactId>mariadb-java-client</artifactId>
49-
<version>3.0.5-SNAPSHOT</version>
49+
<version>3.0.6-SNAPSHOT</version>
5050
</dependency>
5151
</dependencies>
5252
```

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>mariadb-java-client</artifactId>
88
<packaging>jar</packaging>
99
<name>mariadb-java-client</name>
10-
<version>3.0.4</version>
10+
<version>3.0.5</version>
1111
<description>JDBC driver for MariaDB and MySQL</description>
1212
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>
1313

@@ -23,7 +23,7 @@
2323
<logback.version>1.3.0-alpha12</logback.version>
2424
<jacoco.version>0.8.7</jacoco.version>
2525
<waffle-jna.version>3.1.1</waffle-jna.version>
26-
<mysql-connector-java.version>8.0.28</mysql-connector-java.version>
26+
<mysql-connector-java.version>8.0.29</mysql-connector-java.version>
2727
<bnd-maven-plugin.version>6.2.0</bnd-maven-plugin.version>
2828
</properties>
2929

src/main/java/org/mariadb/jdbc/BaseCallableStatement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.mariadb.jdbc.client.result.Result;
1717
import org.mariadb.jdbc.codec.Parameter;
1818
import org.mariadb.jdbc.export.ExceptionFactory;
19+
import org.mariadb.jdbc.util.ParameterList;
1920

2021
/** Common methods for function/stored procedure */
2122
public abstract class BaseCallableStatement extends ServerPreparedStatement
@@ -167,6 +168,13 @@ public void registerOutParameter(int parameterIndex, int sqlType, int scale) thr
167168
registerOutParameter(parameterIndex, sqlType);
168169
}
169170

171+
@Override
172+
public void clearParameters() throws SQLException {
173+
checkNotClosed();
174+
parameters = new ParameterList();
175+
outputParameters.stream().forEach(index -> parameters.set(index - 1, Parameter.NULL_PARAMETER));
176+
}
177+
170178
/**
171179
* Retrieves whether the last OUT parameter read had the value of SQL <code>NULL</code>. Note that
172180
* this method should be called only after calling a getter method; otherwise, there is no value

src/main/java/org/mariadb/jdbc/BasePreparedStatement.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ public BasePreparedStatement(
7272
this.sql = sql;
7373
}
7474

75+
@Override
76+
public String toString() {
77+
StringBuilder sb = new StringBuilder("sql:'" + sql + "'");
78+
sb.append(", parameters:[");
79+
for (int i = 0; i < parameters.size(); i++) {
80+
org.mariadb.jdbc.client.util.Parameter param = parameters.get(i);
81+
if (param == null) {
82+
sb.append("null");
83+
} else {
84+
sb.append(param.bestEffortStringValue(con.getContext()));
85+
}
86+
if (i != parameters.size() - 1) {
87+
sb.append(",");
88+
}
89+
}
90+
sb.append("]");
91+
return sb.toString();
92+
}
93+
7594
/**
7695
* Set PREPARE result
7796
*

src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,4 +502,9 @@ public void close() throws SQLException {
502502
con.fireStatementClosed(this);
503503
super.close();
504504
}
505+
506+
@Override
507+
public String toString() {
508+
return "ClientPreparedStatement{" + super.toString() + '}';
509+
}
505510
}

src/main/java/org/mariadb/jdbc/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class Configuration {
9696

9797
// protocol
9898
private boolean allowMultiQueries = false;
99-
private boolean allowLocalInfile = false;
99+
private boolean allowLocalInfile = true;
100100
private boolean useCompression = false;
101101
private boolean useAffectedRows = false;
102102
private boolean useBulkStmts = true;

src/main/java/org/mariadb/jdbc/Connection.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Connection implements java.sql.Connection {
4747
private final boolean canUseServerTimeout;
4848
private final boolean canUseServerMaxRows;
4949
private final int defaultFetchSize;
50+
private final boolean forceTransactionEnd;
5051
private MariaDbPoolConnection poolConnection;
5152

5253
/**
@@ -58,6 +59,7 @@ public class Connection implements java.sql.Connection {
5859
*/
5960
public Connection(Configuration conf, ReentrantLock lock, Client client) {
6061
this.conf = conf;
62+
this.forceTransactionEnd = Boolean.parseBoolean(conf.nonMappedOptions().getProperty("forceTransactionEnd", "false"));
6163
this.lock = lock;
6264
this.exceptionFactory = client.getExceptionFactory().setConnection(this);
6365
this.client = client;
@@ -198,7 +200,7 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
198200
public void commit() throws SQLException {
199201
lock.lock();
200202
try {
201-
if ((client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
203+
if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
202204
client.execute(new QueryPacket("COMMIT"), false);
203205
}
204206
} finally {
@@ -210,7 +212,7 @@ public void commit() throws SQLException {
210212
public void rollback() throws SQLException {
211213
lock.lock();
212214
try {
213-
if ((client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
215+
if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
214216
client.execute(new QueryPacket("ROLLBACK"), true);
215217
}
216218
} finally {
@@ -842,7 +844,7 @@ && getContext().getVersion().getMinorVersion() == 2
842844
}
843845

844846
// in transaction => rollback
845-
if ((client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
847+
if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
846848
client.execute(new QueryPacket("ROLLBACK"), true);
847849
}
848850

src/main/java/org/mariadb/jdbc/Driver.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,35 @@ public static Connection connect(Configuration configuration) throws SQLExceptio
5656
break;
5757

5858
default:
59-
HostAddress hostAddress =
60-
configuration.addresses().isEmpty() ? null : configuration.addresses().get(0);
61-
client =
62-
configuration.transactionReplay()
63-
? new ReplayClient(configuration, hostAddress, lock, false)
64-
: new StandardClient(configuration, hostAddress, lock, false);
59+
ClientInstance<Configuration, HostAddress, ReentrantLock, Boolean, Client> clientInstance =
60+
(configuration.transactionReplay()) ? ReplayClient::new : StandardClient::new;
61+
62+
if (configuration.addresses().isEmpty()) {
63+
// unix socket / windows pipe
64+
client = clientInstance.apply(configuration, null, lock, false);
65+
} else {
66+
// loop until finding
67+
SQLException lastException = null;
68+
for (HostAddress host : configuration.addresses()) {
69+
try {
70+
client = clientInstance.apply(configuration, host, lock, false);
71+
return new Connection(configuration, lock, client);
72+
} catch (SQLException e) {
73+
lastException = e;
74+
}
75+
}
76+
throw lastException;
77+
}
6578
break;
6679
}
6780
return new Connection(configuration, lock, client);
6881
}
6982

83+
@FunctionalInterface
84+
private interface ClientInstance<T, U, V, W, R> {
85+
R apply(T t, U u, V v, W w) throws SQLException;
86+
}
87+
7088
/**
7189
* Connect to the given connection string.
7290
*

src/main/java/org/mariadb/jdbc/FunctionStatement.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,24 @@ protected void preValidParameters() throws SQLException {
9090
parameters = newParameters;
9191
super.validParameters();
9292
}
93+
94+
@Override
95+
public String toString() {
96+
StringBuilder sb = new StringBuilder("FunctionStatement{sql:'" + sql + "'");
97+
sb.append(", parameters:[");
98+
for (int i = 0; i < parameters.size(); i++) {
99+
org.mariadb.jdbc.client.util.Parameter param = parameters.get(i);
100+
if (outputParameters.contains(i + 1)) sb.append("<OUT>");
101+
if (param == null) {
102+
sb.append("null");
103+
} else {
104+
sb.append(param.bestEffortStringValue(con.getContext()));
105+
}
106+
if (i != parameters.size() - 1) {
107+
sb.append(",");
108+
}
109+
}
110+
sb.append("]}");
111+
return sb.toString();
112+
}
93113
}

src/main/java/org/mariadb/jdbc/ProcedureStatement.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,24 @@ protected void handleParameterOutput() throws SQLException {
6767
}
6868
}
6969
}
70+
71+
@Override
72+
public String toString() {
73+
StringBuilder sb = new StringBuilder("ProcedureStatement{sql:'" + sql + "'");
74+
sb.append(", parameters:[");
75+
for (int i = 0; i < parameters.size(); i++) {
76+
org.mariadb.jdbc.client.util.Parameter param = parameters.get(i);
77+
if (outputParameters.contains(i + 1)) sb.append("<OUT>");
78+
if (param == null) {
79+
sb.append("null");
80+
} else {
81+
sb.append(param.bestEffortStringValue(con.getContext()));
82+
}
83+
if (i != parameters.size() - 1) {
84+
sb.append(",");
85+
}
86+
}
87+
sb.append("]}");
88+
return sb.toString();
89+
}
7090
}

0 commit comments

Comments
 (0)