<commit_before>package com.tqdev.metrics.jdbc;

import com.tqdev.metrics.core.MetricRegistry;

import javax.sql.DataSource;
import java.io.Closeable;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

public class InstrumentedDataSource implements DataSource, Closeable {
    private DataSource wrapped;
    private MetricRegistry registry;

    private volatile boolean metricsEnabled = false;

    public InstrumentedDataSource(DataSource wrapped, MetricRegistry registry) {
        this.wrapped = wrapped;
        this.registry = registry;
    }

    public void setMetricsEnabled(boolean enabled) {
        metricsEnabled = enabled;
    }

    @Override
    public Connection getConnection() throws SQLException {
        if (!metricsEnabled) {
            return wrapped.getConnection();
        }
        return new InstrumentedConnection(wrapped.getConnection(), registry);
    }

    @Override
    public Connection getConnection(String username, String password) throws SQLException {
        if (!metricsEnabled) {
            return wrapped.getConnection();
        }
        return new InstrumentedConnection(wrapped.getConnection(username, password), registry);
    }

    @Override
    public PrintWriter getLogWriter() throws SQLException {
        return wrapped.getLogWriter();
    }

    @Override
    public void setLogWriter(PrintWriter out) throws SQLException {
        wrapped.setLogWriter(out);
    }

    @Override
    public void setLoginTimeout(int seconds) throws SQLException {
        wrapped.setLoginTimeout(seconds);
    }

    @Override
    public int getLoginTimeout() throws SQLException {
        return wrapped.getLoginTimeout();
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        return wrapped.getParentLogger();
    }

    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {
        return wrapped.unwrap(iface);
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return wrapped.isWrapperFor(iface);
    }

    @Override
    public void close() throws IOException {
        if (wrapped instanceof Closeable) {
            ((Closeable) wrapped).close();
        } else {
            try {
                Method close = wrapped.getClass().getMethod("close");
                close.invoke(wrapped);
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                // Ignore, no parameterless close method defined
            }
        }
    }
}<commit_msg>spaces or tabs?<commit_after>package com.tqdev.metrics.jdbc;

import java.io.Closeable;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

import javax.sql.DataSource;

import com.tqdev.metrics.core.MetricRegistry;

public class InstrumentedDataSource implements DataSource, Closeable {
	private DataSource wrapped;
	private MetricRegistry registry;

	private volatile boolean metricsEnabled = false;

	public InstrumentedDataSource(DataSource wrapped, MetricRegistry registry) {
		this.wrapped = wrapped;
		this.registry = registry;
	}

	public void setMetricsEnabled(boolean enabled) {
		metricsEnabled = enabled;
	}

	@Override
	public Connection getConnection() throws SQLException {
		if (!metricsEnabled) {
			return wrapped.getConnection();
		}
		return new InstrumentedConnection(wrapped.getConnection(), registry);
	}

	@Override
	public Connection getConnection(String username, String password) throws SQLException {
		if (!metricsEnabled) {
			return wrapped.getConnection();
		}
		return new InstrumentedConnection(wrapped.getConnection(username, password), registry);
	}

	@Override
	public PrintWriter getLogWriter() throws SQLException {
		return wrapped.getLogWriter();
	}

	@Override
	public void setLogWriter(PrintWriter out) throws SQLException {
		wrapped.setLogWriter(out);
	}

	@Override
	public void setLoginTimeout(int seconds) throws SQLException {
		wrapped.setLoginTimeout(seconds);
	}

	@Override
	public int getLoginTimeout() throws SQLException {
		return wrapped.getLoginTimeout();
	}

	@Override
	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
		return wrapped.getParentLogger();
	}

	@Override
	public <T> T unwrap(Class<T> iface) throws SQLException {
		return wrapped.unwrap(iface);
	}

	@Override
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		return wrapped.isWrapperFor(iface);
	}

	@Override
	public void close() throws IOException {
		if (wrapped instanceof Closeable) {
			((Closeable) wrapped).close();
		} else {
			try {
				Method close = wrapped.getClass().getMethod("close");
				close.invoke(wrapped);
			} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
				// Ignore, no parameterless close method defined
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.08604387291981845, 'fraction_numerical': 0.0, 'mean_word_length': 3.803814713896458, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7323683', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1377, 'n_words': 354}