Add support for MariaDB
Add support for MariaDB using MariaDB connector [1]. [1] https://github.com/MariaDB/mariadb-connector-j Change-Id: I72496f93eb15e24093c8b9d9cda0b225342faa13
This commit is contained in:
parent
0129f08967
commit
fd9f2e1109
@ -1543,6 +1543,10 @@ Connect to an SAP MaxDB database server.
|
||||
+
|
||||
Connect to a MySQL database server.
|
||||
+
|
||||
* `MARIADB`
|
||||
+
|
||||
Connect to a MariaDB database server.
|
||||
+
|
||||
* `ORACLE`
|
||||
+
|
||||
Connect to an Oracle database server.
|
||||
|
@ -74,6 +74,14 @@ rights on it:
|
||||
Visit MySQL's link:http://dev.mysql.com/doc/[documentation] for further
|
||||
information regarding using MySQL.
|
||||
|
||||
[[createdb_mariadb]]
|
||||
=== MariaDB
|
||||
|
||||
Refer to MySQL section above how to create MariaDB database.
|
||||
|
||||
Visit MariaDB's link:https://mariadb.com/kb/en/mariadb/[documentation] for further
|
||||
information regarding using MariaDB.
|
||||
|
||||
[[createdb_oracle]]
|
||||
=== Oracle
|
||||
|
||||
|
@ -39,6 +39,9 @@ public class DatabaseConfigModule extends AbstractModule {
|
||||
bind(DatabaseConfigInitializer.class)
|
||||
.annotatedWith(Names.named("jdbc"))
|
||||
.to(JDBCInitializer.class);
|
||||
bind(DatabaseConfigInitializer.class)
|
||||
.annotatedWith(Names.named("mariadb"))
|
||||
.to(MariaDbInitializer.class);
|
||||
bind(DatabaseConfigInitializer.class)
|
||||
.annotatedWith(Names.named("mysql"))
|
||||
.to(MySqlInitializer.class);
|
||||
|
@ -85,6 +85,8 @@ class InitDatabase implements InitStep {
|
||||
|
||||
if (dci instanceof MySqlInitializer) {
|
||||
libraries.mysqlDriver.downloadRequired();
|
||||
} else if (dci instanceof MariaDbInitializer) {
|
||||
libraries.mariadbDriver.downloadRequired();
|
||||
} else if (dci instanceof OracleInitializer) {
|
||||
libraries.oracleDriver.downloadRequired();
|
||||
} else if (dci instanceof DB2Initializer) {
|
||||
|
@ -37,6 +37,8 @@ class JDBCInitializer implements DatabaseConfigInitializer {
|
||||
database.set("driver", "org.apache.derby.jdbc.EmbeddedDriver");
|
||||
} else if (url.startsWith("jdbc:h2:")) {
|
||||
database.set("driver", "org.h2.Driver");
|
||||
} else if (url.startsWith("jdbc:mariadb:")) {
|
||||
database.set("driver", "org.mariadb.jdbc.Driver");
|
||||
} else if (url.startsWith("jdbc:mysql:")) {
|
||||
database.set("driver", "com.mysql.jdbc.Driver");
|
||||
} else if (url.startsWith("jdbc:postgresql:")) {
|
||||
|
@ -43,6 +43,7 @@ class Libraries {
|
||||
/* final */ LibraryDownloader db2Driver;
|
||||
/* final */ LibraryDownloader db2DriverLicense;
|
||||
/* final */ LibraryDownloader hanaDriver;
|
||||
/* final */ LibraryDownloader mariadbDriver;
|
||||
/* final */ LibraryDownloader mysqlDriver;
|
||||
/* final */ LibraryDownloader oracleDriver;
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.pgm.init;
|
||||
|
||||
import static com.google.gerrit.pgm.init.api.InitUtil.username;
|
||||
|
||||
import com.google.gerrit.pgm.init.api.Section;
|
||||
|
||||
class MariaDbInitializer implements DatabaseConfigInitializer {
|
||||
|
||||
@Override
|
||||
public void initConfig(Section databaseSection) {
|
||||
final String defPort = "(mariadb default)";
|
||||
databaseSection.string("Server hostname", "hostname", "localhost");
|
||||
databaseSection.string("Server port", "port", defPort, true);
|
||||
databaseSection.string("Database name", "database", "reviewdb");
|
||||
databaseSection.string("Database username", "username", username());
|
||||
databaseSection.password("username", "password");
|
||||
}
|
||||
}
|
@ -18,6 +18,12 @@
|
||||
sha1 = b0878056f15616989144d6114d36d3942321d0d1
|
||||
remove = mysql-connector-java-.*[.]jar
|
||||
|
||||
[library "mariadbDriver"]
|
||||
name = MariaDB Connector/J 1.5.9
|
||||
url = https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/1.5.9/mariadb-java-client-1.5.9.jar
|
||||
sha1 = 75d4d6e4cdb9a551a102e92a14c640768174e214
|
||||
remove = mariadb-java-client-.*[.]jar
|
||||
|
||||
[library "oracleDriver"]
|
||||
name = Oracle JDBC driver 11g Release 2 (11.2.0)
|
||||
url = file:///u01/app/oracle/product/11.2.0/xe/jdbc/lib/ojdbc6.jar
|
||||
|
@ -25,6 +25,7 @@ public class DataSourceModule extends AbstractModule {
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("derby")).to(Derby.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("h2")).to(H2.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("jdbc")).to(JDBC.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("mariadb")).to(MariaDb.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("mysql")).to(MySql.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("oracle")).to(Oracle.class);
|
||||
bind(DataSourceType.class).annotatedWith(Names.named("postgresql")).to(PostgreSQL.class);
|
||||
|
@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import static com.google.gerrit.server.schema.JdbcUtil.hostname;
|
||||
import static com.google.gerrit.server.schema.JdbcUtil.port;
|
||||
|
||||
import com.google.gerrit.server.config.ConfigSection;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.inject.Inject;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
class MariaDb extends BaseDataSourceType {
|
||||
private final Config cfg;
|
||||
|
||||
@Inject
|
||||
MariaDb(@GerritServerConfig Config cfg) {
|
||||
super("org.mariadb.jdbc.Driver");
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
ConfigSection dbs = new ConfigSection(cfg, "database");
|
||||
b.append("jdbc:mariadb://");
|
||||
b.append(hostname(dbs.optional("hostname")));
|
||||
b.append(port(dbs.optional("port")));
|
||||
b.append("/");
|
||||
b.append(dbs.required("database"));
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usePool() {
|
||||
// MariaDB has given us trouble with the connection pool,
|
||||
// sometimes the backend disconnects and the pool winds
|
||||
// up with a stale connection. Fortunately opening up
|
||||
// a new MariaDB connection is usually very fast.
|
||||
return false;
|
||||
}
|
||||
}
|
@ -49,6 +49,10 @@
|
||||
<Set name="driverClassName">com.mysql.jdbc.Driver</Set>
|
||||
<Set name="url">jdbc:mysql://localhost/reviewdb?user=gerrit2&password=secretkey</Set>
|
||||
-->
|
||||
<!-- MariaDB
|
||||
<Set name="driverClassName">org.mariadb.jdbc.Driver</Set>
|
||||
<Set name="url">jdbc:mariadb://localhost/reviewdb?user=gerrit2&password=secretkey</Set>
|
||||
-->
|
||||
<!-- H2
|
||||
<Set name="driverClassName">org.h2.Driver</Set>
|
||||
<Set name="url">jdbc:h2:file:ReviewDb</Set>
|
||||
|
Loading…
Reference in New Issue
Block a user