Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private Connection open(boolean autoReconnect) throws SQLException {
int maxTimes = this.config.get(MysqlOptions.JDBC_RECONNECT_MAX_TIMES);
int interval = this.config.get(MysqlOptions.JDBC_RECONNECT_INTERVAL);

URIBuilder uriBuilder = new URIBuilder();
URIBuilder uriBuilder = this.newConnectionURIBuilder();
uriBuilder.setPath(url)
.setParameter("rewriteBatchedStatements", "true")
.setParameter("useServerPrepStmts", "false")
Expand All @@ -118,6 +118,10 @@ private Connection connect(String url) throws SQLException {
return DriverManager.getConnection(url, username, password);
}

protected URIBuilder newConnectionURIBuilder() {
return new URIBuilder();
}

@Override
protected void doClose() {
// pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.sql.Connection;
import java.sql.SQLException;

import org.apache.http.client.utils.URIBuilder;
import org.postgresql.util.PSQLException;
import org.slf4j.Logger;

Expand Down Expand Up @@ -49,12 +50,12 @@ public void createDatabase() {
// Create database with non-database-session
LOG.debug("Create database: {}", this.database());

String sql = String.format(POSTGRESQL_DB_CREATE, this.database());
String sql = this.buildCreateDatabase(this.database());
try (Connection conn = this.openWithoutDB(0)) {
try {
conn.createStatement().execute(sql);
} catch (PSQLException e) {
// CockroackDB not support 'template' args of CREATE DATABASE
// CockroackDB not support 'template' arg of CREATE DATABASE
if (e.getMessage().contains("syntax error at or near " +
"\"template\"")) {
sql = String.format(COCKROACH_DB_CREATE, this.database());
Expand All @@ -69,4 +70,15 @@ public void createDatabase() {
// Ignore exception if database already exists
}
}

@Override
protected String buildCreateDatabase(String database) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call it from PostgresqlSessions.createDatabase()

return String.format(POSTGRESQL_DB_CREATE, database);
}

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