Add dialect for MariaDB A new database dialect is added to support MariaDB [1]. [1] https://mariadb.com Change-Id: Ia52c657fa2b52b37584b732f0d75a2a1d314fa16
diff --git a/README_ECLIPSE b/README_ECLIPSE index 51db79b..2592a9b 100644 --- a/README_ECLIPSE +++ b/README_ECLIPSE
@@ -39,8 +39,8 @@ It may be necessary to run the commands as the postgres user. In this case, prefix the commands with `sudo -u postgres`. -MySQL -~~~~~ +MySQL and MariaDB +~~~~~~~~~~~~~~~~~ Enter the mysql console:
diff --git a/pom.xml b/pom.xml index b28af42..727ca0b 100644 --- a/pom.xml +++ b/pom.xml
@@ -519,6 +519,13 @@ </dependency> <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + <version>1.5.9</version> + <scope>test</scope> + </dependency> + + <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>2.5.0</version>
diff --git a/src/main/java/com/google/gwtorm/schema/sql/DialectMariaDB.java b/src/main/java/com/google/gwtorm/schema/sql/DialectMariaDB.java new file mode 100644 index 0000000..171d2e2 --- /dev/null +++ b/src/main/java/com/google/gwtorm/schema/sql/DialectMariaDB.java
@@ -0,0 +1,25 @@ +// Copyright 2017 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.gwtorm.schema.sql; + +import java.sql.Connection; + +/** Dialect for <a href="https://mariadb.com/">MariaDB</a> */ +public class DialectMariaDB extends DialectMySQL { + @Override + public boolean handles(String url, Connection c) { + return url.startsWith("jdbc:mariadb:"); + } +}
diff --git a/src/main/java/com/google/gwtorm/schema/sql/SqlDialect.java b/src/main/java/com/google/gwtorm/schema/sql/SqlDialect.java index 98f1ae1..17c1e88 100644 --- a/src/main/java/com/google/gwtorm/schema/sql/SqlDialect.java +++ b/src/main/java/com/google/gwtorm/schema/sql/SqlDialect.java
@@ -45,6 +45,7 @@ DIALECTS.add(new DialectH2()); DIALECTS.add(new DialectPostgreSQL()); DIALECTS.add(new DialectMySQL()); + DIALECTS.add(new DialectMariaDB()); DIALECTS.add(new DialectOracle()); DIALECTS.add(new DialectMaxDB()); DIALECTS.add(new DialectHANA());
diff --git a/src/test/java/com/google/gwtorm/schema/sql/DialectMariaDBTest.java b/src/test/java/com/google/gwtorm/schema/sql/DialectMariaDBTest.java new file mode 100644 index 0000000..c73b1f5 --- /dev/null +++ b/src/test/java/com/google/gwtorm/schema/sql/DialectMariaDBTest.java
@@ -0,0 +1,59 @@ +// Copyright 2017 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.gwtorm.schema.sql; + +import static org.junit.Assume.assumeNoException; + +import com.google.gwtorm.data.PhoneBookDb; +import com.google.gwtorm.data.PhoneBookDb2; +import com.google.gwtorm.jdbc.Database; +import com.google.gwtorm.jdbc.JdbcExecutor; +import com.google.gwtorm.jdbc.SimpleDataSource; + +import org.junit.Before; + +import java.sql.DriverManager; +import java.util.Properties; + +public class DialectMariaDBTest extends DialectMySQLTest { + @Before + public void setUp() throws Exception { + Class.forName(org.mariadb.jdbc.Driver.class.getName()); + + final String host = "localhost"; + final String database = "gwtorm"; + final String user = "gwtorm"; + final String pass = "gwtorm"; + + final String url = "jdbc:mariadb://" + host + "/" + database; + try { + db = DriverManager.getConnection(url, user, pass); + } catch (Throwable t) { + assumeNoException(t); + } + executor = new JdbcExecutor(db); + dialect = new DialectMariaDB().refine(db); + + final Properties p = new Properties(); + p.setProperty("driver", org.mariadb.jdbc.Driver.class.getName()); + p.setProperty("url", db.getMetaData().getURL()); + p.setProperty("user", user); + p.setProperty("password", pass); + phoneBook = + new Database<>(new SimpleDataSource(p), PhoneBookDb.class); + phoneBook2 = + new Database<>(new SimpleDataSource(p), PhoneBookDb2.class); + } +}