com.undefinedlabs.scope.rules.sql.provider.ConnectionInfoProviderRegistry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scope-rule-java-sql Show documentation
Show all versions of scope-rule-java-sql Show documentation
Scope is a APM for tests to give engineering teams unprecedented visibility into their CI process to quickly
identify, troubleshoot and fix failed builds.
This artifact contains the classes to instrument the Java SQL package.
package com.undefinedlabs.scope.rules.sql.provider;
import com.undefinedlabs.scope.rules.sql.provider.internal.NoopConnectionInfoProvider;
import com.undefinedlabs.scope.rules.sql.provider.internal.h2.H2JdbcConnectionInfoProvider;
import com.undefinedlabs.scope.rules.sql.provider.internal.mysql.MySqlConnectionImplInfoProvider;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
public enum ConnectionInfoProviderRegistry {
INSTANCE;
private static final ConnectionInfoProvider NOOP_PROVIDER = new NoopConnectionInfoProvider();
private static final Map PROVIDERS = new HashMap<>();
static {
PROVIDERS.put(
H2JdbcConnectionInfoProvider.JDBC_CONNECTION_CLASS_NAME,
new H2JdbcConnectionInfoProvider());
PROVIDERS.put(
MySqlConnectionImplInfoProvider.JDBC_CONNECTION_CLASS_NAME,
new MySqlConnectionImplInfoProvider());
}
public ConnectionInfoProvider getProvider(final Connection connection) {
return connection != null ? getProvider(connection.getClass().getName()) : NOOP_PROVIDER;
}
ConnectionInfoProvider getProvider(final String connectionClassName) {
return PROVIDERS.get(connectionClassName) != null
? PROVIDERS.get(connectionClassName)
: NOOP_PROVIDER;
}
}