com.scalar.db.storage.jdbc.RdbEngineFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalardb Show documentation
Show all versions of scalardb Show documentation
A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases
package com.scalar.db.storage.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
/** Factory class of subclasses of {@link RdbEngineStrategy} */
public final class RdbEngineFactory {
private RdbEngineFactory() {
throw new AssertionError();
}
public static RdbEngineStrategy create(JdbcConfig config) {
return create(config.getJdbcUrl());
}
public static RdbEngineStrategy create(Connection connection) throws SQLException {
String jdbcUrl = connection.getMetaData().getURL();
return create(jdbcUrl);
}
static RdbEngineStrategy create(String jdbcUrl) {
if (jdbcUrl.startsWith("jdbc:mysql:")) {
return new RdbEngineMysql();
} else if (jdbcUrl.startsWith("jdbc:postgresql:")) {
return new RdbEnginePostgresql();
} else if (jdbcUrl.startsWith("jdbc:oracle:")) {
return new RdbEngineOracle();
} else if (jdbcUrl.startsWith("jdbc:sqlserver:")) {
return new RdbEngineSqlServer();
} else if (jdbcUrl.startsWith("jdbc:sqlite:")) {
return new RdbEngineSqlite();
} else {
throw new IllegalArgumentException("the rdb engine is not supported: " + jdbcUrl);
}
}
}