All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.undefinedlabs.scope.rules.sql.provider.internal.h2.H2JdbcConnectionInfoProvider Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 0.15.1-beta.2
Show newest version
package com.undefinedlabs.scope.rules.sql.provider.internal.h2;

import com.undefinedlabs.scope.rules.sql.model.ConnectionInfo;
import com.undefinedlabs.scope.rules.sql.provider.ConnectionInfoProvider;
import com.undefinedlabs.scope.utils.tag.TagValues;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

public class H2JdbcConnectionInfoProvider implements ConnectionInfoProvider {

    public static final String JDBC_CONNECTION_CLASS_NAME = "org.h2.jdbc.JdbcConnection";

    @Override
    public ConnectionInfo extractInfo(Connection connection) {
        if (connection == null || !connection.getClass().getName().contains(JDBC_CONNECTION_CLASS_NAME)) {
            return ConnectionInfo.EMPTY;
        }

        try {
            final DatabaseMetaData metaData = connection.getMetaData();
            final ConnectionInfo.Builder builder = ConnectionInfo.newBuilder();
            builder.withUrl(metaData.getURL())
                    .withUserName(metaData.getUserName())
                    .withInstance(connection.getCatalog())
                    .withProductName(metaData.getDatabaseProductName())
                    .withProductVersion(metaData.getDatabaseProductVersion())
                    .withDriverName(metaData.getDriverName())
                    .withDriverVersion(metaData.getDriverVersion())
                    .withPeerService(TagValues.DB.Service.H2);

            return builder.build();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy