diff --git a/.gitignore b/.gitignore index 2baf4d58..16d29875 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ out .gradle dalesbred/src/test/resources/postgresql-connection.properties dalesbred/src/test/resources/mysql-connection.properties +dalesbred/src/test/resources/mariadb-connection.properties diff --git a/buildSrc/src/main/kotlin/dalesbred.java-library-conventions.gradle.kts b/buildSrc/src/main/kotlin/dalesbred.java-library-conventions.gradle.kts index d5c95591..4cd66d35 100644 --- a/buildSrc/src/main/kotlin/dalesbred.java-library-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/dalesbred.java-library-conventions.gradle.kts @@ -53,6 +53,7 @@ dependencyManagement { dependency("org.hsqldb:hsqldb:2.4.0") dependency("com.h2database:h2:1.4.200") dependency("mysql:mysql-connector-java:8.0.26") + dependency("org.mariadb.jdbc:mariadb-java-client:3.4.1") dependency("com.oracle.database.jdbc:ojdbc8:21.3.0.0") dependency("junit:junit:4.13.2") dependency("ch.qos.logback:logback-core:$logbackVersion") diff --git a/dalesbred/build.gradle.kts b/dalesbred/build.gradle.kts index 3109bf1b..bb8eb4b7 100644 --- a/dalesbred/build.gradle.kts +++ b/dalesbred/build.gradle.kts @@ -46,6 +46,7 @@ dependencies { testImplementation("org.hsqldb:hsqldb") testImplementation("com.h2database:h2") testImplementation("mysql:mysql-connector-java") + testImplementation("org.mariadb.jdbc:mariadb-java-client") testImplementation("junit:junit") testImplementation("ch.qos.logback:logback-core") testImplementation("ch.qos.logback:logback-classic") diff --git a/dalesbred/src/main/java/org/dalesbred/dialect/Dialect.java b/dalesbred/src/main/java/org/dalesbred/dialect/Dialect.java index 24350b70..8043c77c 100644 --- a/dalesbred/src/main/java/org/dalesbred/dialect/Dialect.java +++ b/dalesbred/src/main/java/org/dalesbred/dialect/Dialect.java @@ -109,6 +109,10 @@ public abstract class Dialect { log.debug("Automatically detected dialect MySQL."); return new MySQLDialect(); + case "MariaDB": + log.debug("Automatically detected dialect MariaDB."); + return new MariaDBDialect(); + case "Oracle": log.debug("Automatically detected dialect Oracle."); return new OracleDialect(); diff --git a/dalesbred/src/main/java/org/dalesbred/dialect/MariaDBDialect.java b/dalesbred/src/main/java/org/dalesbred/dialect/MariaDBDialect.java new file mode 100644 index 00000000..be8dd45c --- /dev/null +++ b/dalesbred/src/main/java/org/dalesbred/dialect/MariaDBDialect.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Evident Solutions Oy + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.dalesbred.dialect; + +/** + * Support for MariaDB. + */ +public class MariaDBDialect extends Dialect { +} diff --git a/dalesbred/src/test/kotlin/org/dalesbred/TestDatabaseProvider.kt b/dalesbred/src/test/kotlin/org/dalesbred/TestDatabaseProvider.kt index 9d17b06a..0eae4526 100644 --- a/dalesbred/src/test/kotlin/org/dalesbred/TestDatabaseProvider.kt +++ b/dalesbred/src/test/kotlin/org/dalesbred/TestDatabaseProvider.kt @@ -57,6 +57,9 @@ object TestDatabaseProvider { fun createMySQLConnectionProvider() = createConnectionProviderFromProperties("mysql-connection.properties") + fun createMariaDBConnectionProvider() = + createConnectionProviderFromProperties("mariadb-connection.properties") + fun createInMemoryHSQLConnectionProvider(): ConnectionProvider = DriverManagerConnectionProvider("jdbc:hsqldb:.", "sa", "") diff --git a/dalesbred/src/test/kotlin/org/dalesbred/dialect/MariaDBDialectTest.kt b/dalesbred/src/test/kotlin/org/dalesbred/dialect/MariaDBDialectTest.kt new file mode 100644 index 00000000..2a5d5178 --- /dev/null +++ b/dalesbred/src/test/kotlin/org/dalesbred/dialect/MariaDBDialectTest.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Evident Solutions Oy + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.dalesbred.dialect + +import org.dalesbred.TestDatabaseProvider +import org.junit.Test +import kotlin.test.assertTrue + +class MariaDBDialectTest { + + @Test + fun detectMariaDbDialect() { + val dialect = Dialect.detect(TestDatabaseProvider.createMariaDBConnectionProvider()) + assertTrue { dialect is MariaDBDialect } + } +}