<commit_before>package chav1961.purelib.sql;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.ServiceLoader;

import chav1961.purelib.basic.SimpleURLClassLoader;
import chav1961.purelib.basic.PureLibSettings;
import chav1961.purelib.basic.Utils;
import chav1961.purelib.basic.exceptions.ContentException;
import chav1961.purelib.basic.interfaces.LoggerFacade;
import chav1961.purelib.basic.interfaces.LoggerFacade.Severity;

/**
 * <p>This class is an utility class containing useful methods to work with JDBC drivers.</p>
 * @author <NAME> aka chav1961
 * @since 0.0.5
 */
public class JDBCUtils {
	public static final String	KEY_JDBC_USER = "user";
	public static final String	KEY_JDBC_PASSWORD = "password";
	
	public static final String	KEY_ILLEGAL_DRIVER = "JDBCUtils.illegal.driver";
	public static final String	KEY_DATABASE_ERROR = "JDBCUtils.database.error";
	public static final String	KEY_IO_ERROR = "JDBCUtils.io.error";
	public static final String	KEY_VALIDATE_NOT_ABSOLUTE = "JDBCUtils.validate.notAbsolute";
	public static final String	KEY_VALIDATE_NOT_JDBC = "JDBCUtils.validate.notJDBC";
	public static final String	KEY_VALIDATE_SUBSCHEME_MISSING = "JDBCUtils.validate.subschemeMissing";
	/**
	 * <p>Load JDBC driver by it's name<p>
	 * @param loader loader to load JDBC driver to. Can't be null
	 * @param jdbcDriver JDBC driver file to load driver from. Can't be null
	 * @return jdbc driver loaded. Can't be null
	 * @throws NullPointerException when any parameter is null
	 * @throws ContentException on any errors when loading JDBC driver
	 */
	public static Driver loadJdbcDriver(final SimpleURLClassLoader loader, final File jdbcDriver) throws NullPointerException, ContentException {
		if (loader == null) {
			throw new NullPointerException("Loader to laod driver into can't be null");
		}
		else if (jdbcDriver == null) {
			throw new NullPointerException("JDBC driver can't be null");
		}
		else {
			try{loader.addURL(jdbcDriver.toURI().toURL());
			
				for(Driver	drv : ServiceLoader.load(Driver.class, loader)) {
					return drv;
				}		
				throw new ContentException("No any JDBC drivers found in ["+jdbcDriver.getAbsolutePath()+"]");
			} catch (MalformedURLException e) {
				throw new ContentException(e);
			}
		}
	}
	
	/**
	 * <p>Get connection from JDBC driver.</p>
	 * @param driver driver to get connection from. Can't be null
	 * @param connURI connection string. Can't be null
	 * @param user user name to get connection for. Can't be null
	 * @param password password for <PASSWORD>. Can't be null
	 * @return connection created. Can't be null
	 * @throws SQLException on any SQL error
	 */
	public static Connection getConnection(final Driver driver, final URI connURI, final String user, final char[] password) throws NullPointerException, SQLException {
		if (driver == null) {<commit_msg>Daily commit<commit_after>package chav1961.purelib.sql;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.ServiceLoader;

import chav1961.purelib.basic.SimpleURLClassLoader;
import chav1961.purelib.basic.PureLibSettings;
import chav1961.purelib.basic.Utils;
import chav1961.purelib.basic.exceptions.ContentException;
import chav1961.purelib.basic.interfaces.LoggerFacade;
import chav1961.purelib.basic.interfaces.LoggerFacade.Severity;

/**
 * <p>This class is an utility class containing useful methods to work with JDBC drivers.</p>
 * @author <NAME> aka chav1961
 * @since 0.0.5
 */
public class JDBCUtils {
	public static final String	KEY_JDBC_USER = "user";
	public static final String	KEY_JDBC_PASSWORD = "password";
	
	public static final String	KEY_ILLEGAL_DRIVER = "JDBCUtils.illegal.driver";
	public static final String	KEY_DATABASE_ERROR = "JDBCUtils.database.error";
	public static final String	KEY_IO_ERROR = "JDBCUtils.io.error";
	public static final String	KEY_VALIDATE_NOT_ABSOLUTE = "JDBCUtils.validate.notAbsolute";
	public static final String	KEY_VALIDATE_NOT_JDBC = "JDBCUtils.validate.notJDBC";
	public static final String	KEY_VALIDATE_SUBSCHEME_MISSING = "JDBCUtils.validate.subschemeMissing";
	/**
	 * <p>Load JDBC driver by it's name<p>
	 * @param loader loader to load JDBC driver to. Can't be null
	 * @param jdbcDriver JDBC driver file to load driver from. Can't be null
	 * @return jdbc driver loaded. Can't be null
	 * @throws NullPointerException when any parameter is null
	 * @throws ContentException on any errors when loading JDBC driver
	 */
	public static Driver loadJdbcDriver(final SimpleURLClassLoader loader, final File jdbcDriver) throws NullPointerException, ContentException {
		if (loader == null) {
			throw new NullPointerException("Loader to load driver into can't be null");
		}
		else if (jdbcDriver == null) {
			throw new NullPointerException("JDBC driver file can't be null");
		}
		else {
			try{loader.addURL(jdbcDriver.toURI().toURL());
			
				for(Driver	drv : ServiceLoader.load(Driver.class, loader)) {
					return drv;
				}		
				throw new ContentException("No any JDBC drivers found in ["+jdbcDriver.getAbsolutePath()+"]");
			} catch (MalformedURLException e) {
				throw new ContentException(e);
			}
		}
	}
	
	/**
	 * <p>Get connection from JDBC driver.</p>
	 * @param driver driver to get connection from. Can't be null
	 * @param connURI connection string. Can't be null
	 * @param user user name to get connection for. Can't be null
	 * @param password password for user. Can't be null
	 * @return connection created. Can't be null
	 * @throws SQLException on any SQL error
	 */
	public static Connection getConnection(final Driver driver, final URI connURI, final String user, final char[] password) throws NullPointerException, SQLException {
		if (driver == null) {
{'fraction_non_alphanumeric': 0.09217506631299735, 'fraction_numerical': 0.011604774535809019, 'mean_word_length': 4.707663197729423, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '3219913', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1775, 'n_words': 578}