migratedb.v1.commandline.driversupport.SQLServerDriverSupport Maven / Gradle / Ivy
package migratedb.v1.commandline.driversupport;
import com.google.auto.service.AutoService;
import migratedb.v1.commandline.DriverSupport;
import migratedb.v1.core.api.logging.Log;
import java.util.Properties;
@AutoService(DriverSupport.class)
public class SQLServerDriverSupport implements DriverSupport {
private static final Log LOG = Log.getLog(SQLServerDriverSupport.class) ;
@Override
public String getName() {
return "SQL Server";
}
@Override
public boolean handlesJdbcUrl(String url) {
return url.startsWith("jdbc:sqlserver:") || (supportsJTDS() && url.startsWith("jdbc:jtds:")) ||
url.startsWith("jdbc:p6spy:sqlserver:") || (supportsJTDS() && url.startsWith("jdbc:p6spy:jtds:"));
}
@Override
public String getDriverClass(String url, ClassLoader classLoader) {
if (url.startsWith("jdbc:p6spy:sqlserver:") || (supportsJTDS() && url.startsWith("jdbc:p6spy:jtds:"))) {
return "com.p6spy.engine.spy.P6SpyDriver";
}
if (url.startsWith("jdbc:jtds:")) {
if (supportsJTDS()) {
return "net.sourceforge.jtds.jdbc.Driver";
} else if (!supportsJTDS()) {
LOG.warn("JTDS does not support this database. Using the Microsoft JDBC driver instead");
}
}
return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
}
@Override
public void modifyDefaultConnectionProps(String url, Properties props, ClassLoader classLoader) {
props.put("applicationName", APPLICATION_NAME);
}
@Override
public boolean detectUserRequiredByUrl(String url) {
return !(url.contains("integratedSecurity=")
|| url.contains("authentication=ActiveDirectoryIntegrated")
|| url.contains("authentication=ActiveDirectoryMSI"));
}
@Override
public boolean detectPasswordRequiredByUrl(String url) {
return !(url.contains("integratedSecurity=")
|| url.contains("authentication=ActiveDirectoryIntegrated")
|| url.contains("authentication=ActiveDirectoryMSI"));
}
protected boolean supportsJTDS() {
return true;
}
}