Skip to content

Commit

Permalink
Bump httpclient from 4.5.2 to 4.5.13
Browse files Browse the repository at this point in the history
also fix added leading "/" into url by URIBuilder:
https://github.com/hugegraph/hugegraph/pull/1487#issuecomment-998749310

Change-Id: I71aa4f75bf53fd3841f51856af3df85169b37d66
  • Loading branch information
javeme committed Dec 21, 2021
1 parent 68e3467 commit b5ec777
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
package com.baidu.hugegraph.backend.store.mysql;

import java.net.SocketTimeoutException;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;
Expand All @@ -38,12 +39,15 @@
import com.baidu.hugegraph.backend.store.BackendSession.AbstractBackendSession;
import com.baidu.hugegraph.backend.store.BackendSessionPool;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;

public class MysqlSessions extends BackendSessionPool {

private static final Logger LOG = Log.logger(MysqlStore.class);

private static final String JDBC_PREFIX = "jdbc:";

private static final int DROP_DB_TIMEOUT = 10000;

private HugeConfig config;
Expand Down Expand Up @@ -221,8 +225,17 @@ protected String buildUri(boolean withConnParams, boolean withDB,
int interval = this.config.get(MysqlOptions.JDBC_RECONNECT_INTERVAL);
String sslMode = this.config.get(MysqlOptions.JDBC_SSL_MODE);

URIBuilder builder = this.newConnectionURIBuilder();
builder.setPath(url).setParameter("useSSL", sslMode);
E.checkArgument(url.startsWith(JDBC_PREFIX),
"The url must start with '%s': '%s'",
JDBC_PREFIX, url);
String urlWithoutJdbc = url.substring(JDBC_PREFIX.length());
URIBuilder builder;
try {
builder = this.newConnectionURIBuilder(urlWithoutJdbc);
} catch (URISyntaxException e) {
throw new BackendException("Invalid url '%s'", e, url);
}
builder.setParameter("useSSL", sslMode);
if (withConnParams) {
builder.setParameter("characterEncoding", "utf-8")
.setParameter("rewriteBatchedStatements", "true")
Expand All @@ -234,7 +247,7 @@ protected String buildUri(boolean withConnParams, boolean withDB,
if (timeout != null) {
builder.setParameter("socketTimeout", String.valueOf(timeout));
}
return builder.toString();
return JDBC_PREFIX + builder.toString();
}

protected String buildUrlPrefix(boolean withDB) {
Expand All @@ -250,8 +263,9 @@ protected String connectDatabase() {
return Strings.EMPTY;
}

protected URIBuilder newConnectionURIBuilder() {
return new URIBuilder();
protected URIBuilder newConnectionURIBuilder(String url)
throws URISyntaxException {
return new URIBuilder(url);
}

private Connection connect(String url) throws SQLException {
Expand Down Expand Up @@ -494,7 +508,7 @@ public boolean execute(String sql) throws SQLException {
if (!this.conn.getAutoCommit()) {
this.end();
}

try (Statement statement = this.conn.createStatement()) {
return statement.execute(sql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.baidu.hugegraph.backend.store.postgresql;

import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -112,9 +113,10 @@ protected String buildExistsTable(String table) {
}

@Override
protected URIBuilder newConnectionURIBuilder() {
protected URIBuilder newConnectionURIBuilder(String url)
throws URISyntaxException {
// Suppress error log when database does not exist
return new URIBuilder().addParameter("loggerLevel", "OFF");
return new URIBuilder(url).addParameter("loggerLevel", "OFF");
}

@Override
Expand Down

0 comments on commit b5ec777

Please sign in to comment.