Skip to content
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

Fix issue with OceanBase back up driver not falling back to MySQL #31

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,22 @@
import org.flywaydb.community.database.OceanBaseDatabaseExtension;
import org.flywaydb.core.api.ResourceProvider;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.database.base.BaseDatabaseType;
import org.flywaydb.core.internal.database.base.CommunityDatabaseType;
import org.flywaydb.core.internal.database.base.Database;
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
import org.flywaydb.core.internal.jdbc.StatementInterceptor;
import org.flywaydb.core.internal.parser.Parser;
import org.flywaydb.core.internal.parser.ParsingContext;
import org.flywaydb.core.internal.util.ClassUtils;
import org.flywaydb.database.mysql.MySQLDatabaseType;
import org.flywaydb.database.mysql.MySQLParser;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;

public class OceanBaseDatabaseType extends BaseDatabaseType implements CommunityDatabaseType {
public class OceanBaseDatabaseType extends MySQLDatabaseType implements CommunityDatabaseType {

private static final String MYSQL_JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String MYSQL_LEGACY_JDBC_DRIVER = "com.mysql.jdbc.Driver";
private static final String OB_JDBC_DRIVER = "com.oceanbase.jdbc.Driver";
private static final String OB_LEGACY_JDBC_DRIVER = "com.alipay.oceanbase.jdbc.Driver";

Expand All @@ -61,21 +59,16 @@ public boolean handlesJDBCUrl(String url) {

@Override
public String getDriverClass(String url, ClassLoader classLoader) {
if (url.startsWith("jdbc:mysql:")) {
return MYSQL_JDBC_DRIVER;
}
return OB_JDBC_DRIVER;
return url.startsWith("jdbc:oceanbase:")?
OB_JDBC_DRIVER :
super.getDriverClass(url, classLoader);
}

@Override
public String getBackupDriverClass(String url, ClassLoader classLoader) {
if (url.startsWith("jdbc:mysql:") && ClassUtils.isPresent(MYSQL_LEGACY_JDBC_DRIVER, classLoader)) {
return MYSQL_LEGACY_JDBC_DRIVER;
}
if (url.startsWith("jdbc:oceanbase:") && ClassUtils.isPresent(OB_LEGACY_JDBC_DRIVER, classLoader)) {
return OB_LEGACY_JDBC_DRIVER;
}
return null;
return (url.startsWith("jdbc:oceanbase:") && ClassUtils.isPresent(OB_LEGACY_JDBC_DRIVER, classLoader)?
OB_LEGACY_JDBC_DRIVER :
super.getBackupDriverClass(url, classLoader));
}

@Override
Expand All @@ -98,11 +91,6 @@ public Database createDatabase(Configuration configuration, JdbcConnectionFactor
return new OceanBaseDatabase(configuration, jdbcConnectionFactory, statementInterceptor);
}

@Override
public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext) {
return new MySQLParser(configuration, parsingContext);
}

@Override
public String getPluginVersion(Configuration config) {
return OceanBaseDatabaseExtension.readVersion();
Expand Down
Loading