<commit_before>package com.github.dyna4jdbc;

import com.github.dyna4jdbc.internal.MisconfigurationSQLException;
import com.github.dyna4jdbc.internal.JDBCError;
import com.github.dyna4jdbc.internal.common.util.exception.ExceptionUtil;
import com.github.dyna4jdbc.internal.processrunner.jdbc.impl.ProcessRunnerConnection;
import com.github.dyna4jdbc.internal.scriptengine.jdbc.impl.ScriptEngineConnection;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.Properties;

class ConnectionFactory {

	private static final ConnectionFactory INSTANCE = new ConnectionFactory(); // thread-safe: no state is held


	static ConnectionFactory getInstance() {
		return INSTANCE;
	}

	java.sql.Connection newConnection(String factoryConfiguration, Properties info) throws SQLException {
		try {     
			String[] bridgeNameAndConfig = factoryConfiguration.split(":", 2);

			String bridgeName = bridgeNameAndConfig[0];
			String config = bridgeNameAndConfig.length == 2 ? bridgeNameAndConfig[1] : null;

			return newConnection(bridgeName, config, info);
		}
		catch (MisconfigurationSQLException ex)
		{
			String causeMessage = ExceptionUtil.getRootCauseMessage(ex);
			throw JDBCError.INVALID_CONFIGURATION.raiseSQLException(ex, causeMessage);
		}
		catch (Exception ex)
		{
			String causeMessage = ExceptionUtil.getRootCauseMessage(ex);
			throw JDBCError.CONNECT_FAILED_GENERIC.raiseSQLException(ex, causeMessage);
		}
	}


	private java.sql.Connection newConnection(String bridgeName, String config, Properties info) throws Exception {
		try {
			BuiltInConnectionBridge connectionBridge = BuiltInConnectionBridge.getByName(bridgeName);

			final Class<?> classToInstantiate = (connectionBridge != null) ? connectionBridge.clazz :
				Class.forName(bridgeName);

			Constructor<?> constructor = classToInstantiate.getConstructor(String.class, Properties.class);

			return (java.sql.Connection) constructor.newInstance(config, info);
		}
		catch(InvocationTargetException ite) {
			Throwable cause = ite.getCause();
			if (cause instanceof RuntimeException)
				throw (RuntimeException) cause;
			else if (cause instanceof Error)
				throw (Error) cause;
			else
				throw (Exception)cause;
		}
	}

	private enum BuiltInConnectionBridge {
		SCRIPTENGINE("scriptengine", ScriptEngineConnection.class),
		PROCESS_RUNNER("process-runner", ProcessRunnerConnection.class);

		private final String name;
		private final Class<? extends java.sql.Connection> clazz;

		BuiltInConnectionBridge(String name, Class<? extends java.sql.Connection> clazz) {
			this.name = name;
			this.clazz = clazz;
		}

		private static BuiltInConnectionBridge getByName(String name) {
			for (BuiltInConnectionBridge bridge : BuiltInConnectionBridge.values()) {
				if (bridge.name.equalsIgnoreCase(name)) {
					return bridge;
				}
			}

			return null;
		}
	}


}<commit_msg>Code quality enhancements<commit_after>package com.github.dyna4jdbc;

import com.github.dyna4jdbc.internal.MisconfigurationSQLException;
import com.github.dyna4jdbc.internal.JDBCError;
import com.github.dyna4jdbc.internal.common.util.exception.ExceptionUtil;
import com.github.dyna4jdbc.internal.processrunner.jdbc.impl.ProcessRunnerConnection;
import com.github.dyna4jdbc.internal.scriptengine.jdbc.impl.ScriptEngineConnection;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;

class ConnectionFactory {

    private static final ConnectionFactory INSTANCE = new ConnectionFactory(); // thread-safe: no state is held

    private static final Map<String, Class<? extends Connection>> CONNECTION_TYPES;

    static {
        Map<String, Class<? extends Connection>> connectionTypes = new HashMap<>();

        connectionTypes.put("scriptengine", ScriptEngineConnection.class);
        connectionTypes.put("process-runner", ProcessRunnerConnection.class);

        CONNECTION_TYPES = Collections.unmodifiableMap(connectionTypes);
    }


    static ConnectionFactory getInstance() {
        return INSTANCE;
    }

    java.sql.Connection newConnection(String factoryConfiguration, Properties info) throws SQLException {
        try {
            String[] bridgeNameAndConfig = factoryConfiguration.split(":", 2);

            String bridgeName = bridgeNameAndConfig[0].toLowerCase(Locale.ENGLISH);
            String config = bridgeNameAndConfig.length == 2 ? bridgeNameAndConfig[1] : null;


            return newConnection(bridgeName, config, info);

        } catch (MisconfigurationSQLException ex) {
            String causeMessage = ExceptionUtil.getRootCauseMessage(ex);
            throw JDBCError.INVALID_CONFIGURATION.raiseSQLException(ex, causeMessage);
        } catch (Exception ex) {
            String causeMessage = ExceptionUtil.getRootCauseMessage(ex);
            throw JDBCError.CONNECT_FAILED_GENERIC.raiseSQLException(ex, causeMessage);
        }
    }


    private java.sql.Connection newConnection(String connectionType, String config, Properties info) throws Exception {
        try {

            Class<? extends Connection> connectionClass = CONNECTION_TYPES.get(connectionType);
            if (connectionClass == null) {
                throw MisconfigurationSQLException.forMessage("No such connection type: '%s'", connectionType);
            }

            Constructor<? extends Connection> connectionConstructor =
                    connectionClass.getConstructor(String.class, Properties.class);

            return connectionConstructor.newInstance(config, info);


        } catch (InvocationTargetException ite) {
            Throwable cause = ite.getCause();
            if (cause instanceof RuntimeException)
                throw (RuntimeException) cause;
            else if (cause instanceof Error)
                throw (Error) cause;
            else
                throw (Exception) cause;
        }
    }


}
{'fraction_non_alphanumeric': 0.08850440858426219, 'fraction_numerical': 0.0033272334054233904, 'mean_word_length': 4.022556390977444, 'pattern_counts': {'":': 2, '<': 14, '<?xml version=': 0, '>': 14, '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': '7484684', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1548, 'n_words': 344}