Skip to content

Commit

Permalink
Add mariadb support
Browse files Browse the repository at this point in the history
  • Loading branch information
kellen committed Jan 3, 2025
1 parent 16d1f71 commit a684866
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
8 changes: 8 additions & 0 deletions dbeam-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
Expand All @@ -64,6 +68,10 @@
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory-connector-j-8</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mariadb-socket-factory</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.stream.Collectors;

public class JdbcConnectionUtil {

private static Map<String, String> driverMapping =
ImmutableMap.of(
"postgresql", "org.postgresql.Driver",
"mysql", "com.mysql.cj.jdbc.Driver",
"h2", "org.h2.Driver");
"mariadb", "org.mariadb.jdbc.Driver",
"h2", "org.h2.Driver"
);

private static String driverPrefixes =
driverMapping.keySet().stream()
.map(k -> "jdbc:" + k)
.collect(Collectors.joining(", "));

public static String getDriverClass(final String url) throws ClassNotFoundException {
final String[] parts = url.split(":", 3);
Preconditions.checkArgument(
parts.length > 1 && "jdbc".equals(parts[0]) && driverMapping.get(parts[1]) != null,
"Invalid jdbc connection URL: %s. Expect jdbc:postgresql or jdbc:mysql as prefix.",
url);
parts.length > 1 && "jdbc".equals(parts[0]) && driverMapping.containsKey(parts[1]),
"Invalid jdbc connection URL: %s. Expected one of %s as prefix.",
url,
driverPrefixes
);
return Class.forName(driverMapping.get(parts[1])).getCanonicalName();
}
}
2 changes: 1 addition & 1 deletion e2e/ddl.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

-- This file contatins psql views with complex types to validate and troubleshoot dbeam
-- This file contains psql views with complex types to validate and troubleshoot dbeam
-- import with:
-- psql -f ddl.sql postgres

Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<bouncycastle.version>1.78.1</bouncycastle.version>
<junit.version>4.13.2</junit.version>
<mysql.version>8.4.0</mysql.version>
<mariadb.version>3.5.1</mariadb.version>
<postgresql.version>42.7.4</postgresql.version>
<socket-factory.version>1.18.0</socket-factory.version>
</properties>
Expand Down Expand Up @@ -365,6 +366,11 @@
<artifactId>mysql-connector-j</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb.version}</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
Expand All @@ -376,6 +382,11 @@
<artifactId>mysql-socket-factory-connector-j-8</artifactId>
<version>${socket-factory.version}</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mariadb-socket-factory</artifactId>
<version>${socket-factory.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down

0 comments on commit a684866

Please sign in to comment.