-
Notifications
You must be signed in to change notification settings - Fork 4
feat(mariadb): Add MariaDB support #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ db2-11-5 | |
| derby-10-14 | ||
| h2-1-4 | ||
| hsqldb-2-7 | ||
| mariadb-11-4 | ||
| mssql-2022 | ||
| mysql-9-20 | ||
| oracle-18 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/org/dbunit/ext/mariadb/MariaDbDataTypeFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * | ||
| * The DbUnit Database Testing Framework | ||
| * Copyright (C)2002-2004, DbUnit.org | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| * | ||
| */ | ||
| package org.dbunit.ext.mariadb; | ||
|
|
||
| import java.sql.Types; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| import org.dbunit.dataset.datatype.DataType; | ||
| import org.dbunit.dataset.datatype.DataTypeException; | ||
| import org.dbunit.ext.mysql.MySqlDataTypeFactory; | ||
|
|
||
| /** | ||
| * Specialized factory that recognizes MariaDB data types. | ||
| * <p> | ||
| * MariaDB is wire-compatible with MySQL, so this extends | ||
| * {@link MySqlDataTypeFactory} and adds recognition for the MariaDB-native | ||
| * types that have no MySQL equivalent: {@code UUID} (10.7+) and | ||
| * {@code INET4}/{@code INET6} (10.10+). MariaDB's JDBC driver reports all | ||
| * three as SQL type {@link Types#OTHER}, which {@link MySqlDataTypeFactory} | ||
| * (and its {@code DefaultDataTypeFactory} parent) does not otherwise | ||
| * recognize. | ||
| * <p> | ||
| * MariaDB's {@code JSON} type is a {@code LONGTEXT} alias enforced by a | ||
| * {@code CHECK} constraint, not a distinct SQL type — it already reports as | ||
| * plain {@code LONGTEXT} and needs no special handling here. | ||
| * | ||
| * @author Jeff Jensen | ||
| * @since 3.4.1 | ||
| */ | ||
| public class MariaDbDataTypeFactory extends MySqlDataTypeFactory | ||
| { | ||
| /** SQL type name MariaDB reports for a native {@code UUID} column. */ | ||
| public static final String SQL_TYPE_NAME_UUID = "UUID"; | ||
| /** SQL type name MariaDB reports for a native {@code INET4} column. */ | ||
| public static final String SQL_TYPE_NAME_INET4 = "INET4"; | ||
| /** SQL type name MariaDB reports for a native {@code INET6} column. */ | ||
| public static final String SQL_TYPE_NAME_INET6 = "INET6"; | ||
|
|
||
| /** | ||
| * Database product names supported. | ||
| */ | ||
| private static final Collection DATABASE_PRODUCTS = Arrays.asList(new String[] {"mariadb"}); | ||
|
|
||
| /** | ||
| * @see org.dbunit.dataset.datatype.IDbProductRelatable#getValidDbProducts() | ||
| */ | ||
| @Override | ||
| public Collection getValidDbProducts() | ||
| { | ||
| return DATABASE_PRODUCTS; | ||
| } | ||
|
|
||
| @Override | ||
| public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException | ||
| { | ||
| if (sqlType == Types.OTHER) | ||
| { | ||
| if (SQL_TYPE_NAME_UUID.equalsIgnoreCase(sqlTypeName) | ||
| || SQL_TYPE_NAME_INET4.equalsIgnoreCase(sqlTypeName) | ||
| || SQL_TYPE_NAME_INET6.equalsIgnoreCase(sqlTypeName)) | ||
| { | ||
| return DataType.VARCHAR; | ||
| } | ||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return super.createDataType(sqlType, sqlTypeName); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| = MariaDB | ||
|
|
||
| == Overview | ||
|
|
||
| `org.dbunit.ext.mariadb` provides MariaDB-specific type recognition for | ||
| dbUnit. MariaDB is wire- and SQL-compatible with MySQL, so its factory | ||
| builds on link:mysql.html[MySQL]'s rather than duplicating it, but this | ||
| page is self-contained — no need to read the MySQL page too. | ||
|
|
||
| == IDataTypeFactory | ||
|
|
||
| link:/dbunit/apidocs/org/dbunit/ext/mariadb/MariaDbDataTypeFactory.html[MariaDbDataTypeFactory] | ||
| extends `MySqlDataTypeFactory`, so it inherits MySQL's mappings — | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| `longtext` as `CLOB`, `bit` as `BOOLEAN`/`TINYINT` depending on context, | ||
| `point` as `BINARY`, and the `UNSIGNED` integer family — and adds | ||
| recognition of MariaDB-native types with no MySQL equivalent: | ||
|
|
||
| [cols="1,3", options="header"] | ||
| |=== | ||
| |Type |Handling | ||
|
|
||
| |`UUID` (10.7+) |Reported as SQL type `OTHER`; mapped to `VARCHAR`. | ||
| |`INET4` (10.10+) |Reported as SQL type `OTHER` via table metadata (a live query instead reports it as plain `CHAR`, indistinguishable from a real char column); mapped to `VARCHAR`. | ||
| |`INET6` (10.10+) |Same as `INET4`. | ||
| |`JSON` |A `LONGTEXT` alias enforced by a `CHECK` constraint, not a distinct SQL type — already works via the inherited `longtext` handling, no extra mapping needed. | ||
| |=== | ||
|
|
||
| Register it via `DatabaseConfig.PROPERTY_DATATYPE_FACTORY` — see | ||
| link:../properties.html#typefactory[Properties] and | ||
| link:../connections.html[Connections & Configuration]. | ||
|
|
||
| == IMetadataHandler | ||
|
|
||
| There is no MariaDB-specific `IMetadataHandler` — register MySQL's | ||
| link:/dbunit/apidocs/org/dbunit/ext/mysql/MySqlMetadataHandler.html[MySqlMetadataHandler] | ||
| instead, and treat it as a requirement rather than an option: MariaDB | ||
| Connector/J needs it even more than MySQL does. MySQL Connector/J's | ||
| `nullCatalogMeansCurrent` default already restricts an unfiltered | ||
| `DatabaseMetaData#getTables()` call to the connection's current database; | ||
| MariaDB Connector/J has no such default, so a connection using dbUnit's | ||
| plain default handler sees every catalog's tables, including | ||
| `information_schema`/`performance_schema` system tables. dbUnit then fails | ||
| with a `SQLSyntaxErrorException` the moment it tries to operate on one of | ||
| those leaked tables (e.g. during `DELETE_ALL`). `MySqlMetadataHandler` | ||
| fixes this because it passes the schema as the JDBC catalog argument, | ||
| which MariaDB Connector/J does honor even though it ignores the schema | ||
| pattern argument. Equivalently — or in addition, for defense in depth — | ||
| add `nullCatalogMeansCurrent=true` to the MariaDB JDBC URL to match MySQL | ||
| Connector/J's own default. | ||
|
|
||
| == Connection Preconfiguration Class | ||
|
|
||
| None — MariaDB has no dedicated `IDatabaseConnection` subclass. Register | ||
| `MariaDbDataTypeFactory` and `MySqlMetadataHandler` directly on a plain | ||
| `DatabaseConnection`'s `DatabaseConfig`: | ||
|
|
||
| [source,java] | ||
| ---- | ||
| IDatabaseConnection connection = new DatabaseConnection(jdbcConnection, schema); | ||
| DatabaseConfig config = connection.getConfig(); | ||
| config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MariaDbDataTypeFactory()); | ||
| config.setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new MySqlMetadataHandler()); | ||
| ---- | ||
|
|
||
| == Vendor-Specific Types | ||
|
|
||
| The `longtext`/`bit`/`point`/`UNSIGNED` handling inherited from MySQL, | ||
| plus MariaDB's own `UUID`/`INET4`/`INET6` handling — see | ||
| `IDataTypeFactory` above. | ||
|
|
||
| == Known Quirks | ||
|
|
||
| Forgetting to register `MySqlMetadataHandler` (or the | ||
| `nullCatalogMeansCurrent=true` URL parameter) is the most common surprise | ||
| on MariaDB: it surfaces as a `SQLSyntaxErrorException` naming an | ||
| `information_schema`/`performance_schema` table rather than anything | ||
| that looks like a configuration problem — see `IMetadataHandler` above. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.