Skip to content

Commit

Permalink
Merge pull request #31 from flyway/oceanbase-backup
Browse files Browse the repository at this point in the history
Fix issue with OceanBase back up driver not falling back to MySQL
  • Loading branch information
Barry-RG authored Mar 7, 2024
2 parents faca6c0 + 7c590b9 commit 5da4527
Showing 1 changed file with 8 additions and 20 deletions.
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

0 comments on commit 5da4527

Please sign in to comment.